Skip to content

Commit 39ed946

Browse files
Create 225.py
1 parent 5fc08ea commit 39ed946

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

001-500/225.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)