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 5fc08ea commit 39ed946Copy full SHA for 39ed946
001-500/225.py
@@ -0,0 +1,29 @@
1
+import collections
2
+
3
+class MyStack:
4
5
+ def __init__(self):
6
+ self.queue = collections.deque()
7
8
+ def push(self, x: int) -> None:
9
+ q = self.queue
10
+ q.append(x)
11
+ for _ in range(len(q)-1):
12
+ q.append(q.popleft())
13
14
+ def pop(self) -> int:
15
+ return self.queue.popleft()
16
17
+ def top(self) -> int:
18
+ return self.queue[0]
19
20
+ def empty(self) -> bool:
21
+ return (not len(self.queue))
22
23
24
+# Your MyStack object will be instantiated and called as such:
25
+# obj = MyStack()
26
+# obj.push(x)
27
+# param_2 = obj.pop()
28
+# param_3 = obj.top()
29
+# param_4 = obj.empty()
0 commit comments