diff --git a/10 October LeetCode Challenge 2021/25_minStack.cpp b/10 October LeetCode Challenge 2021/25_minStack.cpp new file mode 100644 index 0000000..7a52630 --- /dev/null +++ b/10 October LeetCode Challenge 2021/25_minStack.cpp @@ -0,0 +1,34 @@ +class MinStack { + public: + stacks; + multisetm; + + void push(int val) {//insert elements on both set and stack + s.push(val); + m.insert(val); + } + + void pop() {//poping elements on both set and stack + int top = s.top(); + s.pop(); + m.erase(m.find(top)); + } + + int top() { //return stack top + return s.top(); + } + + int getMin() {// return set first element + return *m.begin(); + } + }; + + +/** + * Your MinStack object will be instantiated and called as such: + * MinStack* obj = new MinStack(); + * obj->push(val); + * obj->pop(); + * int param_3 = obj->top(); + * int param_4 = obj->getMin(); + */