-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDesign_circular_deque.py
56 lines (46 loc) · 1.36 KB
/
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
55
56
class MyCircularDeque(object):
def __init__(self, k):
self.list = []
self.maxLength = k
def insertFront(self, value):
if not self.isFull():
self.list.insert(0, value)
return True
return False
def insertLast(self, value):
if not self.isFull():
self.list.append(value)
return True
return False
def deleteFront(self):
if not self.isEmpty():
self.list.pop(0)
return True
return False
def deleteLast(self):
if not self.isEmpty():
self.list.pop()
return True
return False
def getFront(self):
if not self.isEmpty():
return self.list[0]
return -1
def getRear(self):
if not self.isEmpty():
return self.list[-1]
return -1
def isEmpty(self):
return len(self.list) == 0
def isFull(self):
return self.maxLength == len(self.list)
# Your MyCircularDeque object will be instantiated and called as such:
# obj = MyCircularDeque(k)
# param_1 = obj.insertFront(value)
# param_2 = obj.insertLast(value)
# param_3 = obj.deleteFront()
# param_4 = obj.deleteLast()
# param_5 = obj.getFront()
# param_6 = obj.getRear()
# param_7 = obj.isEmpty()
# param_8 = obj.isFull()