当前位置:网站首页>724. 寻找数组的中心下标
724. 寻找数组的中心下标
2022-07-04 05:07:00 【anieoo】
原题链接:724. 寻找数组的中心下标
solution:
左求和*2+中心索引值 = 总和
class Solution {
public:
int pivotIndex(vector<int>& nums) {
int sum = 0;
for(auto &x : nums) sum += x; //求出总和
int k = 0;
for(int i = 0;i < nums.size();i++) {
if(i + 1 <= nums.size() && (k * 2 + nums[i] == sum)) return i;
k += nums[i];
}
return -1;
}
};边栏推荐
- IP时代来临,电竞酒店如何借好游戏的“东风”?
- COMP1721 Creating Classes
- The second case analysis of the breakthrough of defense system from the perspective of the red team
- Detailed comparison of Hynix emmc5.0 and 5.1 series
- June 2022 summary
- ETCD数据库源码分析——初始化总览
- 中科磐云—2022广东木马信息获取解析
- 远程桌面客户端 RDP
- TCP state transition diagram
- Notepad++--显示相关的配置
猜你喜欢

光模块字母含义及参数简称大全

企业级日志分析系统ELK(如果事与愿违那一定另有安排)

VB.net 简单的处理图片,黑白(类库——7)

National vocational college skills competition (secondary vocational group) network security competition questions - Analysis

中職組網絡安全—內存取證
![[wechat applet] template and configuration (wxml, wxss, global and page configuration, network data request)](/img/78/63ab1a8bb1b6e256cc740f3febe711.jpg)
[wechat applet] template and configuration (wxml, wxss, global and page configuration, network data request)

令人头痛的延时双删

Graduation design of small programs -- small programs of food and recipes

Just do it with your hands 7 - * project construction details 2 - hook configuration

Zhongke panyun-2022 Guangdong Trojan horse information acquisition and analysis
随机推荐
[matlab] matlab simulation - low pass Gaussian white noise
LabVIEW错误对话框的出现
2022 R2 mobile pressure vessel filling retraining question bank and answers
Zhongke Panyun - 2022 Guangxi reverse analysis ideas
PostgreSQL has officially surpassed mysql. Is this guy too strong!
如何使用postman实现简单的接口关联【增删改查】
Rollup各组件作用
2022危险化学品经营单位安全管理人员上岗证题库及答案
[matlab] communication signal modulation general function interpolation function
Enterprise level log analysis system elk (if things backfire, there must be other arrangements)
Flutter calls Gaode map app to realize location search, route planning and reverse geocoding
Simulink与Arduino串口通信
Build an Internet of things infrared temperature measuring punch in machine with esp32 / rush to work after the Spring Festival? Baa, no matter how hard you work, you must take your temperature first
The data mark is a piece of fat meat, and it is not only China Manfu technology that focuses on this meat
June 2022 summary
Error response from daemon: You cannot remove a running container 8d6f0d2850250627cd6c2acb2497002fc3
[matlab] matlab simulation modulation system - DSB system
A summary of the 8544 problem that SolidWorks Standard cannot obtain a license
[high concurrency, high performance and high availability of massive data MySQL practice-7] - memory data drop disk
由于使用flash存放参数时,擦除掉了flash的代码区导致进入硬件错误中断