-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon_mistakes.txt
31 lines (29 loc) · 1.11 KB
/
common_mistakes.txt
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
1. use dot "." to access class member, not "->"
2. be careful with '/' operator if you want to get float result
3. missing return statement
4. append element to a linked list needs to keep track of the tail or you will always
end up with setting head.next so the list will alway be of size 2
5. forloop does not work for linked list
6. linked list questions usually need two variables: head and cur
7. [0 for x in range(256)] should be [0 for _ in range(256)]
8. if/else unnecessary nesting
if ...:
return False
else xxx:
do_sth()
should be
if ...:
return False
do_sth()
9. checker >> 1 does not change a. it should be checker >>= 1.
example: 1.4 palindrome_permutation_2
10. always test hot spots such as empty string as input
example: 1.5 one_away_1 at Hot Spot 1 & 2
11. for i in len(xxx)
- this should be for i in range(len(xxx))
12. 'header'.join(['a', 'b'])
- this does not produce: 'headerab', instead it will output 'aheaderb'
- the right way to do it is: 'header' + ''.join(['a', 'b'])
13. while len(lst) > 0:
data = lst.pop()
this will have side effect on the list. not recommended for looping a list