C++ O(1) solution
class MinStack {\n    public:\n        vector<int> a;\n        vector<int> min;\n        MinStack() {\n            min.push_back(2147483647);\n        }\n      
    class MinStack {\n    public:\n        vector<int> a;\n        vector<int> min;\n        MinStack() {\n            min.push_back(2147483647);\n        }\n        void push(int x) {\n            a.push_back(x);\n            if (x < min.back()) {\n                min.push_back(x);\n            } else {\n                min.push_back(min.back());\n            }\n        }\n    \n        void pop() {\n            a.pop_back();\n            min.pop_back();\n        }\n    \n        int top() {\n            return a.back();\n        }\n    \n        int getMin() {\n            return min.back();\n        }\n    };
[]