[LeetCode 155. Min Stack ] Stack Easy (19주차 8/10, 22/150)
Algorithm/LeetCode 문제 풀이 2019. 5. 12. 11:32Stack을 만드는 건데 list를 사용해서 만들었더니 느리다.
class MinStack:
def __init__(self):
"""
initialize your data structure here.
"""
self.data = []
def push(self, x: int) -> None:
self.data.append(x)
def pop(self) -> None:
if not self.data:
return
self.data.pop()
def top(self) -> int:
if not self.data:
return []
return self.data[len(self.data)-1]
def getMin(self) -> int:
if not self.data:
return []
return min(self.data)
# Your MinStack object will be instantiated and called as such:
# obj = MinStack()
# obj.push(x)
# obj.pop()
# param_3 = obj.top()
# param_4 = obj.getMin()
'Algorithm > LeetCode 문제 풀이' 카테고리의 다른 글
[LeetCode 69. Sqrt(x)] Easy, Binary Search 1/5 24/150 (0) | 2019.05.15 |
---|---|
[LeetCode 378. Kth Smallest Element in a Sorted Matrix ] Stack Easy (19주차 9/10, 23/150) (0) | 2019.05.12 |
[LeetCode 20. Valid Parentheses ] Easy (19주차 7/10, 21/150) (0) | 2019.05.12 |
[LeetCode 14. Longest Common Prefix ] Easy (19주차 6/10, 20/150) (0) | 2019.05.12 |
[LeetCode 13. Roman to Integer] Easy (19주차 5/10, 19/150) (0) | 2019.05.12 |