Created
April 12, 2018 19:21
-
-
Save ksexton/b3ebe88797e997b3f253589c492d7e6a to your computer and use it in GitHub Desktop.
2018-04-12 daily problem
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
// | |
// Given a list of numbers, return whether any two sums to k. | |
// | |
// For example, given [10, 15, 3, 7] and k of 17, return true since 10 + 7 is 17. | |
// | |
// Bonus: Can you do this in one pass? | |
package main | |
import "fmt" | |
func checkNumbers(numbers []int, total int) bool { | |
l := len(numbers) | |
match := false | |
for k, v := range numbers { | |
if k == (l - 1) { | |
break | |
} else { | |
for i := k + 1; i < l; i++ { | |
fmt.Println(v, " + ", numbers[i], "= ", v+numbers[i]) | |
if v+numbers[i] == total { | |
match = true | |
} | |
} | |
} | |
} | |
return match | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment