-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLC0484.py
40 lines (32 loc) · 950 Bytes
/
LC0484.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
class MyCircularDeque:
def __init__(self, k: int):
self.maxSize = k
self.dq = deque()
def insertFront(self, value: int) -> bool:
if len(self.dq) < self.maxSize:
self.dq.appendleft(value)
return True
def insertLast(self, value: int) -> bool:
if len(self.dq) < self.maxSize:
self.dq.append(value)
return True
def deleteFront(self) -> bool:
if self.dq:
self.dq.popleft()
return True
def deleteLast(self) -> bool:
if self.dq:
self.dq.pop()
return True
def getFront(self) -> int:
if self.dq:
return self.dq[0]
return -1
def getRear(self) -> int:
if self.dq:
return self.dq[-1]
return -1
def isEmpty(self) -> bool:
return not self.dq
def isFull(self) -> bool:
return len(self.dq) == self.maxSize