728x90
LeetCode-232
Implement Queue using Stacks : Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (push, peek, pop, and empty).
note : sub
์ ์ ์ ์ถ
:::python
class MyQueue:
def init(self):
self.temp = collections.deque()
def push(self, x: int) -> None:
self.temp.append(x)
def pop(self) -> int:
return self.temp.popleft()
def peek(self) -> int:
return self.temp[0]
def empty(self) -> bool:
if len(self.temp) == 0:
return True
else:
return False
# Your MyQueue object will be instantiated and called as such:
# obj = MyQueue()
# obj.push(x)
# param_2 = obj.pop()
# param_3 = obj.peek()
# param_4 = obj.empty()
Result : 34ms Memory: 13.9mb
๋ฐ์ํ
'๐ข One step' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[leetcode-641] Design Circular Deque (0) | 2023.04.08 |
---|---|
[leetcode-622] Design Circular Queue (0) | 2023.04.07 |
[leetcode-225] Implement Queue using Stacks (0) | 2023.04.05 |
[leetcode 739] Daily Temperature (0) | 2023.04.03 |
[LeetCode-316] Remove Duplicate Letters (0) | 2023.03.30 |