✅💯🔥100% Beats with One Stack and One Variable
Approach\nLet\u2019s take a variable that stores the minimum number. So whenever a push operation comes in just take that number put it in the stack and update 
# Approach\nLet\u2019s take a variable that stores the minimum number. So whenever a push operation comes in just take that number put it in the stack and update the variable to the number.\n\n# Complexity\n- Time complexity:\n$$O(1)$$\n\n- Space complexity:\n$$O(n)$$\n\n# Code\n```\nclass MinStack {\npublic:\n    stack<long long> st;\n    long long mini;\n    MinStack() {}\n\n    void push(int val) {\n        long long val2 = (long long)val;\n        if(st.empty()){\n            mini=val2;\n            st.push(val2);\n        }\n        else{\n            if(val2>mini){\n                st.push(val2);\n            }\n            else{\n                st.push(long(2*val2*1LL)-mini);\n                mini=val2;\n            }\n        }\n    }\n\n    void pop() {\n        if(st.empty()){\n            return;\n        }\n\n        long long x=st.top();\n        st.pop();\n        if(x<mini){\n            mini=(2*mini)-x;\n        }\n    }\n\n    int top() {\n        if(st.empty()){\n            return -1;\n        }\n        long long x=st.top();\n        if(mini<x){\n            return x;\n        }\n        return mini;\n    }\n\n    int getMin() {\n        return mini;\n    }\n};\n\n/**\n * Your MinStack object will be instantiated and called as such:\n * MinStack* obj = new MinStack();\n * obj->push(val);\n * obj->pop();\n * int param_3 = obj->top();\n * int param_4 = obj->getMin();\n */\n```
['C++']