Skip to content

Commit 3f9420f

Browse files
feat: two sum
1 parent 6b6875b commit 3f9420f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

resolved/two-sum.go

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package resolved
2+
3+
func TwoSum(numbers []int, target int) []int {
4+
hashTable := make(map[int]int)
5+
6+
for i, v := range numbers {
7+
dif := target - v
8+
9+
if idx, ok := hashTable[dif]; ok {
10+
return []int{idx, i}
11+
}
12+
hashTable[v] = i
13+
}
14+
return nil
15+
}

0 commit comments

Comments
 (0)