Skip to content

Commit

Permalink
add twosum solution
Browse files Browse the repository at this point in the history
  • Loading branch information
ErdemOzgen committed Jul 18, 2022
1 parent 3ae16b0 commit 434052d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions go/1-Two-Sum.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package main

func twoSum(nums []int, target int) []int {
prevMap := make(map[int]int)
for i, num := range nums {
if j, ok := prevMap[target-num]; ok {
return []int{j, i}
}
prevMap[num] = i
}
return []int{}
}

0 comments on commit 434052d

Please sign in to comment.