LeetCode1 两数之和(字典法) class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: m = {} for idx, x in enumerate(nums): y = target - x if y in m: return [m[y], idx] m[x] = idx