class Solution:
def validateStackSequences(self, pushed: List[int], popped: List[int]) -> bool:
stack=[]
n=0
for item in pushed:
stack.append(item)
while(stack and stack[-1]==popped[n]):
stack.pop()
n+=1
return not stack
LEETCODE 946. 验证栈序列
最新推荐文章于 2024-08-16 19:16:34 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)