Skip to content

Latest commit

 

History

History
20 lines (18 loc) · 481 Bytes

946.md

File metadata and controls

20 lines (18 loc) · 481 Bytes

946. Validate Stack Sequences

Solution 1 (time O(n), space O(n))

class Solution(object):
    def validateStackSequences(self, pushed, popped):
        """
        :type pushed: List[int]
        :type popped: List[int]
        :rtype: bool
        """
        s, p = [], 0
        for t in pushed:
            s.append(t)
            while s and s[-1] == popped[p]:
                s.pop()
                p += 1
        return len(s) == 0