1524. Number of Sub-arrays With Odd Sum

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 1524

class Solution:
    def numOfSubarrays(self, arr: List[int]) -> int:
        mod = 10**9 + 7
        cnt = [1, 0]
        res = s = 0
        for x in arr:
            s += x
            res = (res + cnt[s & 1 ^ 1]) % mod
            cnt[s & 1] += 1
        return res