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 c121a93 commit 623fb0fCopy full SHA for 623fb0f
0225-implement-stack-using-queues/0225-implement-stack-using-queues.py
@@ -0,0 +1,18 @@
1
+class MyStack:
2
+
3
+ def __init__(self):
4
+ self.q = collections.deque()
5
6
+ def push(self, x: int) -> None:
7
+ self.q.append(x)
8
9
+ def pop(self) -> int:
10
+ for i in range(len(self.q) - 1):
11
+ self.push(self.q.popleft())
12
+ return self.q.popleft()
13
14
+ def top(self) -> int:
15
+ return self.q[-1]
16
17
+ def empty(self) -> bool:
18
+ return len(self.q) == 0
0 commit comments