-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy patharraylist.py
64 lines (53 loc) · 1.65 KB
/
arraylist.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
57
58
59
60
61
62
63
64
class ArrayListManager:
'''
* @param n: You should generate an array list of n elements.
* @return: The array list your just created.
'''
def create(self, n):
# Write your code here
self.arr = [i for i in range(n)]
return self.arr
'''
* @param list: The list you need to clone
* @return: A deep copyed array list from the given list
'''
def clone(self, list):
# Write your code here
return [i for i in list]
'''
* @param list: The array list to find the kth element
* @param k: Find the kth element
* @return: The kth element
'''
def get(self, list, k):
# Write your code here
return list[k]
'''
* @param list: The array list
* @param k: Find the kth element, set it to val
* @param val: Find the kth element, set it to val
'''
def set(self, list, k, val):
# write your code here
list[k] = val
'''
* @param list: The array list to remove the kth element
* @param k: Remove the kth element
'''
def remove(self, list, k):
# write tour code here
for i in range(k, len(list) - 1):
list[i] = list[i + 1]
list.pop()
'''
* @param list: The array list.
* @param val: Get the index of the first element that equals to val
* @return: Return the index of that element
'''
def indexOf(self, list, val):
# Write your code here
for i in range(len(list)):
if list[i] == val:
return i
return -1
# easy: https://www.lintcode.com/problem/385/