- Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy patharraylist.py
More file actions
Latest commit
64 lines (53 loc) · 1.65 KB
/
Copy patharraylist.py
File metadata and controls
64 lines (53 loc) · 1.65 KB
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
classArrayListManager:
'''
* @param n: You should generate an array list of n elements.
* @return: The array list your just created.
'''
defcreate(self, n):
# Write your code here
self.arr= [iforiinrange(n)]
returnself.arr
'''
* @param list: The list you need to clone
* @return: A deep copyed array list from the given list
'''
defclone(self, list):
# Write your code here
return [iforiinlist]
'''
* @param list: The array list to find the kth element
* @param k: Find the kth element
* @return: The kth element
'''
defget(self, list, k):
# Write your code here
returnlist[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
'''
defset(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
'''
defremove(self, list, k):
# write tour code here
foriinrange(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
'''
defindexOf(self, list, val):
# Write your code here
foriinrange(len(list)):
iflist[i] ==val:
returni
return-1
# easy: https://www.lintcode.com/problem/385/