[简单] 622. 设计循环队列

https://leetcode-cn.com/problems/design-circular-queue/

 

请原谅我直接,这一题。。。我这么傻心里都嘀咕,怎么出得那么傻~没有灵魂得题目。

 

class MyCircularQueue {


    List<Integer> queue = new ArrayList<>();
    Integer capacity = 100000;

    public MyCircularQueue(int k) {
        capacity = k;
    }

    public boolean enQueue(int value) {
        if (queue.size() < capacity) {
            queue.add(value);
            return true;
        }
        return false;
    }

    public boolean deQueue() {
        if(queue.size() == 0) {
            return false;
        }
        queue.remove(0);
        return true;
    }

    public int Front() {
        if(queue.size() == 0) {
            return -1;
        }
        return queue.get(0);
    }

    public int Rear() {
        if(queue.size() == 0) {
            return -1;
        }
        return queue.get(queue.size()  -1);
    }

    public boolean isEmpty() {
        return (queue.size() == 0);
    }

    public boolean isFull() {
        return (queue.size() == capacity);
    }
}

/**
 * Your MyCircularQueue object will be instantiated and called as such:
 * MyCircularQueue obj = new MyCircularQueue(k);
 * boolean param_1 = obj.enQueue(value);
 * boolean param_2 = obj.deQueue();
 * int param_3 = obj.Front();
 * int param_4 = obj.Rear();
 * boolean param_5 = obj.isEmpty();
 * boolean param_6 = obj.isFull();
 */
View Code

 

posted @ 2022-04-04 02:35  v大喵  阅读(20)  评论(0编辑  收藏  举报