-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathcontainer-design-ii.py
38 lines (34 loc) · 1004 Bytes
/
container-design-ii.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
class MyContainerII:
def __init__(self):
# initialize your data structure here
self.data = []
self.sum = 0
"""
@param element: element: Add element into this container.
@return: nothing
"""
def add(self, element):
# write your code here
for i in range(len(self.data)):
if self.data[i] == element:
return
self.data.append(element)
self.sum += element
"""
@param element: element: Remove element into this container.
@return: nothing
"""
def remove(self, element):
# write your code here
for i in range(len(self.data)):
if self.data[i] == element:
self.data.pop(i)
self.sum -= element
break
"""
@return: Sum of integers.
"""
def getSum(self):
# write your code here
return self.sum
# easy: https://www.lintcode.com/problem/container-design-ii/