| 8 | |
| 9 | |
| 10 | class MinStack { |
| 11 | private Node head; |
| 12 | |
| 13 | /** initialize your data structure here. */ |
| 14 | public MinStack() { |
| 15 | |
| 16 | } |
| 17 | |
| 18 | public void push(int val) { |
| 19 | if (head == null) { |
| 20 | head = new Node(val, val, null); |
| 21 | } else { |
| 22 | head = new Node(val, Math.min(val, head.min), head); |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | public void pop() { |
| 27 | head = head.next; |
| 28 | } |
| 29 | |
| 30 | public int top() { |
| 31 | return head.val; |
| 32 | } |
| 33 | |
| 34 | public int getMin() { |
| 35 | return head.min; |
| 36 | } |
| 37 | |
| 38 | private class Node { |
| 39 | int val; |
| 40 | int min; |
| 41 | Node next; |
| 42 | |
| 43 | Node(int val, int min, Node next) { |
| 44 | this.val = val; |
| 45 | this.min = min; |
| 46 | this.next = next; |
| 47 | } |
| 48 | } |
| 49 | } |
nothing calls this directly
no outgoing calls
no test coverage detected