当前位置:网站首页>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
边栏推荐
- OC 转 Swift 条件编译、标记、宏、 Log、 版本检测、过期提示
- Want to be an architect? Tamping the foundation is the most important
- 线程同步、生命周期
- 51 Single Chip Microcomputer Design of traffic light system (with Proteus simulation, C program, schematic diagram, PCB, thesis and other complete data)
- Introduction to Arduino for esp8266 serial port function
- ArrayList collection basic usage
- What is the main purpose of PCIe X1 slot?
- 外包干了四年,废了...
- do(Local scope)、初始化器、内存冲突、Swift指针、inout、unsafepointer、unsafeBitCast、successor、
- Alexnet model
猜你喜欢
机器学习之逻辑回归(Logistic Regression)原理讲解和实例应用,果断收藏
Swift - Literal,字面量协议,基本数据类型、dictionary/array之间的转换
阿里研发三面,面试官一套组合拳让我当场懵逼
MySQL报错packet out of order
Thread synchronization, life cycle
[stc8g2k64s4] introduction of comparator and sample program of comparator power down detection
外包幹了四年,廢了...
Branch statement of process control
A good tool: aardio
Detailed comparison between asemi three-phase rectifier bridge and single-phase rectifier bridge
随机推荐
Alexnet model
How do I open the win10 startup folder?
Explanation and example application of the principle of logistic regression in machine learning
Contraction mapping theorem
Electronic perpetual calendar of DS1302_ 51 single chip microcomputer, month, day, week, hour, minute and second, lunar calendar and temperature, with alarm clock and complete set of data
[servlet] detailed explanation of servlet (use + principle)
UML project example -- UML diagram description of tiktok
raised exception class EAccexxViolation with ‘Access violation at address 45EFD5 in module 出错
Brute force of DVWA low -- > High
8.4 循环神经网络从零实现
GIS数据处理-cesium中模型位置设置
自动化的艺术
想要成为架构师?夯实基础最重要
[untitled]
eolink 如何助力远程办公
capacitance
电容
【工厂模式详解】工厂方法模式
8.2 文本预处理
QT Detailed explanation of pro file