Created
April 17, 2018 14:49
-
-
Save marsp0/e32bebb0e6da9ecd1853fa4bc52f2fbd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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