← 返回 bytedance 的题目列表Validate Stack Sequences
类型:online_judge
Given two integer arrays pushed and popped each representing the push and pop sequences of a stack, return true if this is a valid stack sequence, otherwise return false.
Example 1:
Input: pushed = [1,2,3,4,5], popped = [4,5,3,2,1]
Output: true
Explanation: We might do the following sequence:
push(1), push(2), push(3), push(4), pop() -> 4
push(5), pop() -> 5
pop() -> 3
pop() -> 2
pop() -> 1
Example 2:
Input: pushed = [1,2,3,4,5], popped = [4,3,5,1,2]
Output: false
Explanation: 1 cannot be popped because it hasn't been pushed yet.
Constraints:
0 <= pushed.length == popped.length <= 1000
0 <= pushed[i], popped[i] < 1000
pushed is a permutation of popped.
Tags: Stack
Example
Input
pushed = [1,2,3,4,5], popped = [4,5,3,2,1]
Output
true