当前位置:网站首页>每日一题-LeetCode396-旋转函数-递推
每日一题-LeetCode396-旋转函数-递推
2022-04-23 14:48:00 【李烦烦搞快点】
Note:
官方题解挺好看懂的
列出来 f0 和 f1 就看出来递推关系了,然后代码实现一下即可
代码如下:
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;
}
};
版权声明
本文为[李烦烦搞快点]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Mr_Ghost812/article/details/124346916
边栏推荐
- qt之.pro文件详解
- Vscode Chinese plug-in doesn't work. Problem solving
- 8.4 循环神经网络从零实现
- do(Local scope)、初始化器、内存冲突、Swift指针、inout、unsafepointer、unsafeBitCast、successor、
- 数组模拟队列进阶版本——环形队列(真正意义上的排队)
- 2-Go变量操作
- Ali developed three sides, and the interviewer's set of combined punches made me confused on the spot
- One of the advanced applications of I / O reuse: non blocking connect -- implemented using select (or poll)
- 金九银十,入职字节跳动那一天,我哭了(蘑菇街被裁,奋战7个月拿下offer)
- 线程同步、生命周期
猜你喜欢

Proteus simulation design of DC adjustable regulated power supply (with simulation + paper and other data)

Introduction to Arduino for esp8266 serial port function

【STC8G2K64S4】比较器介绍以及比较器掉电检测示例程序

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

UML项目实例——抖音的UML图描述

电容
![Eight way responder system 51 Single Chip Microcomputer Design [with Proteus simulation, C program, schematic diagram, PCB files, component list and papers, etc.]](/img/1b/d1dea1726f3f91d2ba1ab8f2d7ff4c.jpg)
Eight way responder system 51 Single Chip Microcomputer Design [with Proteus simulation, C program, schematic diagram, PCB files, component list and papers, etc.]

Progress in the treatment of depression

L'externalisation a duré quatre ans.

Do (local scope), initializer, memory conflict, swift pointer, inout, unsafepointer, unsafebitcast, success
随机推荐
UML project example -- UML diagram description of tiktok
Vous ne connaissez pas encore les scénarios d'utilisation du modèle de chaîne de responsabilité?
中富金石财富班29800效果如何?与专业投资者同行让投资更简单
We reference My97DatePicker to realize the use of time plug-in
2-Go变量操作
全连接层的作用是什么?
Select receives both normal data and out of band data
8.4 循环神经网络从零实现
Find daffodils - for loop practice
外包幹了四年,廢了...
ASEMI整流模块MDQ100-16在智能开关电源中的作用
【Proteus仿真】自动量程(范围<10V)切换数字电压表
MDS55-16-ASEMI整流模块MDS55-16
[NLP] HMM hidden Markov + Viterbi word segmentation
MCU function signal generator, output four kinds of waveforms, adjustable frequency, schematic diagram, simulation and C program
成都控制板设计提供_算是详细了_单片机程序头文件的定义、编写及引用介绍
如何打开Win10启动文件夹?
解决computed属性与input的blur事件冲突问题
【JZ46 把数字翻译成字符串】
三、梯度下降求解最小θ
