class MyCircularDeque:
def __init__(self, k: int):
"""
Initialize your data structure here. Set the size of the deque to be k.
"""
# 长度为k时占用k+1的空间,多出来的空间用来区分isEmpty和isFull
# 首尾两个指针相等的时候为empty,尾部+1等于首部的时候为Full
self.q = [0] * (k + 1)
self.len = k + 1
self.rear = 0
self.front = 0
def move_forward(self, pos):
return (pos + 1) % self.len
def move_backward(self, pos):#设计函数简化后边
return
数组实现的循环双端队列
最新推荐文章于 2024-04-22 17:18:34 发布