当前位置:网站首页>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;
}
};边栏推荐
- ETCD数据库源码分析——初始化总览
- Just do it with your hands 7 - * project construction details 2 - hook configuration
- 2022 t elevator repair operation certificate examination question bank and simulation examination
- KMP匹配字符串
- TCP状态转换图
- [matlab] matlab simulates digital baseband transmission system eye diagram of bipolar baseband signal (class I part response waveform)
- ping端口神器psping
- [matlab] general function of communication signal modulation bandpass filter
- Simple g++ and GDB debugging
- [QT] timer
猜你喜欢

Character types of C language

ETCD数据库源码分析——初始化总览

Programming example of stm32f1 and stm32subeide -74hc595 drives 4-bit 7-segment nixie tube

中科磐云—模块A 基础设施设置与安全加固 评分标准

How to build your own knowledge engine? Community open application
![[technology development -25]: integration technology of radio and television network, Internet, telecommunication network and power grid](/img/87/e0469e280365ed0261e2b551ebd888.png)
[technology development -25]: integration technology of radio and television network, Internet, telecommunication network and power grid

Zhongke Panyun - module a infrastructure setting and safety reinforcement scoring standard

KMP match string

《Cross-view Transformers for real-time Map-view Semantic Segmentation》论文笔记

Just do it with your hands 7 - * project construction details 2 - hook configuration
随机推荐
[matlab] matlab simulation - low pass Gaussian white noise
[untitled]
Flutter ‘/usr/lib/libswiftCore. dylib‘ (no such file)
Integer type of C language
[matlab] matlab simulation modulation system SSB system
Secondary vocational group network security - memory Forensics
[technology development -25]: integration technology of radio and television network, Internet, telecommunication network and power grid
Annex III: scoring standard of the defender docx
EVM proof in appliedzkp zkevm (11)
海力士EMMC5.0及5.1系列对比详解
Unity2D--人物移动并转身
VB.net GIF(制作、拆解——优化代码,类库——5)
Rollup各组件作用
令人头痛的延时双删
[wechat applet] template and configuration (wxml, wxss, global and page configuration, network data request)
练习-冒泡排序
Yyds dry goods inventory TCP & UDP
With the advent of the IP era, how can E-sports hotels take advantage of the "east wind" of games?
Zhongke Panyun - module a infrastructure setting and safety reinforcement scoring standard
2022g2 power station boiler stoker special operation certificate examination question bank and answers