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 b8eab50 commit b5713abCopy full SHA for b5713ab
easy/Implement Queue using Stacks.py
@@ -0,0 +1,21 @@
1
+#232. Implement Queue using Stacks
2
+class MyQueue:
3
+ def __init__(self):
4
+ self.input = []
5
+ self.output = []
6
+
7
+ def push(self, x: int) -> None:
8
+ self.input.append(x)
9
10
+ def pop(self) -> int:
11
+ self.peek()
12
+ return self.output.pop()
13
14
+ def peek(self) -> int:
15
+ if not self.output:
16
+ while self.input:
17
+ self.output.append(self.input.pop())
18
+ return self.output[-1]
19
20
+ def empty(self) -> bool:
21
+ return not self.input and not self.output
0 commit comments