Java Solution - Rotate Indices


  • 0
    P
    public int maxRotateFunction(int[] A) {
            if(A.length==0 || A==null) return 0;
            int len = A.length;
            int sum,i=0,j=0,pos;
            int maxSum = Integer.MIN_VALUE;
            while(i<len){
                sum=0;pos=0;
                while(pos<len){
                    if(j==len) j=0;
                    sum = sum+A[j]*pos++;
                    j++;
                }
                j=i++;
                maxSum = Math.max(sum,maxSum);
            }
            return maxSum;
        }
    

Log in to reply
 

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