Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b5d31a9

Browse files
add 0946-validate-stack-sequences.py
1 parent 6e1801d commit b5d31a9

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution(object):
2+
def validateStackSequences(self, pushed, popped):
3+
i = 0
4+
stack = []
5+
for n in pushed:
6+
stack.append(n)
7+
while i < len(popped) and stack and popped[i] == stack[-1]:
8+
stack.pop()
9+
i += 1
10+
11+
return not stack
12+
13+

0 commit comments

Comments
 (0)