aboutsummaryrefslogtreecommitdiff
path: root/store/works/solutions/leetcode/cpp/155.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'store/works/solutions/leetcode/cpp/155.cpp')
-rw-r--r--store/works/solutions/leetcode/cpp/155.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/store/works/solutions/leetcode/cpp/155.cpp b/store/works/solutions/leetcode/cpp/155.cpp
new file mode 100644
index 0000000..48550be
--- /dev/null
+++ b/store/works/solutions/leetcode/cpp/155.cpp
@@ -0,0 +1,38 @@
+#include <vector>
+#include <set>
+
+class MinStack
+{
+public:
+ /** initialize your data structure here. */
+ MinStack()
+ {
+ }
+
+ void push(int x)
+ {
+ data_.push_back(x);
+ sorted_data_.insert(x);
+ }
+
+ void pop()
+ {
+ const auto v = data_.back();
+ data_.pop_back();
+ sorted_data_.erase(sorted_data_.find(v));
+ }
+
+ int top()
+ {
+ return data_.back();
+ }
+
+ int getMin()
+ {
+ return *sorted_data_.cbegin();
+ }
+
+private:
+ std::vector<int> data_;
+ std::multiset<int> sorted_data_;
+};