当前位置:网站首页>[untitled] leetcode 396 rotation function [finding laws in mathematics] the way of leetcode in heroding
[untitled] leetcode 396 rotation function [finding laws in mathematics] the way of leetcode in heroding
2022-04-22 20:04:00 【HERODING23】

Their thinking :
A very simple mathematical logic reasoning problem , Simply put, it's about finding rules , Every two consecutive F Subtracting the , There will always be F(i)-F(i-1)=sum+n*nums[n-i], So according to this Law , Just put F(0) Work it out , The back ones come out directly , There's no need for violence , The code is as follows :
class Solution {
public:
int maxRotateFunction(vector<int>& nums) {
int n = nums.size();
int sum = 0, F = 0;
for(int i = 0; i < n; i ++) {
sum += nums[i];
F += i * nums[i];
}
int maxSum = F;
for(int i = 1; i < n; i ++) {
F = F + sum - n * nums[n - i];
maxSum = max(maxSum, F);
}
return maxSum;
}
};
版权声明
本文为[HERODING23]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221956577479.html
边栏推荐
- Is it true to download the financial app of qiniu business school? Is it safe to open an account in qiniu
- What is the reason why the camera device with built-in 4G card of Haikang cannot register with easycvr platform?
- C语言位域应用--一个字节存八个标志位
- Jmeter:一文2000字接口测试基础知识介绍
- Academician Mei Hong: how to construct artificial swarm intelligence
- 工作光靠努力是不够的!还有这个...
- [basic knowledge of automated testing] basic concepts and common frameworks of automated testing
- In 2022, the most underestimated function of postman, the efficiency of automated interface testing, is simply invincible
- 海康内置4G卡的摄像头设备无法注册EasyCVR平台是什么原因?
- Obtain the real IP address of the client after envoy proxy
猜你喜欢

Detailed tutorial on installing MySQL 8.0 + eclipse configuration under Linux

The origin explanation and use example of image pre training model

文件上传问题记录

Software testing industry must see, a text of 800 words to teach you how to build the allure test report environment

What is the reason why the camera device with built-in 4G card of Haikang cannot register with easycvr platform?

一文读懂Hoo Smart Chain的可视化公链
![[Niuke brush question 19] MP3 cursor position](/img/ea/8ec110cbacf68ea0337437e311cc72.png)
[Niuke brush question 19] MP3 cursor position

高级ipc - dbus详解

【H5】微信端H5页面制作

面试千万不要这么说,“不喜欢开发,所以选择测试”
随机推荐
New generation agent weapon - traefik
行业趋势远比努力更重要--顶测科技总结
dbus客户端使用指南
怎么才能申购可转债呢?申购可转债安全吗?
这就是深度学习如此强大的原因
Application of C language bit field -- storing eight flag bits in one byte
Redis 最全解读
[basic knowledge of automated testing] basic concepts and common frameworks of automated testing
解决金仓数据库KingbaseES使用--force-rewind强制拉起备机时,时间线不吻合的问题
期货开户在手机上办理安全吗?需要线下客户经理协助办理吗?
[Chongqing Guangdong education] Nanyang Institute of Technology English rambling Chinese culture reference materials
开源免费,最好用的3大系统9大防火墙软件安利给你们
The concept, function, problem and solution of closure
The difference between null and "" in kingbases database
【近期功能更新】无缝体验免费 Demo!
互联网快讯:联想公布ESG新进展;极米H3S、极米Z6X Pro出色音画获好评;小红书回应“裁员20%”
使用rpmbuild打包php
<山东大学项目实训>辐射预计算渲染及后处理降噪系统研究(一)
文件上传问题记录
Advanced IPC - DBUS details