|  | 
 
| 
设计循环队列问题中 获取队尾元素代码没有看懂具体内容如下
x
马上注册,结交更多好友,享用更多功能^_^您需要 登录 才可以下载或查看,没有账号?立即注册  class MyCircularQueue():
 
 def __init__(self, k):
 """
 Initialize your data structure here. Set the size of the queue to be k.
 :type k: int
 """
 self.a = [0]*k
 self.head = 0
 self.tail = 0
 self.max_size = k
 self.size = 0
 
 
 
 def Rear(self):
 """
 Get the last item from the queue.
 :rtype: int
 """
 
 if self.size == 0:
 return -1
 cur = self.tail
 cur -= 1
 cur = (cur + self.max_size)%self.max_size
 return self.a[cur]
 
 在获取队尾的元素时为什么不是直接
 cur = self.tail
 return self.a[cur]
 还需要
 cur = self.tail
 cur -= 1
 cur = (cur + self.max_size)%self.max_size
 return self.a[cur]
 
 
 
 | 
 |