Study notes for data structures & algorithms
Rotate
- 逆推
- Reverse
- Swap (主对角线, 分界线, 轴)
常规手段
- dummy 作哨兵, cur 作游标
- 一直遍历(最长链表), 每次遍历再进行空值判断
Reverse list
- pre, cur, post
Root-to-leaf
- int: a + b (choose a non-empty element between a and b)
- boolean: false (if root is null)
- void: return
Whether the node is empty
- (root) ? null : root
Circular Queue
- 根据 head 和 size 计算出 tail
- 循环: 对 n 取模
Two Sum
- 需要频繁访问 target 时,考虑采用哈希表
KMP
Two Sum
- 返回的是元素而非 index,可考虑排序 + 双指针
Add two numbers
- reverse
- carry : sum / n (n 进制)
- pop : sum % n (n 进制)
Missing number
- Gauss' Formula
