-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsolution.py
More file actions
34 lines (28 loc) · 809 Bytes
/
Copy pathsolution.py
File metadata and controls
34 lines (28 loc) · 809 Bytes
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
class MyQueue:
def __init__(self):
self.s1=[]
self.s2=[]
def push(self, x: int) -> None:
self.s1.append(x)
def pop(self) -> int:
while(self.s1):
self.s2.append(self.s1.pop())
res = self.s2.pop()
while(self.s2):
self.s1.append(self.s2.pop())
return res
def peek(self) -> int:
while(self.s1):
self.s2.append(self.s1.pop())
res = self.s2[len(self.s2)-1]
while(self.s2):
self.s1.append(self.s2.pop())
return res
def empty(self) -> bool:
return False if self.s1 else True
# Your MyQueue object will be instantiated and called as such:
# obj = MyQueue()
# obj.push(x)
# param_2 = obj.pop()
# param_3 = obj.peek()
# param_4 = obj.empty()