From 6b559c5163522728fcc32d4663409fe704fa7583 Mon Sep 17 00:00:00 2001 From: anan <771181720@qq.com> Date: Sat, 2 Mar 2024 15:09:21 +0800 Subject: [PATCH] Site updated: 2024-03-02 15:09:21 --- 2024/03/02/LeetCode01/index.html | 4 ++-- categories/index.html | 32 ++++++++++++++++---------------- local-search.xml | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) 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 []
-

知识点