标签:enumerate target class for elf 两数之和 list func rate
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
mapping = {}
for num, value in enumerate(nums):
value2 = target - value
if value2 in mapping:
return [mapping[value2], num]
mapping[value] = num
func twoSum(nums []int, target int) []int {
mapping := map[int]int{}
for n, num := range nums {
num2 := target - num
if _, ok := mapping[num2]; ok {
return []int{mapping[num2], n}
}
mapping[num] = n
}
return []int{0,0}
}
标签:enumerate target class for elf 两数之和 list func rate
原文地址:https://www.cnblogs.com/leisurelylicht/p/1-liang-shu-zhi-he.html