diff --git a/2024/03/02/LeetCode01/index.html b/2024/03/02/LeetCode01/index.html index 23b7a61..917d26c 100644 --- a/2024/03/02/LeetCode01/index.html +++ b/2024/03/02/LeetCode01/index.html @@ -25,7 +25,7 @@ - + @@ -304,7 +304,7 @@

题解方法二:哈希表

对于数组中的每一个数x,首先查询哈希表中是否存在target-x,如果存在则返回结果,不存在就将x插入到哈希表中,保证不会让x和自己匹配。

1
2
3
4
5
6
7
8
9
10
11
class Solution:
def twoSum(self,nums,target):
hashtable = dict()
for i,num in enumerate(nums):
num2 = target - num
print(num,num2)
if num2 in hashtable:
return [i,hashtable[num2]]
hashtable[num] = i
print(hashtable)
return []
-

知识点