Problem 1
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "log"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
log.Println(problem1(16, []int{10, 15, 3, 7}))
|
||||||
|
}
|
||||||
+18
@@ -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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user