publicintpop() { if (this.stackData.isEmpty()) { thrownewRuntimeException("Your stack is empty."); } intvalue=this.stackData.pop(); if (value == this.getMin()) { this.stackMin.pop(); } return value; }
publicinttop() { return stackData.peek(); }
publicintgetMin() { if (this.stackMin.isEmpty()) { thrownewRuntimeException("Your stack is empty."); } returnthis.stackMin.peek(); } }
/** * Your MinStack object will be instantiated and called as such: * MinStack obj = new MinStack(); * obj.push(x); * obj.pop(); * int param_3 = obj.top(); * int param_4 = obj.getMin(); */
publicintpop() { if (this.stackData.isEmpty()) { thrownewRuntimeException("Your stack is empty."); } this.stackMin.pop(); returnthis.stackData.pop(); }
publicinttop() { return stackData.peek(); }
publicintgetMin() { if (this.stackMin.isEmpty()) { thrownewRuntimeException("Your stack is empty."); } returnthis.stackMin.peek(); } }
/** * Your MinStack object will be instantiated and called as such: * MinStack obj = new MinStack(); * obj.push(x); * obj.pop(); * int param_3 = obj.top(); * int param_4 = obj.getMin(); */