问题:
题目来源:力扣(LeetCode)
难度:中等
分析:
按照逻辑实现就可,这个题的技巧在于取模和加自身数组长度,用于实现双端循环。
同时多使用了一位空闲位在尾指针的后面,用于区分满队列和空队列。
解决方法:
1:
#取模操作很重要
#多加一位用于区分满队列和空队列
class MyCircularDeque:
def __init__(self, k: int):
"""
Initialize your data structure here. Set the size of the deque to be k.
"""
self.front = 0
self.rear = 0
self.capacity = k + 1
self.arr = [0 for _ in range(self.capacity)]
def insertFront(self, value: int)