Accepted Golang solution


  • 0
    M
    func twoSum(nums []int, target int) []int {
        d := make([]int, 2)
        mymap := make(map[int]int)
        for idx, num := range nums {
            //fmt.Printf("%d\n", num )
            _, ok := mymap[target-num]
            if ok {
                d[0] = mymap[target-num]
                d[1] = idx
                return d
            } else {
                mymap[num] = idx
            }
        }
        return d
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.