Skip to content

Commit aa011de

Browse files
authored
two sum solution
1 parent 8b2a045 commit aa011de

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

two-sum/yhkee0404.go

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

0 commit comments

Comments
 (0)