首页 > 代码库 > rotate-function

rotate-function

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;    }}

 

rotate-function