- 使用哈希表, 查找
target - num
是否存在于hash table中, 查询速度更快- 在Python中
hash table
使用字典实现, 交换原list
中的idx
和num
的位置, 将num
作为字典中的key
,idx
作为字典的value
.
- 在Python中
- 技巧: 迭代2个链表的同时,顺便进行计算,使算法复杂度大大降低.
- 滑动窗口法
- TODO O(log(m+n))
target - num
是否存在于hash table中, 查询速度更快
hash table
使用字典实现, 交换原list
中的idx
和num
的位置, 将num
作为字典中的key
, idx
作为字典的value
.