Skip to main content

🟡 剑指 Offer 31. 栈的压入、弹出序列

LeetCode 提示

题目难度 中等

原题链接 🔗 leetcode

题解 1.py#

class Solution:    def validateStackSequences(self, pushed: List[int], popped: List[int]) -> bool:        res = []        for p in pushed:            res.append(p)
            while res and popped:                if res[-1] == popped[0]:                    res.pop(-1)                    popped.pop(0)                else:                    break                    return len(res) == 0