Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b5713ab

Browse files
authoredOct 23, 2022
Create Implement Queue using Stacks.py
1 parent b8eab50 commit b5713ab

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
 

‎easy/Implement Queue using Stacks.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#232. Implement Queue using Stacks
2+
class MyQueue:
3+
def __init__(self):
4+
self.input = []
5+
self.output = []
6+
7+
def push(self, x: int) -> None:
8+
self.input.append(x)
9+
10+
def pop(self) -> int:
11+
self.peek()
12+
return self.output.pop()
13+
14+
def peek(self) -> int:
15+
if not self.output:
16+
while self.input:
17+
self.output.append(self.input.pop())
18+
return self.output[-1]
19+
20+
def empty(self) -> bool:
21+
return not self.input and not self.output

0 commit comments

Comments
 (0)
Please sign in to comment.