946 Validate Stack Sequences
Last updated
Was this helpful?
Last updated
Was this helpful?
Given two sequencespushed
andpopped
with distinct values, returntrue
if and only if this could have been the result of a sequence of push and pop operations on an initially empty stack.
Example 1:
Example 2:
Note:
0 <= pushed.length == popped.length <= 1000
0 <= pushed[i], popped[i] < 1000
pushed
is a permutation ofpopped
.
pushed
andpopped
have distinct values.
(1) Stack
Stack: Time: O(n), Space: O(n)