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.
2 parents 296bbc5 + 5e79c43 commit aa52836Copy full SHA for aa52836
python/0225-implement-stack-using-queues.py
@@ -4,18 +4,15 @@ def __init__(self):
4
5
def push(self, x: int) -> None:
6
self.q.append(x)
7
+
8
+ for _ in range(len(self.q) - 1):
9
+ self.q.append(self.q.popleft())
10
11
def pop(self) -> int:
- for i in range(len(self.q) - 1):
- self.push(self.q.popleft())
12
return self.q.popleft()
13
14
def top(self) -> int:
15
16
- res = self.q[0]
17
18
- return res
+ return self.q[0]
19
20
def empty(self) -> bool:
21
return len(self.q) == 0
0 commit comments