diff --git a/0x10/1.cpp b/0x10/1.cpp new file mode 100644 index 0000000..8762c23 --- /dev/null +++ b/0x10/1.cpp @@ -0,0 +1,38 @@ +// 41 +class MinStack +{ +public: + /** initialize your data structure here. */ + int a[105], tot = 0; + MinStack() + { + } + void push(int x) + { + a[++tot] = x; + } + void pop() + { + tot--; + } + int top() + { + return a[tot]; + } + int getMin() + { + int ans = 1e9; + for (int i = tot; i >= 1; i--) + ans = (a[i] < ans) ? a[i] : ans; + return ans; + } +}; + +/** + * Your MinStack object will be instantiated and called as such: + * MinStack obj = new MinStack(); + * obj.push(x); + * obj.pop(); + * int param_3 = obj.top(); + * int param_4 = obj.getMin(); + */ \ No newline at end of file