[Leetcode] 225. Implement Stack using Queues
2021. 1. 18. 11:43ㆍProblem Solving/LeetCode
Leetcode 225. Implement Stack using Queues
(3) Implement Stack using Queues - LeetCode
Solution
from collections import deque
class MyStack:
def __init__(self):
self.q = collections.deque()
def push(self, x: int) -> None:
self.q.append(x)
def pop(self) -> int:
return self.q.pop()
def top(self) -> int:
return self.q[-1]
def empty(self) -> bool:
return len(self.q) == 0
# Your MyStack object will be instantiated and called as such:
# obj = MyStack()
# obj.push(x)
# param_2 = obj.pop()
# param_3 = obj.top()
# param_4 = obj.empty()
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
[Leetcode] 622. Design Circular Queue (0) | 2021.01.18 |
---|---|
[Leetcode] 232. Implement Queue using Stacks (0) | 2021.01.18 |
[Leetcode] 739. Daily Temperatures (0) | 2021.01.18 |
[LeetCode] 20. Valid Parentheses (0) | 2021.01.18 |
[LeetCode] 328. Odd Even Linked List (0) | 2021.01.15 |