Leetcode

1. Two Sum

  • 使用哈希表, 查找 target - num 是否存在于hash table中, 查询速度更快
    • 在Python中hash table使用字典实现, 交换原list中的idxnum的位置, 将num作为字典中的key, idx作为字典的value.

2. Add Two Numbers

  • 技巧: 迭代2个链表的同时,顺便进行计算,使算法复杂度大大降低.

3. Longest Substring Without Repeating Characters

  • 滑动窗口法

4. Median of Two Sorted Arrays

  • TODO O(log(m+n))