力扣第一题的两数之和的Python代码
时间: 2024-05-27 09:13:59 浏览: 140
leetcode练习题——1. 两数之和(python实现)
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
hash_map = {}
for i, num in enumerate(nums):
if target - num in hash_map:
return [hash_map[target - num], i]
hash_map[num] = i
return []
阅读全文