Skip to content

Instantly share code, notes, and snippets.

@kYroL01
Created August 24, 2021 21:01
Show Gist options
  • Save kYroL01/99f129e1cffd058024d9e7c23b9ade5a to your computer and use it in GitHub Desktop.
Save kYroL01/99f129e1cffd058024d9e7c23b9ade5a to your computer and use it in GitHub Desktop.
Fast two sum - alternative way instead of two for loops
func twoSum(nums []int, target int) []int {
var tempDict = make(map[int]int)
for key, value := range nums {
if _, ok := tempDict[value]; ok{
return []int{tempDict[value], key}
}
tempDict[target-value] = key
}
return []int{}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment