当前位置:网站首页>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
边栏推荐
- 《JVM系列》 第七章 -- 字节码执行引擎
- 8.4 循环神经网络从零实现
- Want to be an architect? Tamping the foundation is the most important
- Svn detailed use tutorial
- What is the main purpose of PCIe X1 slot?
- PWM speed regulation control system of DC motor based on 51 single chip microcomputer (with complete set of data such as Proteus simulation + C program)
- Arduino for esp8266串口功能简介
- Swift - literal, literal protocol, conversion between basic data types and dictionary / array
- 拼接hql时,新增字段没有出现在构造方法中
- Electronic scale weighing system design, hx711 pressure sensor, 51 single chip microcomputer (proteus simulation, C program, schematic diagram, thesis and other complete data)
猜你喜欢
![Detailed explanation of C language knowledge points -- first knowledge of C language [1]](/img/7d/2fc527949562e1a7ef1525c7fced81.png)
Detailed explanation of C language knowledge points -- first knowledge of C language [1]

中富金石财富班29800效果如何?与专业投资者同行让投资更简单

冰冰学习笔记:一步一步带你实现顺序表

555 timer + 74 series chip to build eight way responder, 30s countdown, proteus simulation, etc

Bingbing learning notes: take you step by step to realize the sequence table

eolink 如何助力远程办公

Multisim Simulation Design of DC adjustable regulated power supply of LM317 (with simulation + paper + reference)

Electronic scale weighing system design, hx711 pressure sensor, 51 single chip microcomputer (proteus simulation, C program, schematic diagram, thesis and other complete data)

Design of single chip microcomputer Proteus for temperature and humidity monitoring and alarm system of SHT11 sensor (with simulation + paper + program, etc.)
![[servlet] detailed explanation of servlet (use + principle)](/img/7e/69b768f85bad14a71ce9fcef922283.png)
[servlet] detailed explanation of servlet (use + principle)
随机推荐
I/O复用的高级应用之一:非阻塞 connect———使用 select 实现(也可以用 poll 实现)
The initial C language framework is suitable for review and preliminary understanding
MySQL报错packet out of order
Matlab Simulink modeling and design of single-phase AC-AC frequency converter, with MATLAB simulation, PPT and papers
AT89C52 MCU frequency meter (1Hz ~ 20MHz) design, LCD1602 display, including simulation, schematic diagram, PCB and code, etc
MCU function signal generator, output four kinds of waveforms, adjustable frequency, schematic diagram, simulation and C program
One of the advanced applications of I / O reuse: non blocking connect -- implemented using select (or poll)
Chapter 7 of JVM series -- bytecode execution engine
ArrayList collection basic usage
8.2 文本预处理
帧同步 实现
1n5408-asemi rectifier diode
机器学习之逻辑回归(Logistic Regression)原理讲解和实例应用,果断收藏
Detailed comparison between asemi three-phase rectifier bridge and single-phase rectifier bridge
【Servlet】Servlet 详解(使用+原理)
Role of asemi rectifier module mdq100-16 in intelligent switching power supply
Select receives both normal data and out of band data
[stc8g2k64s4] introduction of comparator and sample program of comparator power down detection
select 同时接收普通数据 和 带外数据
8.5 循环神经网络简洁实现
