Created
August 24, 2021 21:01
-
-
Save kYroL01/99f129e1cffd058024d9e7c23b9ade5a to your computer and use it in GitHub Desktop.
Fast two sum - alternative way instead of two for loops
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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