Skip to content

Instantly share code, notes, and snippets.

@marsp0
Created April 17, 2018 14:49
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 marsp0/e32bebb0e6da9ecd1853fa4bc52f2fbd to your computer and use it in GitHub Desktop.
Save marsp0/e32bebb0e6da9ecd1853fa4bc52f2fbd to your computer and use it in GitHub Desktop.
package main
//Naive approach
func twoSumNaive(numbers []int, target int) []int {
var toReturn = []int{}
for i := 0; i < len(numbers); i++ {
var current = numbers[i]
var toFind = target - current
for j := i + 1; j < len(numbers); j++ {
if numbers[j] == toFind {
toReturn = append(toReturn, i+1)
toReturn = append(toReturn, j+1)
} else if numbers[j] > toFind {
break
}
}
}
return toReturn
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment