What's wrong with this program?input [3,3,4,3,0] 3


  • 0
    S
    public double findMaxAverage(int[] nums, int k) {
        int anchor=nums[0];
        double sum=nums[0];
        for(int i=1;i<nums.length;i++)
        {
                if(k-i==0)
                {
                    anchor=Math.max(nums[i],anchor+nums[i]);
                    sum=Math.max(sum,anchor);
                }
        }
        return sum/k;
    }

Log in to reply
 

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