We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f09204a commit c51614cCopy full SHA for c51614c
232-implement-queue-using-stacks/implement-queue-using-stacks.py
@@ -0,0 +1,32 @@
1
+class MyQueue:
2
+
3
+ def __init__(self):
4
+ self.s1=[]
5
+ self.s2=[]
6
7
+ def push(self, x: int) -> None:
8
+ self.s1.append(x)
9
10
+ def pop(self) -> int:
11
+ while self.s1:
12
+ self.s2.append(self.s1.pop())
13
+ ele = self.s2.pop()
14
+ while self.s2:
15
+ self.s1.append(self.s2.pop())
16
17
+ return ele
18
19
20
+ def peek(self) -> int:
21
+ return self.s1[0]
22
23
+ def empty(self) -> bool:
24
+ return len(self.s1)==0
25
26
27
+# Your MyQueue object will be instantiated and called as such:
28
+# obj = MyQueue()
29
+# obj.push(x)
30
+# param_2 = obj.pop()
31
+# param_3 = obj.peek()
32
+# param_4 = obj.empty()
0 commit comments