add new solutions

This commit is contained in:
kanna5 2026-01-05 16:48:03 +09:00
parent ca24d0a56a
commit 0c73608ce5
Signed by: kkyy
GPG key ID: 06332F3965E9B0CF
36 changed files with 791 additions and 0 deletions

View file

@ -0,0 +1,28 @@
package q3354
func countValidSelections(nums []int) int {
sumR := 0
for i := range nums {
sumR += nums[i]
}
sumL := 0
nValid := 0
for i := range nums {
sumR -= nums[i]
if i > 0 {
sumL += nums[i-1]
}
if nums[i] == 0 {
diff := sumL - sumR
if diff == 0 {
nValid += 2
} else if diff*diff == 1 {
nValid++
}
}
}
return nValid
}
var _ = countValidSelections