题解 | #包含min函数的栈#
包含min函数的栈
https://www.nowcoder.com/practice/4c776177d2c04c2494f2555c9fcc1e49
#include <climits> #include <stack> class Solution { public: vector<int> s; void push(int value) { s.push_back(value); } void pop() { s.pop_back(); } int top() { return s[s.size() - 1]; } int min() { int m = INT_MAX; for (int i = 0; i < s.size(); ++i) { if (s[i] < m) { m = s[i]; } } return m; } };