当前位置:网站首页>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;
}
};
边栏推荐
- 2022G2电站锅炉司炉特种作业证考试题库及答案
- Redis realizes ranking function
- Write a complete answer applet (including single choice questions, judgment questions and multiple topics) (III) single choice questions, judgment questions, and the first question display
- [paper summary] zero shot semantic segmentation
- VB.net GIF(制作、拆解——优化代码,类库——5)
- [matlab] matlab simulates digital baseband transmission system - digital baseband transmission system
- 2022 R2 mobile pressure vessel filling retraining question bank and answers
- Daily question brushing record (12)
- Trie number dictionary tree
- Annex 4: scoring criteria of the attacker docx
猜你喜欢
National vocational college skills competition (secondary vocational group) network security competition questions - Analysis
TCP state transition diagram
TCP状态转换图
如何构建属于自己的知识引擎?社群开放申请
Letter meaning and parameter abbreviation of optical module Daquan
2022年T电梯修理操作证考试题库及模拟考试
抓包整理外篇fiddler———— 会话栏与过滤器
《Cross-view Transformers for real-time Map-view Semantic Segmentation》论文笔记
补某视频网站的js,进行视频解密
海力士EMMC5.0及5.1系列对比详解
随机推荐
Electronic components mall and data manual download website summary
Simulink and Arduino serial port communication
Unity2d -- character moves and turns
Remote desktop client RDP
Using jsts in esmodule environment
如何使用postman实现简单的接口关联【增删改查】
Ping port artifact psping
2022年A特种设备相关管理(电梯)考试题模拟考试平台操作
VB.net 简单的处理图片,黑白(类库——7)
Rollup各组件作用
2022 Guangdong provincial competition - code information acquisition and analysis flag
When using flash to store parameters, the code area of flash is erased, which leads to the interrupt of entering hardware error
[technology development -25]: integration technology of radio and television network, Internet, telecommunication network and power grid
ping端口神器psping
KMP匹配字符串
With the advent of the IP era, how can E-sports hotels take advantage of the "east wind" of games?
How to build your own knowledge engine? Community open application
[matlab] matlab simulates digital baseband transmission system eye diagram of bipolar baseband signal (class I part response waveform)
Annex 4: scoring criteria of the attacker docx
Flutter ‘/usr/lib/libswiftCore. dylib‘ (no such file)