当前位置:网站首页>Daily question - leetcode396 - rotation function - recursion
Daily question - leetcode396 - rotation function - recursion
2022-04-23 14:48:00 【Li Fan, hurry up】
Note:
The official solution is very good to understand
List f0 and f1 You can see the recursive relationship , Then the code can be implemented
The code is as follows :
class Solution {
public:
int maxRotateFunction(vector<int>& nums) {
int f = 0, sum = 0;
for(int i = 0; i < nums.size(); i ++)
sum += nums[i];
for(int i = 0; i < nums.size(); i ++)
f += i * nums[i];
int res = f;
for(int i = nums.size() - 1; i > 0; i --){
f = f + sum - nums.size() * nums[i];
res = max(res, f);
}
return res;
}
};
版权声明
本文为[Li Fan, hurry up]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231447599931.html
边栏推荐
- Swift - Literal,字面量协议,基本数据类型、dictionary/array之间的转换
- TLC5615 based multi-channel adjustable CNC DC regulated power supply, 51 single chip microcomputer, including proteus simulation and C code
- 一款不错的工具:aardio
- 8.4 循环神经网络从零实现
- 中富金石财富班29800效果如何?与专业投资者同行让投资更简单
- 全连接层的作用是什么?
- 【无标题】
- 多语言通信基础 06 go实现grpc的四种数据流模式实现
- 详解TCP的三次握手
- [proteus simulation] automatic range (range < 10V) switching digital voltmeter
猜你喜欢
OC to swift conditional compilation, marking, macro, log, version detection, expiration prompt
ArrayList collection basic usage
OC 转 Swift 条件编译、标记、宏、 Log、 版本检测、过期提示
LeetCode 练习——396. 旋转函数
What is the main purpose of PCIe X1 slot?
剑指 Offer II 019. 最多删除一个字符得到回文(简单)
Find daffodils - for loop practice
Swift:Entry of program、Swift调用OC、@_silgen_name 、 OC 调用Swift、dynamic、String、Substring
OpenFaaS实战之四:模板操作(template)
Programming philosophy - automatic loading, dependency injection and control inversion
随机推荐
SQLSERVER事物与锁的问题
【Proteus仿真】自动量程(范围<10V)切换数字电压表
Frame synchronization implementation
The initial C language framework is suitable for review and preliminary understanding
Do (local scope), initializer, memory conflict, swift pointer, inout, unsafepointer, unsafebitcast, success
Electronic scale weighing system design, hx711 pressure sensor, 51 single chip microcomputer (proteus simulation, C program, schematic diagram, thesis and other complete data)
QT Detailed explanation of pro file
I/O复用的高级应用之一:非阻塞 connect———使用 select 实现(也可以用 poll 实现)
One of the advanced applications of I / O reuse: non blocking connect -- implemented using select (or poll)
Progress in the treatment of depression
qt之.pro文件详解
8.4 循环神经网络从零实现
你还不知道责任链模式的使用场景吗?
select 同时接收普通数据 和 带外数据
Role of asemi rectifier module mdq100-16 in intelligent switching power supply
[proteus simulation] automatic range (range < 10V) switching digital voltmeter
博睿数据携手F5共同构建金融科技从代码到用户的全数据链DNA
On the insecurity of using scanf in VS
Swift - literal, literal protocol, conversion between basic data types and dictionary / array
1-初识Go语言