当前位置:网站首页>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
边栏推荐
- QT actual combat: Yunxi calendar
- Explain TCP's three handshakes in detail
- 在游戏世界组建一支AI团队,超参数的多智能体「大乱斗」开赛
- 你还不知道责任链模式的使用场景吗?
- Matlab Simulink modeling and design of single-phase AC-AC frequency converter, with MATLAB simulation, PPT and papers
- eolink 如何助力远程办公
- 机器学习之逻辑回归(Logistic Regression)原理讲解和实例应用,果断收藏
- ArrayList collection basic usage
- Swift protocol Association object resource name management multithreading GCD delay once
- Select receives both normal data and out of band data
猜你喜欢
![[servlet] detailed explanation of servlet (use + principle)](/img/7e/69b768f85bad14a71ce9fcef922283.png)
[servlet] detailed explanation of servlet (use + principle)

电容
![[stc8g2k64s4] introduction of comparator and sample program of comparator power down detection](/img/8c/e72e628a44a36bfc7406a002d00215.png)
[stc8g2k64s4] introduction of comparator and sample program of comparator power down detection

你還不知道責任鏈模式的使用場景嗎?

Set up an AI team in the game world and start the super parametric multi-agent "chaos fight"

Mds55-16-asemi rectifier module mds55-16

capacitance

1-初识Go语言

一个月把字节,腾讯,阿里都面了,写点面经总结……

Explanation and example application of the principle of logistic regression in machine learning
随机推荐
Contraction mapping theorem
电容
Mq-2 and DS18B20 fire temperature smoke alarm system design, 51 single chip microcomputer, with simulation, C code, schematic diagram, PCB, etc
Outsourcing for four years, abandoned
SQLSERVER事物与锁的问题
Swift protocol Association object resource name management multithreading GCD delay once
1-初识Go语言
Select receives both normal data and out of band data
一个月把字节,腾讯,阿里都面了,写点面经总结……
一款不错的工具:aardio
Explanation and example application of the principle of logistic regression in machine learning
Interviewer: let's talk about the process of class loading and the mechanism of class loading (parental delegation mechanism)
抑郁症治疗的进展
SVN详细使用教程
自动化的艺术
AT89C51 MCU digital voltmeter development, measuring range 0 ~ 5V, proteus simulation, schematic diagram, PCB and C program, etc
8.4 循环神经网络从零实现
[detailed explanation of factory mode] factory method mode
Proteus simulation design of DC adjustable regulated power supply (with simulation + paper and other data)
Alexnet model
