Skip to content

Latest commit

 

History

History
19 lines (18 loc) · 403 Bytes

offer31.md

File metadata and controls

19 lines (18 loc) · 403 Bytes

模拟

  • time: O(n)
  • space: O(n)
  • 36ms
  • 97%
class Solution:
    def validateStackSequences(self, pushed: List[int], popped: List[int]) -> bool:
        j = 0
        st = []
        n = len(pushed)
        for i in range(n):
            st.append(pushed[i])
            while st and j < n and st[-1] == popped[j]:
                st.pop()
                j += 1
        return not st