mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-07 18:10:29 +08:00
@ -2,12 +2,11 @@ package leetcode
|
|||||||
|
|
||||||
func twoSum(nums []int, target int) []int {
|
func twoSum(nums []int, target int) []int {
|
||||||
m := make(map[int]int)
|
m := make(map[int]int)
|
||||||
for i := 0; i < len(nums); i++ {
|
for k, v := range nums {
|
||||||
another := target - nums[i]
|
if idx, ok := m[target-v]; ok {
|
||||||
if _, ok := m[another]; ok {
|
return []int{idx, k}
|
||||||
return []int{m[another], i}
|
|
||||||
}
|
}
|
||||||
m[nums[i]] = i
|
m[v] = k
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user