当前位置:网站首页>每日一题-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
边栏推荐
- 利用 MATLAB 编程实现最速下降法求解无约束最优化问题
- TLC5615 based multi-channel adjustable CNC DC regulated power supply, 51 single chip microcomputer, including proteus simulation and C code
- Epoll's et, lt working mode -- example program
- Electronic scale weighing system design, hx711 pressure sensor, 51 single chip microcomputer (proteus simulation, C program, schematic diagram, thesis and other complete data)
- Mq-2 and DS18B20 fire temperature smoke alarm system design, 51 single chip microcomputer, with simulation, C code, schematic diagram, PCB, etc
- [stc8g2k64s4] introduction of comparator and sample program of comparator power down detection
- UML project example -- UML diagram description of tiktok
- Raised exception class eaccexviolation with 'access violation at address 45efd5 in module error
- Is asemi ultrafast recovery diode interchangeable with Schottky diode
- 电容
猜你喜欢
A good tool: aardio
OC 转 Swift 条件编译、标记、宏、 Log、 版本检测、过期提示
自动化的艺术
Is asemi ultrafast recovery diode interchangeable with Schottky diode
AT89C52 MCU frequency meter (1Hz ~ 20MHz) design, LCD1602 display, including simulation, schematic diagram, PCB and code, etc
Svn detailed use tutorial
I thought I could lie down and enter Huawei, but I was confused when I received JD / didi / iqiyi offers one after another
Bingbing learning notes: take you step by step to realize the sequence table
博睿数据携手F5共同构建金融科技从代码到用户的全数据链DNA
8.3 语言模型与数据集
随机推荐
Explanation and example application of the principle of logistic regression in machine learning
Swift protocol Association object resource name management multithreading GCD delay once
Unity_ Code mode add binding button click event
全连接层的作用是什么?
When splicing HQL, the new field does not appear in the construction method
go基础 反射
1 - first knowledge of go language
Set up an AI team in the game world and start the super parametric multi-agent "chaos fight"
What is the main purpose of PCIe X1 slot?
qt之.pro文件详解
LeetCode 练习——396. 旋转函数
I/O复用的高级应用:同时处理 TCP 和 UDP 服务
Electronic perpetual calendar of DS1302_ 51 single chip microcomputer, month, day, week, hour, minute and second, lunar calendar and temperature, with alarm clock and complete set of data
QT interface optimization: double click effect
Branch statement of process control
【Proteus仿真】自动量程(范围<10V)切换数字电压表
机器学习之逻辑回归(Logistic Regression)原理讲解和实例应用,果断收藏
Provided by Chengdu control panel design_ It's detailed_ Introduction to the definition, compilation and quotation of single chip microcomputer program header file
Svn detailed use tutorial
【NLP】HMM隐马尔可夫+维特比分词