Skip to content

Instantly share code, notes, and snippets.

@samocodes
Created May 11, 2024 03:26
Show Gist options
  • Save samocodes/a07122635fdd3ab9a08f932f64b2fd44 to your computer and use it in GitHub Desktop.
Save samocodes/a07122635fdd3ab9a08f932f64b2fd44 to your computer and use it in GitHub Desktop.
func twoSum(nums []int, target int) []int {
m := make(map[int]int, len(nums))
for i, x := range nums {
y := target - x
if v, ok := m[y]; ok {
return []int{v, i}
}
m[x] = i
}
return []int{}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment