feat(1-two-sum): add golang best soln

This commit is contained in:
Sangeeth Sudheer 2022-01-01 22:24:04 +05:30
parent 6e6014bcc8
commit 54afd0abcc

View File

@ -0,0 +1,14 @@
func twoSum(nums []int, target int) []int {
// Optimal solution: using a hashtable
m := make(map[int]int)
for i, num := range nums {
if j, ok := m[target-num]; ok {
return []int{i, j}
}
m[num] = i
}
return []int{}
}