forked from DmrfCoder/AlgorithmAndDataStructure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5.py
35 lines (26 loc) · 662 Bytes
/
5.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# -*- coding:utf-8 -*-
class Solution:
def __init__(self):
self.stack1 = []
self.stack2 = []
def push(self, node):
# write code here
self.stack1.append(node)
def pop(self):
# return xx
self.stack2 = []
while len(self.stack1) != 1:
self.stack2.append(self.stack1.pop())
node = self.stack1.pop()
while self.stack2:
self.stack1.append(self.stack2.pop())
return node
solution = Solution()
solution.push(1)
solution.push(2)
solution.push(3)
solution.push(4)
print solution.pop()
print solution.pop()
print solution.pop()
print solution.pop()