File tree 2 files changed +42
-1
lines changed
2 files changed +42
-1
lines changed Original file line number Diff line number Diff line change 63
63
| 206 | [ Reverse Linked Lists] ( https://leetcode.com/problems/reverse-linked-list ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/ReverseLinkedList.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/reverse_linked_list.py ) |
64
64
| 217 | [ Contains Duplicate] ( https://leetcode.com/problems/contains-duplicate ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/ContainsDuplicate.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/contains_duplicate.py ) |
65
65
| 219 | [ Contains Duplicate II] ( https://leetcode.com/problems/contains-duplicate-ii ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/ContainsDuplicateII.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/contains_duplicate_ii.py ) |
66
- | 225 | [ Implement Stack using Queues] ( https://leetcode.com/problems/implement-stack-using-queues ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/MyStack.java ) |
66
+ | 225 | [ Implement Stack using Queues] ( https://leetcode.com/problems/implement-stack-using-queues ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/MyStack.java ) [ ![ Python ] ( https://img.icons8.com/color/35/000000/python.png )] ( python/implement_stack_using_queues.py ) |
67
67
| 226 | [ Invert Binary Tree] ( https://leetcode.com/problems/invert-binary-tree ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/InvertBinaryTree.java ) |
68
68
| 231 | [ Power of Two] ( https://leetcode.com/problems/power-of-two ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/PowerOf2.java ) |
69
69
| 232 | [ Implement Queue Using Stacks] ( ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/MyQueue.java ) |
Original file line number Diff line number Diff line change
1
+ from collections import deque
2
+
3
+
4
+ class MyStack :
5
+
6
+ def __init__ (self ):
7
+ """
8
+ Initialize your data structure here.
9
+ """
10
+ self .queue = deque ()
11
+
12
+ def push (self , x : int ) -> None :
13
+ """
14
+ Push element x onto stack.
15
+ """
16
+ self .queue .append (x )
17
+
18
+ def pop (self ) -> int :
19
+ """
20
+ Removes the element on top of the stack and returns that element.
21
+ """
22
+ return self .queue .pop ()
23
+
24
+ def top (self ) -> int :
25
+ """
26
+ Get the top element.
27
+ """
28
+ return self .queue [- 1 ]
29
+
30
+ def empty (self ) -> bool :
31
+ """
32
+ Returns whether the stack is empty.
33
+ """
34
+ return len (self .queue ) == 0
35
+
36
+ # Your MyStack object will be instantiated and called as such:
37
+ # obj = MyStack()
38
+ # obj.push(x)
39
+ # param_2 = obj.pop()
40
+ # param_3 = obj.top()
41
+ # param_4 = obj.empty()
You can’t perform that action at this time.
0 commit comments