-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_3.go
More file actions
48 lines (39 loc) · 784 Bytes
/
task_3.go
File metadata and controls
48 lines (39 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import "fmt"
func main() {
a := []int{4, -1, 0, 3}
b := []int{-2, 5, 0, 3}
// a := []int{2, -2, -3, 3}
// b := []int{0, 0, 4, -4}
fmt.Println(Solution(a, b))
}
// Solution ...
func Solution(A []int, B []int) int {
if len(A) != len(B) {
return 0
}
// length N -> 1, N-1
for index := 1; index <= len(A)-1; index++ {
if findSliceSum(A, index) && findSliceSum(B, index) {
return index
}
}
return 0
}
func findSliceSum(a []int, k int) bool {
slice1 := a[0:k]
slice2 := a[k:]
sum1 := sum(slice1)
sum2 := sum(slice2)
fmt.Println(a)
fmt.Println(slice1, sum1)
fmt.Println(slice2, sum2)
fmt.Println("-----------------------------------------")
return sum1 == sum2
}
func sum(a []int) (sum int) {
for _, i := range a {
sum += i
}
return
}