We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 23a5384 commit 187053eCopy full SHA for 187053e
0232-implement-queue-using-stacks/0232-implement-queue-using-stacks.py
@@ -0,0 +1,20 @@
1
+class MyQueue(object):
2
+ def __init__(self):
3
+ self.in_stk = []
4
+ self.out_stk = []
5
+
6
+ def push(self, x):
7
+ self.in_stk.append(x)
8
9
+ def pop(self):
10
+ self.peek()
11
+ return self.out_stk.pop()
12
13
+ def peek(self):
14
+ if not self.out_stk:
15
+ while self.in_stk:
16
+ self.out_stk.append(self.in_stk.pop())
17
+ return self.out_stk[-1]
18
19
+ def empty(self):
20
+ return not self.in_stk and not self.out_stk
0 commit comments