#155.Min Stack [LeetCode Grind 75 in Java]

[Problem Link] https://leetcode.com/problems/min-stack/

//insted of this, we can use two stacks as well
class MinState{
    int val;
    int min;

    public MinState(int val, int min){
        this.val = val;
        this.min = min;
    }
}

class MinStack {

    private Stack<MinState> minSt;
    private int min;

    public MinStack() {
        minSt = new Stack<>();
        min = Integer.MAX_VALUE;
    }

    public void push(int val) {

        if(minSt.isEmpty()) min = val;
        else min = Math.min(minSt.peek().min, val);

        minSt.push(new MinState(val, min));
    }

    public void pop() {
        minSt.pop();
    }

    public int top() {
        return minSt.peek().val;
    }

    public int getMin() {
        return minSt.peek().min;
    }
}