Problem 1
This commit is contained in:
commit
f1dc228da4
7
main.go
Normal file
7
main.go
Normal 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
18
problem1.go
Normal 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
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user