forked from ls1248659692/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.py
More file actions
37 lines (27 loc) · 615 Bytes
/
Copy patharray.py
File metadata and controls
37 lines (27 loc) · 615 Bytes
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
# list is a collection which is ordered and changeable, with continuous space.
#
# Time: O(1) to index or write or append, O(n) to insert or remove
# Space: O(n)
def list_operations():
# initialization
list1 = [3, 1, 2, 4]
list2 = list(range(5))
# [*X] equals to list(X)
list2 = [*range(5)]
# append
list1.append(5)
list1 += [5]
list1 += 5,
list1.extend([5, 6])
# insert
list1.insert(0)
# index
list1.index(3)
# count
list1.count(3)
# remove
list1.remove(3)
# sort
list1.sort(reverse=True)
# reverse
list1.reverse()