当前位置:网站首页>396. 旋轉函數
396. 旋轉函數
2022-04-22 12:51:00 【anieoo】
原題鏈接:396. 旋轉函數

solution: 找規律
//F(0) = nums[0] * 0 + nums[1] * 1 + nums[2] * 2 + .... nums[n] * n;
//F(1) = nums[0] * n + nums[1] * 0 + nums[2] * 1 + nums[2] * 1 + .... nums[n] * n - 1
//F(2) = nums[0] * n - 1 + nums[1] * n + nums[2] * 0 +.... nums[n] * n-2;
---》》
//F(1) = F(0) - sum(nums) + n * nums(0);
//F(2) = F(F1) - sum(nums) + n * nums(1);
class Solution {
public:
int maxRotateFunction(vector<int>& nums) {
int n = nums.size();
int sum = 0; //數組元素和
int F = 0; //保存更新F(0).F(1)...
int ans = INT_MIN; //返回值
for(int i = 0;i < n;i++){
sum += nums[i];
F += nums[i] * i;
}
for(int i = 0;i < n;i++){
F = F - sum + n * nums[i];
ans = max(ans, F);
}
return ans;
}
};
版权声明
本文为[anieoo]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221250261414.html
边栏推荐
- 这个开源项目是要把我笑死吗?
- [life gossip] Chinese sports platform teaches you how to improve the lottery winning rate
- Scientific research - SCI hub course
- 制裁压力下,俄罗斯计划通过友好国家平行进口电子产品
- Use R language_ Xlsx function export and write dataframe data to excel file
- JS盒子点击时跟随鼠标移动
- 数学——协方差
- VR全景婚礼给你别样的浪漫,记录婚礼的甜蜜瞬间
- VNC连接Too many security failures
- matlab 桥梁中一跨选择合适的跨径组合
猜你喜欢

Let cpolar get a fixed TCP address

Book city project registration page and email verification

标准化钢箱梁abaqus模型建立,使用RSG的插件二次开发

. net treasure API: outputformatter, format output object

Share the small problems you have encountered in writing projects recently

Express Can‘t set headers after they are sent.问题

ABAQUS model of local stress of bottom plate and web under the action of steel box girder jacking

智慧文旅逐渐数字化,vr全景推动文旅一体化发展

线程相关问题

Remote monitoring system of greenhouse based on stm32f103c8t6 + esp8266
随机推荐
matlab 桥梁跨径组合问题GUI图形界面完成
IDE Import Project
Let cpolar get a fixed TCP address
分享一下自己最近寫的一個移動端項目積累的一些實用技巧
書城項目注册頁面和郵箱驗證
JS基础9
Thread related issues
let和var的区别面试题答案
Express Can‘t set headers after they are sent.问题
分享一下自己最近写项目遇到的小问题
ROS2学习笔记(八)从turtlesim学习ROS2的启动文件
H5<canvas>标签+原生JS 自制一个简易画图工具
ROS2学习笔记(九)从turtlesim学习ROS2的bag录制
智慧文旅逐渐数字化,vr全景推动文旅一体化发展
Enterprise code static testing tool helix QAC - technical specifications
标准化钢箱梁abaqus模型建立,使用RSG的插件二次开发
Select the appropriate span combination for one span in MATLAB Bridge
数学——协方差
R语言使用write_xlsx函数导出、写入dataframe数据到excel文件实战
ROS2学习笔记(七)从turtlesim学习ROS2的工具