Skip to content

Commit 1e7c886

Browse files
committed
Create 225.implement-stack-using-queues.py
1 parent 9ad0637 commit 1e7c886

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

225.implement-stack-using-queues.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# https://leetcode.cn/problems/plus-one
2+
3+
4+
class MyStack:
5+
'''
6+
Date: 2023.08.04
7+
Pass/Error/Bug: 1/0/0
8+
执行用时: 48 ms, 在所有 Python3 提交中击败了 22.37% 的用户
9+
内存消耗:15.64 MB, 在所有 Python3 提交中击败了 62.97% 的用户
10+
'''
11+
def __init__(self):
12+
self.stack = []
13+
14+
def push(self, x: int) -> None:
15+
self.stack.append(x)
16+
17+
def pop(self) -> int:
18+
x = self.stack[-1]
19+
self.stack = self.stack[:-1]
20+
return x
21+
22+
def top(self) -> int:
23+
return self.stack[-1]
24+
25+
def empty(self) -> bool:
26+
if len(self.stack) == 0:
27+
return True
28+
else:
29+
return False
30+
31+
32+
33+
# Your MyStack object will be instantiated and called as such:
34+
# obj = MyStack()
35+
# obj.push(x)
36+
# param_2 = obj.pop()
37+
# param_3 = obj.top()
38+
# param_4 = obj.empty()

0 commit comments

Comments
 (0)