diff --git a/src/hash相关/q1_两数之和/f1/Solution.py b/src/hash相关/q1_两数之和/f1/Solution.py new file mode 100644 index 0000000..af0f7ad --- /dev/null +++ b/src/hash相关/q1_两数之和/f1/Solution.py @@ -0,0 +1,14 @@ +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + res = [] + dicts = {} + if len(nums)<=1: + return res + for i,each in enumerate(nums): + if (target-each) in dicts: + res.append(i) + res.append(dicts[target-each]) + return res + else: + dicts[each] = i + return res