C++ two stacks
Use one stack data to store the elements and the other stack minimum to store the minimum.\n\nFor push, push the element to data. If the element is not larger t
Use one stack `data` to store the elements and the other stack `minimum` to store the minimum.\n\nFor `push`, push the element to `data`. If the element is not larger than the top of `minimum`, push it to `minimum`. For `pop`, if the top of the two stacks are equal, pop both; otherwise pop `data`. For `top` and `getMin`, just return the top of `data` and `minimum` respectively.\n\n```cpp\nclass MinStack {\npublic:\n    /** initialize your data structure here. */\n    MinStack() {\n        \n    }\n    \n    void push(int x) {\n        data.push(x);\n        if (minimum.empty() || minimum.top() >= x) {\n            minimum.push(x);\n        }\n    }\n    \n    void pop() {\n        if (top() == getMin()) {\n            minimum.pop();\n        }\n        data.pop();\n    }\n    \n    int top() {\n        return data.top();\n    }\n    \n    int getMin() {\n        return minimum.top();\n    }\nprivate:\n    stack<int> data, minimum;\n};\n ```
['Stack', 'C++']