# LeetCode
- Medium
- Search in Rotated Sorted Array (33):
- My ans:
- Use Binary Search twice for pivot and target
- collect mid_index in the function
- Best ans:
- 4 situations
- if mid < target:
- target > or < right
- Combination Sum (39):
- My ans:
- DFS + Recursion + Global Variable sum outside
- Best ans:
- Global Variable sum outside -> as input of function + for loop
- Rotate Image (48):
- 90 degree -> reverse + transpose
- pythonic but not full inline: reverse + zip(*A)
- Group Anagrams (49):
- My ans:
- Find if the permutation of word been listed with for loop
- Best ans:
- Use [sorted](https://docs.python.org/3/howto/sorting.html)!!!
- Maximum Subarray (53):
- My ans:
- [kadane's algorithm](https://www.codingninjas.com/blog/2020/09/17/a-quick-look-at-kadanes-algorithm/)
- Why all other answers are slow?
- Spiral Matrix (54):
- My ans/Best ans:
- Spin -90 degree
- Merge Intervals (56):
- My ans:
- sorted + care about the merged interval sup/inf
- Insert Interval (57):
- My ans:
- Insert + Sort + Merge
- Unique Paths (62):
- My ans:
- Easy Math (permute $m$a and $n$b)
- Set Matrix Zeroes (73):
- My ans:
- record zero rows + columns -> space O(m+n)
- Best ans:
- if M(i, j) = 0 -> M(i, 0) = M(0, j) = 0
- traverse again and refer to M(i, 0) & M(0, j)
- update first row/column
- Decode Ways (91):
- My ans:
- for loop + residual dp
- Best ans:
- length+char dp
# 注意:
1. tree
2. graph
3. DP