mirror of
https://github.com/20kaushik02/leetcode-gulag.git
synced 2025-12-06 11:34:07 +00:00
32 lines
449 B
C++
32 lines
449 B
C++
#include "soln.hpp"
|
|
|
|
MinStack::MinStack()
|
|
{
|
|
_stack = {};
|
|
total_min = INT_MAX;
|
|
}
|
|
|
|
void MinStack::push(int val)
|
|
{
|
|
total_min = min(int(val), total_min);
|
|
_stack.push_back({val, total_min});
|
|
}
|
|
|
|
void MinStack::pop()
|
|
{
|
|
_stack.pop_back();
|
|
if (_stack.size() == 0)
|
|
total_min = INT_MAX;
|
|
else
|
|
total_min = _stack.back().second;
|
|
}
|
|
|
|
int MinStack::top()
|
|
{
|
|
return int(_stack.back().first);
|
|
}
|
|
|
|
int MinStack::getMin()
|
|
{
|
|
return int(_stack.back().second);
|
|
} |