-
-
Save JamesJi9277/d3e68b23802de5afc31a to your computer and use it in GitHub Desktop.
3.3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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