题解 | #包含min函数的栈#
包含min函数的栈
https://www.nowcoder.com/practice/4c776177d2c04c2494f2555c9fcc1e49
class Solution { public: void push(int value) { s_data.push(value); if (s_help.empty() || value < s_help.top()) { s_help.push(value); } else { s_help.push(s_help.top()); } } void pop() { s_data.pop(); s_help.pop(); } int top() { return s_data.top(); } int min() { return s_help.top(); } private: stack<int> s_data; stack<int> s_help; };
2023-剑指-队列 + 栈 文章被收录于专栏
2023-剑指-队列 + 栈