C++ easy two vector approach


#1
vector<int> st, min_stack;

MinStack::MinStack(){
    st.clear();
    min_stack.clear();
}

void MinStack::push(int x){
    int curr_min=x;
    if(!min_stack.empty()){
        curr_min=min(x, min_stack[min_stack.size()-1]);
    }
    min_stack.push_back(curr_min);
    st.push_back(x);
}

void MinStack::pop(){
    if(!st.empty() && !min_stack.empty()){
        st.pop_back();
        min_stack.pop_back();
    }
}

int MinStack::top(){
    if(st.empty()) return -1;
    else return st[st.size()-1];
}

int MinStack::getMin(){
    if(min_stack.empty()) return -1;
    else return min_stack[min_stack.size()-1];
}