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大同小异,直到最近点开了一篇博文 ...
随机推荐
- Thymeleaf(Java模板引擎)
一.概念 1.Thymeleaf是Web和独立环境的开源的Java模板引擎,能够处理HTML,XML,JavaScript,CSS甚至纯文本:2.Thymeleaf可以在Web(基于Servlet)和 ...
- 怎么将maven项目打包成war包
问题:我在eclipse上能运行,然后我想将这个maven项目打包成war然后放到另外一台机子上(其实是手动放在tomcat的webapp目录中),提供外部访问.现在问题是,一直maven项目打包一直 ...
- Android 使用ViewPager 做的半吊子的图片轮播
Android 使用ViewPager 做的半吊子的图片轮播 效果图 虽然不咋样,但是最起码的功能是实现了,下面我们来一步步的实现它. 界面 下面我们来分析一下界面的构成 整体的布局: 因为我们要做出 ...
- C# 非模式窗体show()和模式窗体showdialog()的区别
对话框不是模式就是无模式的.模式对话框,在可以继续操作应用程序的其他部分之前,必须被关闭(隐藏或卸载).例如,如果一个对话框,在可以切换到其它窗 体或对话框之前要求先单击"确定"或 ...
- [CC-SUBWAY]Subway Ride
[CC-SUBWAY]Subway Ride 题目大意: 一棵\(n(n\le5\times10^5)\)个点的含重边的树,总边数为\(m(m\le10^6)\),每条边有一个颜色.\(q(q\le5 ...
- Java并发(十七):ConcurrentHashMap
先做总结: 1.HashMap HashTable ConcurrentHashMap HashMap:线程不安全 HashTable:线程安全,每个方法都加了 synchronized 修饰.类似 ...
- mac os 切换网络优先级
升级到新系统OS X Yesemite 系统后有WIFI时会默认使用WIFI而不是有线. 但是公司的WIFI基本没法用,每次到公司之后就得把WIFI关掉,回家又打开,烦死了. 今天研究了下原来网络优先 ...
- DataTable初次使用笔记
概述:DataTable是一个jQuery插件,用于生成HTML表格,功能很强大. 使用: 使用DataTable需要引入jQuery,因为他是基于jQuery的插件,然后引入DataTable的js ...
- 模板 SBT
傻逼树模板 struct SBT{ const static int maxn = 1e5 + 15; int lft[maxn] , rht[maxn] , key[maxn] , s[maxn] ...
- bmp图像数据转jpg图像的C语言实现
bmp图像格式协议 jpg图像格式协议 Bmp转jpg图像代码 密码:nmaj