码迷,mamicode.com
首页 > 其他好文 > 详细

rotate-function

时间:2016-09-17 23:42:53      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

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

标签:

原文地址:http://www.cnblogs.com/charlesblc/p/5880014.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!