Skip to content

Commit da4a5d5

Browse files
two sum solution
1 parent c10802e commit da4a5d5

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

two-sum/youngDaLee.go

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

0 commit comments

Comments
 (0)