Skip to content

Instantly share code, notes, and snippets.

@anirudhjain75
Created January 10, 2020 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anirudhjain75/47f78ce404327ee7eadff3d767fef975 to your computer and use it in GitHub Desktop.
Save anirudhjain75/47f78ce404327ee7eadff3d767fef975 to your computer and use it in GitHub Desktop.
package main
import "fmt"
func twoSum(intArr []int, sum int) (int, int) {
m := make(map[int]int)
for _, v := range intArr {
m[v] = v
}
a, b := 0, 0
for i:=0; i<len(intArr); i++ {
v, err := m[sum - intArr[i]]
if err {
a = v
b = intArr[i]
fmt.Println(a, b)
} else {
continue
}
}
return a, b
}
func main() {
fmt.Println(twoSum([]int{1,2,3,4,5,6,7,11,9}, 10))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment