其他分享
首页 > 其他分享> > #力扣 LeetCode面试题 03.01. 三合一 @FDDLC

#力扣 LeetCode面试题 03.01. 三合一 @FDDLC

作者:互联网

题目描述:

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;
    }
}

 

 

 

 

标签:stackNum,面试题,TripleInOne,int,力扣,stackSize,03.01,public
来源: https://blog.csdn.net/liuxc324/article/details/115570639