Stack을 만드는 건데 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()

Posted by 공놀이나하여보세
,