标签:
https://leetcode.com/problems/rotate-function/ public class Solution { public int maxRotateFunction(int[] A) { int all = 0; int sum = 0; int ret = Integer.MIN_VALUE; for (int i=0; i<A.length; i++) { all += A[i]; sum += i * A[i]; } if (sum > ret) { ret = sum; } for (int i=A.length-1; i>0; i--) { sum -= A.length * A[i]; sum += all; if (sum > ret) { ret = sum; } } return ret; } }
标签:
原文地址:http://www.cnblogs.com/charlesblc/p/5880014.html