From 8bfb2cf6a2cabcaafb7f51f5ec849211b61ab078 Mon Sep 17 00:00:00 2001 From: Fazeel Usmani Date: Mon, 25 Oct 2021 17:45:28 +0530 Subject: [PATCH] Create 25_minStack.cpp --- .../25_minStack.cpp | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 10 October LeetCode Challenge 2021/25_minStack.cpp 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(); + */