题目描述:
https://leetcode-cn.com/problems/three-in-one-lcci/
Java代码:
class TripleInOne {
int[][] a;
public TripleInOne(int stackSize) {
a=new int[3][stackSize+1];
a[0][0]=a[1][0]=a[2][0]=1;
}
public void push(int stackNum, int value) {
if(a[stackNum][0]<a[0].length)a[stackNum][a[stackNum][0]++]=value;
}
public int pop(int stackNum) {
return a[stackNum][0]==1?-1:a[stackNum][--a[stackNum][0]];
}
public int peek(int stackNum) {
return a[stackNum][0]==1?-1:a[stackNum][a[stackNum][0]-1];
}
public boolean isEmpty(int stackNum) {
return a[stackNum][0]==1;
}
}