Skip to content

Instantly share code, notes, and snippets.

@JamesJi9277
Created April 15, 2015 14:53
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/d3e68b23802de5afc31a to your computer and use it in GitHub Desktop.
Save JamesJi9277/d3e68b23802de5afc31a to your computer and use it in GitHub Desktop.
3.3
public class Solution{
ArrayList<Stack> res = new ArrayList<Stack>();
public void push(int value){
Stack last = getLastStack();
if(last != null && !last.isFull())
last.push(value);
else
{
Stack newStack = new Stack(capacity);
newStack.push(value);
res.add(newStack);
}
}
public int pop(){
Stack last = getLastStack();
int value = last.pop();
if(last.size == 0)
res.remove(res.size()-1);
return value;
}
public Stack getLastStack(res){
if(res.size() == 0)
return null;
else
return res.(res.size()-1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment