-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path641. Design Circular Deque.py
54 lines (45 loc) · 1.2 KB
/
641. 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
52
53
54
class MyCircularDeque:
def __init__(self, k: int):
self.que = deque([])
self.max_size = k
def insertFront(self, value: int) -> bool:
if len(self.que) < self.max_size:
self.que.appendleft(value)
return True
else:
return False
def insertLast(self, value: int) -> bool:
if len(self.que) < self.max_size:
self.que.append(value)
return True
else:
return False
def deleteFront(self) -> bool:
if self.que:
self.que.popleft()
return True
else:
return False
def deleteLast(self) -> bool:
if self.que:
self.que.pop()
return True
else:
return False
def getFront(self) -> int:
if self.que:
return self.que[0]
else:
return -1
def getRear(self) -> int:
if self.que:
return self.que[-1]
else:
return -1
def isEmpty(self) -> bool:
if self.que:
return False
else:
return True
def isFull(self) -> bool:
return len(self.que) == self.max_size