25 lines
390 B
C++
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();
|
|
}
|
|
} |