leetcode所有奇数长度子数组的和

Posted 空空如也gx

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode所有奇数长度子数组的和相关的知识,希望对你有一定的参考价值。

 

int sumOddLengthSubarrays(int* arr, int arrSize){
    int i,j,cnt,sum,total=0;
    for(i=0; i<arrSize; i++)
    {
        cnt=0;
        sum=0;
        for(j=i; j<arrSize; j++)
        {
            cnt++;
            sum+=arr[j];
            if(cnt%2)
                total+=sum;
        }
    }
    return total;
}

 

以上是关于leetcode所有奇数长度子数组的和的主要内容,如果未能解决你的问题,请参考以下文章