Problem 1

This commit is contained in:
Dustin Pianalto 2020-08-29 19:56:22 -08:00
commit f1dc228da4
2 changed files with 25 additions and 0 deletions

7
main.go Normal file
View File

@ -0,0 +1,7 @@
package main
import "log"
func main() {
log.Println(problem1(16, []int{10, 15, 3, 7}))
}

18
problem1.go Normal file
View File

@ -0,0 +1,18 @@
package main
func problem1(val int, nums []int) bool {
if len(nums) == 0 {
return false
}
comp := make(map[int]struct{})
for _, num := range nums {
if _, ok := comp[val-num]; ok {
return true
}
comp[num] = struct{}{}
}
return false
}