forked from zchenpy/DS_Leetcode_82-problems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
0641. Design Circular Deque.py
51 lines (38 loc) · 1.17 KB
/
0641. Design Circular Deque.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
641. Design Circular Deque
https://leetcode.com/problems/design-circular-deque/
class MyCircularDeque:
def __init__(self, k: int):
self.queue=deque([])
self.size=k
def insertFront(self, value: int) -> bool:
if len(self.queue)<self.size:
self.queue.insert(0,value)
return True
return False
def insertLast(self, value: int) -> bool:
if len(self.queue) <self.size:
self.queue.append(value)
return True
return False
def deleteFront(self) -> bool:
if self.queue:
self.queue.popleft()
return True
return False
def deleteLast(self) -> bool:
if self.queue:
self.queue.pop()
return True
return False
def getFront(self) -> int:
if self.queue:
return self.queue[0]
return -1
def getRear(self) -> int:
if self.queue:
return self.queue[-1]
return -1
def isEmpty(self) -> bool:
return len(self.queue) == 0
def isFull(self) -> bool:
return len(self.queue) == self.size