12ms easy solution in Go


  • 1
    T
    func twoSum(nums []int, target int) []int {
        m := make(map[int]int)
        for i, v := range nums {
            if j, ok := m[target - v]; ok {             
                return []int{j, i}
            } else {
                m[v] = i
            }
        }
        return []int{-1, -1}
    }

  • 0
    N

    A very crafty solution!


Log in to reply
 

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