A simple C solution beats 92.16 %[Accepted]


  • 0
    B
    double findMaxAverage(int* nums, int numsSize, int k) {
        int sumMax=0;
        int sum=0;
        for(int i=0;i<k;i++)
        {
            sumMax=sumMax+nums[i];
        }
        sum=sumMax;
        for(int i=k;i<numsSize;i++)
        {
            sum=sum+nums[i]-nums[i-k];
            if(sum>sumMax)
            {sumMax=sum;}
        }
        return (double)sumMax/k;
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.