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 ee8fcfd commit f6ad59cCopy full SHA for f6ad59c
14_Queue/02. Implement Stack using Queues.py
@@ -0,0 +1,28 @@
1
+# https://leetcode.com/problems/implement-stack-using-queues/
2
+
3
+class MyStack:
4
5
+ def __init__(self):
6
+ self._deque = collections.deque()
7
8
+ def push(self, x: int) -> None:
9
+ self._deque.append(x)
10
+ for _ in range(len(self._deque)-1):
11
+ self._deque.append(self._deque.popleft())
12
13
+ def pop(self) -> int:
14
+ return self._deque.popleft()
15
16
+ def top(self) -> int:
17
+ return self._deque[0]
18
19
+ def empty(self) -> bool:
20
+ return len(self._deque) == 0
21
22
23
+# Your MyStack object will be instantiated and called as such:
24
+# obj = MyStack()
25
+# obj.push(x)
26
+# param_2 = obj.pop()
27
+# param_3 = obj.top()
28
+# param_4 = obj.empty()
0 commit comments