https://leetcode.com/problems/rotate-function/#/description
i是从后向前遍历的
F(1) = F(0) + sum - n * A[i]
public class Solution {
public int maxRotateFunction(int[] A) {
int sum = 0;
int rotate = 0;
for (int i = 0; i < A.length; i++) {
sum += A[i];
rotate += i * A[i];
}
int max = rotate;
for (int i = A.length - 1; i >= 0; i--) {
rotate = rotate + sum - A.length * A[i];
max = Math.max(max, rotate);
}
return max;
}
}