Skip to content

Instantly share code, notes, and snippets.

@MorrisLaw
Last active June 3, 2022 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MorrisLaw/2a76fe081c5d456281af1655653ebc79 to your computer and use it in GitHub Desktop.
Save MorrisLaw/2a76fe081c5d456281af1655653ebc79 to your computer and use it in GitHub Desktop.
Two Sum - LeetCode 1
func twoSum(nums []int, target int) []int {
hm := make(map[int]int)
for i, n := range nums {
if j, exists := hm[n]; exists {
return []int{i, j}
}
hm[target-n] = i
}
return []int{}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment