| 1 | class MinStack { |
| 2 | |
| 3 | private Stack<Integer> _data; |
| 4 | private Stack<Integer> _min; |
| 5 | |
| 6 | /** initialize your data structure here. */ |
| 7 | public MinStack() { |
| 8 | _data = new Stack<>(); |
| 9 | _min = new Stack<>(); |
| 10 | } |
| 11 | |
| 12 | public void push(int x) { |
| 13 | _data.add(x); |
| 14 | if (_min.isEmpty()){ |
| 15 | _min.push(x); |
| 16 | } |
| 17 | else{ |
| 18 | if (x > _min.peek()){ |
| 19 | x = _min.peek(); |
| 20 | } |
| 21 | _min.push(x); |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | public void pop() { |
| 26 | _data.pop(); |
| 27 | _min.pop(); |
| 28 | } |
| 29 | |
| 30 | public int top() { |
| 31 | return _data.peek(); |
| 32 | } |
| 33 | |
| 34 | public int getMin() { |
| 35 | return _min.peek(); |
| 36 | } |
| 37 | } |
nothing calls this directly
no outgoing calls
no test coverage detected