Java Solution:MIn Stack


#1
class Node {

    int data;
    Node next;
    Node previous;
    Node previousFirst;
}
Node node;
Node first = null;
Node oldFirst = null;
Node last = null;

public void push(int x) {
    if (node == null) {
        node = new Node();
        node.data = x;
        node.previous = null;
        node.next = null;

        first = node;
        last = node;
        oldFirst = first;
    } else {
        Node t = new Node();
        t.data = x;
        t.next = null;
        t.previous = last;
        if (last != null) {
            last.next = t;
           // last.previous = last;
        }
        last = t;
        if (first != null && x < first.data) {
            oldFirst = first;
            first = t;
            first.previousFirst = oldFirst;
        }
            if(first==null)
            first=t;
        
    }
}

public void pop() {
    if (last==first && first != null) {
        first = first.previousFirst;
    }

    if (last != null) {
        last = last.previous;
        if (last != null) {
            last.next = null;
        }
    }
}

public int top() {
    if (last == null) {
        return -1;
    }
    return last.data;
}

public int getMin() {
    if (first == null) {
        return -1;
    }
    return first.data;
}

#2

Hey, I find your method unique. How did you approach this question with LL?