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的更多相关文章

  1. [LeetCode] Rotate Function 旋转函数

    Given an array of integers A and let n to be its length. Assume Bk to be an array obtained by rotati ...

  2. LeetCode 396. Rotate Function

    Given an array of integers A and let n to be its length. Assume Bk to be an array obtained by rotati ...

  3. Leetcode: Rotate Function

    Given an array of integers A and let n to be its length. Assume Bk to be an array obtained by rotati ...

  4. [Swift]LeetCode396. 旋转函数 | Rotate Function

    Given an array of integers A and let n to be its length. Assume Bk to be an array obtained by rotati ...

  5. 396. Rotate Function 移动加权求和,取最大值

    [抄题]: Given an array of integers A and let n to be its length. Assume Bk to be an array obtained by ...

  6. 【LeetCode】396. Rotate Function 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/rotate-fu ...

  7. 【leetcode❤python】 396. Rotate Function

    #-*- coding: UTF-8 -*- #超时#        lenA=len(A)#        maxSum=[]#        count=0#        while count ...

  8. 396. Rotate Function

    一开始没察觉到0123 3012 2301 而不是 0123 1230 2301 的原因,所以也没找到规律,一怒之下brute-force.. public int maxRotateFunction ...

  9. 396 Rotate Function 旋转函数

    给定一个长度为 n 的整数数组 A .假设 Bk 是数组 A 顺时针旋转 k 个位置后的数组,我们定义 A 的“旋转函数” F 为:F(k) = 0 * Bk[0] + 1 * Bk[1] + ... ...

  10. 理解JavaScript中的参数传递 - leetcode189. Rotate Array

    1.关于leetcode 这是第一篇关于leetcode的题解,就先扯点关于leetcode的话. 其实很早前就在博客园看到过leetcode一些题解,总以为跟一般OJ大同小异,直到最近点开了一篇博文 ...

随机推荐

  1. 005 Ajax中使用jquery实现三种格式的信息

    1.jquery中的ajax 二:load 2.load方法 3.load测试程序大纲 4.load测试程序 <!DOCTYPE html> <html> <head&g ...

  2. JavaScript对象参考手册

    1.array 属性: constructor 返回原型函数: length 数组个数: prototype 向对象添加属性和方法 方法: concat() 连接两个或多个数组,并返回结果: fill ...

  3. Eclipse中syso 快捷键 Alt + / 不能使用的问题

    通过使用windows-preferences-java-editor-templates中的快捷键,可以显著提升输入速度.快捷键的设置一般是在这里以及general下面的keys里面设置. 但是,在 ...

  4. 传递 hdu 5961 拓扑排序有无环~

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5961 题目为中文,这里就不描述题意了. 思路: 从题目陈述来看,他将一个有向图用一个邻接矩阵来表示,并且分 ...

  5. 1019 General Palindromic Number (20)(20 point(s))

    problem A number that will be the same when it is written forwards or backwards is known as a Palind ...

  6. sublime用浏览器打开html文件

    打开Preferences - 「Key Bindings - User」,添加此行: {"keys": ["ctrl+b"],"command&qu ...

  7. [ 原创 ] Java基础7--Java反射机制主要提供了以下哪些功能?

    AVA反射机制主要提供了以下哪些功能? 在运行时判断一个对象所属的类 在运行时构造一个类的对象 在运行时判断一个类所具有的成员变量和方法 在运行时调用一个对象的方法

  8. 安卓手机安装 Charles 证书

    1: 在  Charles 工具栏里点击 Help --- SSL Proxying --- Save Charles Root Certificate,生成 后缀名是 .cer 的文件, 然后上传到 ...

  9. 【CF 585E】 E. Present for Vitalik the Philatelist

    E. Present for Vitalik the Philatelist time limit per test 5 seconds memory limit per test 256 megab ...

  10. Xshell6和Xftp下载地址,rzsz的使用

    官方下载地址:https://cdn.netsarang.net/98f59c09/Xshell-6.0.0076r_beta.exe https://cdn.netsarang.net/98f59c ...