Accepted Golang O(n) 9ms


  • 0
    M

    func twoSum(nums []int, target int) []int {
    mapContainer := make (map[int]int)
    for i, _ := range nums {
    if _, ok := mapContainer[target-nums[i]]; !ok {
    mapContainer[nums[i]] = i

        } else {
            return []int{mapContainer[target-nums[i]],i}
        }
    }
    return nums
    

    }


Log in to reply
 

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