1. 两数之和
点击查看折叠代码块
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
dic = {}
for i, x in enumerate(nums):
dic[x] = i
for i, x in enumerate(nums):
if target - x in dic and dic[target - x] != i:
return [i, dic[target - x]]