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的更多相关文章
- [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 ...
- 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 ...
- 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 ...
- [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 ...
- 396. Rotate Function 移动加权求和,取最大值
[抄题]: Given an array of integers A and let n to be its length. Assume Bk to be an array obtained by ...
- 【LeetCode】396. Rotate Function 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/rotate-fu ...
- 【leetcode❤python】 396. Rotate Function
#-*- coding: UTF-8 -*- #超时# lenA=len(A)# maxSum=[]# count=0# while count ...
- 396. Rotate Function
一开始没察觉到0123 3012 2301 而不是 0123 1230 2301 的原因,所以也没找到规律,一怒之下brute-force.. public int maxRotateFunction ...
- 396 Rotate Function 旋转函数
给定一个长度为 n 的整数数组 A .假设 Bk 是数组 A 顺时针旋转 k 个位置后的数组,我们定义 A 的“旋转函数” F 为:F(k) = 0 * Bk[0] + 1 * Bk[1] + ... ...
- 理解JavaScript中的参数传递 - leetcode189. Rotate Array
1.关于leetcode 这是第一篇关于leetcode的题解,就先扯点关于leetcode的话. 其实很早前就在博客园看到过leetcode一些题解,总以为跟一般OJ大同小异,直到最近点开了一篇博文 ...
随机推荐
- Tuning Optimization
2017-02-22 在经过Trace的分析并重新优化之后 CPU: Intel(R) Xeon(R) CPU E5-2630 v2 @ 2.6GHz 24core 如上图,CPU使用率平均低于60% ...
- DDR3调试记录
FPGA采集视频数据并写到DDR3,然后从DDR3读出并送给显示终端显示.不能稳定显示.但用FPGA内部逻辑产生color bar写到DDR3后读出来显示正常.因此DDR3部分逻辑没有问题 ...
- Web2.0应用程序的7条原则
个人看好Web的发展潜力,本文字摘自<Collective Intelligence 实战> 网络是平台 使用传统许可模式软件的公司或用户必须运行软件.定期更新至最新版本,以及扩展它来满足 ...
- android 单位 什么是屏幕密度?
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha sp dp px in in 表示英寸, 是屏幕的物理尺寸.1英寸是2.54厘米. dp ...
- Codeforces Round #448 C. Square Subsets
题目链接 Codeforces Round #448 C. Square Subsets 题解 质因数 *质因数 = 平方数,问题转化成求异或方程组解的个数 求出答案就是\(2^{自由元-1}\) , ...
- TF-timeline的使用经验记录
timeline的使用经验记录:https://towardsdatascience.com/howto-profile-tensorflow-1a49fb18073d 看了TF-summit2018 ...
- 【洛谷】1494:[国家集训队]小Z的袜子【莫队】
P1494 [国家集训队]小Z的袜子 题目描述 作为一个生活散漫的人,小Z每天早上都要耗费很久从一堆五颜六色的袜子中找出一双来穿.终于有一天,小Z再也无法忍受这恼人的找袜子过程,于是他决定听天由命…… ...
- nodejs环境使用jshint
一.概述jshint是检测JavaScript语法问题的工具,可以根据自己的需要配置检测规则. 二.安装npm install jshint -g一般全局安装就可以了,可以在任何目录下使用jshint ...
- DataTable初次使用笔记
概述:DataTable是一个jQuery插件,用于生成HTML表格,功能很强大. 使用: 使用DataTable需要引入jQuery,因为他是基于jQuery的插件,然后引入DataTable的js ...
- python开发_thread_布朗运动
这篇blog是非常有趣的,是的,他非常有趣 下面我将给大家介绍有关python中thread来实现布朗运动的一个例子 下面是运行效果: ================================ ...