[LeetCode/Python] 232. Implement Queue using Stacks
2025. 4. 3. 20:16
99클럽 코테 스터디 | 비기너 | 4일차
https://leetcode.com/problems/implement-queue-using-stacks/description/
class MyQueue:
def __init__(self):
self.list1 = []
self.list2 = []
def push(self, x: int) -> None:
while self.list1:
self.list2.append(self.list1.pop())
self.list1.append(x)
while self.list2:
self.list1.append(self.list2.pop())
def pop(self) -> int:
return self.list1.pop()
def peek(self) -> int:
return self.list1[-1]
def empty(self) -> bool:
return not self.list1
# 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()
'코딩테스트 > LeetCode' 카테고리의 다른 글
[LeetCode/Python] 2283. Check if Number Has Equal Digit Count and Digit Value (0) | 2025.04.09 |
---|---|
[LeetCode/Python] 70. Climbing Stairs (0) | 2025.04.07 |
[LeetCode/Python] 225. Implement Stack using Queues (0) | 2025.04.04 |
[LeetCode/Python] 204. Count Primes (0) | 2025.03.25 |
[LeetCode/Python] 387. First Unique Character in a String (0) | 2025.03.24 |