当前位置:网站首页>每日一题-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
边栏推荐
- capacitance
- 2-Go变量操作
- 冰冰学习笔记:一步一步带你实现顺序表
- AT89C52 MCU frequency meter (1Hz ~ 20MHz) design, LCD1602 display, including simulation, schematic diagram, PCB and code, etc
- redis的五种数据类型
- SQLSERVER事物与锁的问题
- Detailed explanation of C language knowledge points -- first knowledge of C language [1]
- Chapter 7 of JVM series -- bytecode execution engine
- Model location setting in GIS data processing -cesium
- Arduino for esp8266串口功能简介
猜你喜欢

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

Using MATLAB programming to realize the steepest descent method to solve unconstrained optimization problems

51 MCU + LCD12864 LCD Tetris game, proteus simulation, ad schematic diagram, code, thesis, etc

你还不知道责任链模式的使用场景吗?

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

1 minute to understand the execution process and permanently master the for cycle (with for cycle cases)

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

Swift - literal, literal protocol, conversion between basic data types and dictionary / array

Matlab Simulink modeling and design of single-phase AC-AC frequency converter, with MATLAB simulation, PPT and papers

8.2 文本预处理
随机推荐
UML project example -- UML diagram description of tiktok
SVN详细使用教程
Master in minutes --- ternary operator (ternary operator)
OC 转 Swift 条件编译、标记、宏、 Log、 版本检测、过期提示
阿里研发三面,面试官一套组合拳让我当场懵逼
Is asemi ultrafast recovery diode interchangeable with Schottky diode
Explanation and example application of the principle of logistic regression in machine learning
UML项目实例——抖音的UML图描述
2-GO variable operation
Matlab Simulink modeling and design of single-phase AC-AC frequency converter, with MATLAB simulation, PPT and papers
[NLP] HMM hidden Markov + Viterbi word segmentation
QT Detailed explanation of pro file
全连接层的作用是什么?
Don't you know the usage scenario of the responsibility chain model?
On the insecurity of using scanf in VS
如何打开Win10启动文件夹?
Epoll's et, lt working mode -- example program
The initial C language framework is suitable for review and preliminary understanding
Multisim Simulation Design of DC adjustable regulated power supply of LM317 (with simulation + paper + reference)
DVWA之暴力破解(Brute Force)Low-->high
