题解 | #包含min函数的栈#
包含min函数的栈
https://www.nowcoder.com/practice/4c776177d2c04c2494f2555c9fcc1e49
class Solution { public: int a[310]; int b[310]; int idx=0; int idx2=0; void push(int value) { a[idx++] = value; if(idx2==0 || value<=b[idx2-1]) b[idx2++] = value; } void pop() { idx--; if(b[idx2-1]==a[idx]) idx2--; } int top() { return a[idx-1]; } int min() { return b[idx2-1]; } };