LeetCode Problem: Two Sum
Problem statement:
Given an array of integers (numbers) and a sum (targetSum), you have to return two indices for which the sum of the values is equal to targetSum
Golang Solution:
func twoSum(numbers []int, targetSum int) []int {
tempMap := map[int]int{}
for index, val := range numbers {
if res, ok := tempMap[targetSum-val]; ok {
return []int{index, res}
} else {
tempMap[val] = index
}
}
return []int{-1, -1}
}