Rotate Function

https://www.lintcode.com/problem/rotate-function/description

public class Solution {
    /**
     * @param A: an array
     * @return: the maximum value of F(0), F(1), ..., F(n-1)
     */
    public int maxRotateFunction(int[] A) {
        // Write your code here
//        转化成数组不变,角标在变大,
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < A.length; i++) {
            int temp = 0;
            for (int j = 0; j < A.length; j++) {
                temp += A[j] * ((i + j) % A.length);
            }
            max = Math.max(temp, max);
        }
        return max;
    }
}

你可能感兴趣的:(Rotate Function)