LeetCode #1524

Number of Sub-arrays With Odd Sum

1개의 풀이 · C++

문제 원문 보기 ↗

SOLUTION INFO

C++ · main.cpp

main.cpp
class Solution {
public:
    int numOfSubarrays(vector<int>& arr) {
        const int MOD = 1e9 + 7;
        int cnt = 0, sum = 0, N = (int)arr.size();
        for(const int &x: arr) {
            sum += x;
            if(sum % 2) ++ cnt;
        }
        return cnt * (1LL + N - cnt) % MOD;
    }
};

SOLUTION DESCRIPTION

풀이 설명

등록된 풀이 설명이 없습니다.