#力扣 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;
    }
}

 

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

 

 

 

上一篇:go入门——项目搭建


下一篇:STM32 PWM波比较输出