当前位置:网站首页>每日一题-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
边栏推荐
- Multisim Simulation Design of DC adjustable regulated power supply of LM317 (with simulation + paper + reference)
- 【NLP】HMM隐马尔可夫+维特比分词
- Matlab Simulink modeling and design of single-phase AC-AC frequency converter, with MATLAB simulation, PPT and papers
- 阿里研发三面,面试官一套组合拳让我当场懵逼
- MCU function signal generator, output four kinds of waveforms, adjustable frequency, schematic diagram, simulation and C program
- Ali developed three sides, and the interviewer's set of combined punches made me confused on the spot
- 编程哲学——自动加载、依赖注入与控制反转
- 机器学习之逻辑回归(Logistic Regression)原理讲解和实例应用,果断收藏
- 1N5408-ASEMI整流二极管1N5408
- QT interface optimization: double click effect
猜你喜欢
Matlab Simulink modeling and design of single-phase AC-AC frequency converter, with MATLAB simulation, PPT and papers
1N5408-ASEMI整流二极管1N5408
GIS数据处理-cesium中模型位置设置
Vous ne connaissez pas encore les scénarios d'utilisation du modèle de chaîne de responsabilité?
we引用My97DatePicker 实现时间插件使用
Mq-2 and DS18B20 fire temperature smoke alarm system design, 51 single chip microcomputer, with simulation, C code, schematic diagram, PCB, etc
Thread synchronization, life cycle
Svn detailed use tutorial
Mds55-16-asemi rectifier module mds55-16
Parameter stack pressing problem of C language in structure parameter transmission
随机推荐
外包幹了四年,廢了...
剑指 Offer II 019. 最多删除一个字符得到回文(简单)
你还不知道责任链模式的使用场景吗?
外包干了四年,废了...
[proteus simulation] automatic range (range < 10V) switching digital voltmeter
Unity_ Code mode add binding button click event
1 minute to understand the execution process and permanently master the for cycle (with for cycle cases)
DVWA之暴力破解(Brute Force)Low-->high
Swift - Literal,字面量协议,基本数据类型、dictionary/array之间的转换
We reference My97DatePicker to realize the use of time plug-in
Proteus simulation design of DC adjustable regulated power supply (with simulation + paper and other data)
When splicing HQL, the new field does not appear in the construction method
解决computed属性与input的blur事件冲突问题
Do (local scope), initializer, memory conflict, swift pointer, inout, unsafepointer, unsafebitcast, success
Outsourcing for four years, abandoned
L'externalisation a duré quatre ans.
【工厂模式详解】工厂方法模式
Pnpm installation and use
3、 Gradient descent solution θ
电容