Problem 2
This commit is contained in:
parent
f1dc228da4
commit
83d8df7520
2
main.go
2
main.go
@ -3,5 +3,5 @@ package main
|
|||||||
import "log"
|
import "log"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.Println(problem1(16, []int{10, 15, 3, 7}))
|
log.Println(problem2([]int{3, 2, 1}))
|
||||||
}
|
}
|
||||||
|
|||||||
18
problem2.go
Normal file
18
problem2.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
func problem2(nums []int) []int {
|
||||||
|
var out []int
|
||||||
|
for i := range nums {
|
||||||
|
val := multiplySlice(nums[:i]) * multiplySlice(nums[i+1:])
|
||||||
|
out = append(out, val)
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func multiplySlice(nums []int) int {
|
||||||
|
out := 1
|
||||||
|
for _, num := range nums {
|
||||||
|
out *= num
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user