728x90
LeetCode-225
Implement Queue using Stacks : Implement a last-in-first-out (LIFO) stack using only two queues. The implemented stack should support all the functions of a normal stack
note : last-in-first-out (LIFO)
Answer
:::python
class MyStack:
def init(self):
self.temp = []
def push(self, x: int) -> None:
self.temp.append(x)
def pop(self) -> int:
return self.temp.pop()
def top(self) -> int:
return self.temp[-1]
def empty(self) -> bool:
if self.temp==[]:
return True
else:
return False
# 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()
Result : 15ms Memory: 14mb
๋ฐ์ํ
'๐ข One step' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[leetcode-622] Design Circular Queue (0) | 2023.04.07 |
---|---|
[leetcode-232] Implement Queue using Stacks (0) | 2023.04.06 |
[leetcode 739] Daily Temperature (0) | 2023.04.03 |
[LeetCode-316] Remove Duplicate Letters (0) | 2023.03.30 |
[leetcode-20] Valid Parenthese (0) | 2023.03.29 |