Skip to content

Commit 434052d

Browse files
committed
add twosum solution
1 parent 3ae16b0 commit 434052d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

go/1-Two-Sum.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package main
2+
3+
func twoSum(nums []int, target int) []int {
4+
prevMap := make(map[int]int)
5+
for i, num := range nums {
6+
if j, ok := prevMap[target-num]; ok {
7+
return []int{j, i}
8+
}
9+
prevMap[num] = i
10+
}
11+
return []int{}
12+
}

0 commit comments

Comments
 (0)