Created
May 11, 2024 03:26
-
-
Save ksamirdev/a07122635fdd3ab9a08f932f64b2fd44 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { | |
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