leetcode/src/jianzhi_offer/min_stack.cpp
2023-05-24 21:07:52 +08:00

25 lines
390 B
C++

#include "jianzhi_offer.h"
namespace yaha {
void MinStack::push(int x) {
_stk.push(x);
if (_min_stk.empty() || _min_stk.top() >= x) {
_min_stk.push(x);
}
}
void MinStack::pop() {
if (_stk.top() == _min_stk.top()) {
_min_stk.pop();
}
_stk.pop();
}
int MinStack::top() {
return _stk.top();
}
int MinStack::min() {
return _min_stk.top();
}
}