标签:UNC range sub maps func ack tar subscript port
package main
import (
"fmt"
)
func main() {
nums := []int{1, 3, 4, 6, 7, 10}
target := 17
newArr := twoSum(nums, target)
fmt.Println(newArr)
}
func twoSum(nums []int, target int) [2]int {
maps := make(map[int]int)
for index, value := range nums {
member := target - value
if _, ok := maps[member]; ok {
subscript := [...]int{member, value}
for i,v := range subscript{
for i1,v1 := range nums{
if v == v1 {
subscript[i]= i1
}
}
}
return subscript
} else {
maps[value] = index
}
}
return [2]int{}
}
标签:UNC range sub maps func ack tar subscript port
原文地址:http://blog.51cto.com/hequan/2326340