My java solution


  • 0
    C
    public class Solution {
    public int maxRotateFunction(int[] A) {
    	int length = A.length;
    	int [] num = new int [A.length];
    	
    	
    	if(length <= 1)return 0;
    	
    	 num[0] = 0;
    	 num[1] = 0;
    	int sum = 0;
    	
    	for(int i=0;i<length;i++)
    	{
    	    sum+=A[i];
    	}
    	
    	for(int i = 0;i<length;i++)
    	{
    	    num[0] += A[i]*i;
    	}
    	
    	int max = num[0];
    	for(int i=1;i<length;i++)
    	{
    	    num[i] = num[i-1]+sum-length*A[length-i];
    	    
    	    max = num[i]>=max?num[i]:max;
    	}
    	return max;
    }	
    

    }


Log in to reply
 

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