Skip to content

Instantly share code, notes, and snippets.

@JamesJi9277
Created April 15, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamesJi9277/ee5393fed97f741d9030 to your computer and use it in GitHub Desktop.
Save JamesJi9277/ee5393fed97f741d9030 to your computer and use it in GitHub Desktop.
//using additional stack to keep track of every minimum value
public class Solution{
Stack<Integer> s2 = new Stack<Integer>();
public void push(int value){
if (value <= min())
s2.push(value);
s1.push(value);
}
public int pop(){
int value = s1.pop();
if(value == min())
s2.pop();
return value;
}
public int min(){
if(s2.isEmpty())
return -1;
else
return s2.pop();
}
}
@shiliuus
Copy link

u r so smart to use min() directly. zan!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment