# 155. Min Stack

{% embed url="<https://leetcode.com/problems/min-stack/>" %}

考验数据结构理解的时候到了...

偷懒直接双stack了，一个用来依序存当前最小值。

```python
class MinStack:

    def __init__(self):
        """
        initialize your data structure here.
        """
        self.stack = []
        self.min = []

    def push(self, x: int) -> None:
        if self.stack == []:
            self.min.append(x)
        else:
            self.min.append(min(x, self.min[-1]))
        self.stack.append(x)

    def pop(self) -> None:
        self.stack.pop()
        self.min.pop()
    
    def top(self) -> int:
        return self.stack[-1]
        

    def getMin(self) -> int:
        return self.min[-1]
        
# 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()
```

**July 29 2020 Update:**

第二遍做，写出来了几乎一模一样的东西...
