File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,35 @@ def empty(self) -> bool:
29
29
return False
30
30
31
31
32
+ class MyStack :
33
+ '''
34
+ Date: 2023.08.05
35
+ Pass/Error/Bug: 1/0/0
36
+ 执行用时: 48 ms, 在所有 Python3 提交中击败了 22.37% 的用户
37
+ 内存消耗:15.54 MB, 在所有 Python3 提交中击败了 69.77% 的用户
38
+ '''
39
+ def __init__ (self ):
40
+ self .queue = []
41
+
42
+ def push (self , x : int ) -> None :
43
+ self .queue .append (x )
44
+ total_n = len (self .queue )
45
+ for i in range (total_n - 1 ):
46
+ self .queue .append (self .queue .pop (0 ))
47
+
48
+ def pop (self ) -> int :
49
+ x = self .queue .pop (0 )
50
+ return x
51
+
52
+ def top (self ) -> int :
53
+ return self .queue [0 ]
54
+
55
+ def empty (self ) -> bool :
56
+ if len (self .queue ) == 0 :
57
+ return True
58
+ else :
59
+ return False
60
+
32
61
33
62
# Your MyStack object will be instantiated and called as such:
34
63
# obj = MyStack()
You can’t perform that action at this time.
0 commit comments