mirror of
https://github.com/lWolvesl/leetcode.git
synced 2026-01-13 02:38:37 +08:00
routine
This commit is contained in:
22
25/11/go/3432.go
Normal file
22
25/11/go/3432.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package L12
|
||||
|
||||
func countPartitions(nums []int) int {
|
||||
n := len(nums)
|
||||
count := 0
|
||||
prefix := make([]int, n)
|
||||
for i, v := range nums {
|
||||
count += v
|
||||
prefix[i] = count
|
||||
}
|
||||
|
||||
ans := 0
|
||||
for i, v := range prefix {
|
||||
if i == n-1 {
|
||||
break
|
||||
}
|
||||
if (count-2*v)%2 == 0 {
|
||||
ans++
|
||||
}
|
||||
}
|
||||
return ans
|
||||
}
|
||||
Reference in New Issue
Block a user