当前位置:网站首页>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;
}
};边栏推荐
- Zhongke panyun-d module analysis and scoring standard
- Zkevm (12) state proof of appliedzkp
- [matlab] general function of communication signal modulation inverse Fourier transform
- Flink1.13 basic SQL syntax (II) join operation
- c语言经典指针和数组笔试题解析
- Unity is connected to the weather system
- Zzulioj:1201: mode problem
- Daily question brushing record (12)
- Just do it with your hands 7 - * project construction details 2 - hook configuration
- Simulink与Arduino串口通信
猜你喜欢

Zhongke panyun-2022 Guangdong Trojan horse information acquisition and analysis

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

Flask

抓包整理外篇fiddler———— 会话栏与过滤器

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

Notes on the paper "cross view transformers for real time map view semantic segmentation"

LM小型可编程控制器软件(基于CoDeSys)笔记二十二:错误4268/4052

光模塊字母含義及參數簡稱大全

2022危险化学品经营单位安全管理人员上岗证题库及答案

ETCD数据库源码分析——初始化总览
随机推荐
【兴趣阅读】Adversarial Filtering Modeling on Long-term User Behavior Sequences for Click-Through Rate Pre
[matlab] matlab simulates digital bandpass transmission system ask, PSK, FSK system
Thread pool: use thread pool to optimize query speed
ETCD数据库源码分析——初始化总览
2022 a special equipment related management (elevator) examination questions simulation examination platform operation
[interested reading] advantageous filtering modeling on long term user behavior sequences for click through rate pre
Get the ID of the record just inserted from laravel
Roles of rollup components
Automated testing selenium foundation -- webdriverapi
laravel 中获取刚刚插入的记录的id
Exercise bubble sort
Capturing and sorting out external Fiddler -- Conversation bar and filter
[matlab] general function of communication signal modulation - generation of narrow-band Gaussian white noise
Several smart watch related chips Bluetooth chip low power consumption
Redis realizes ranking function
Using jsts in esmodule environment
Rollup各组件作用
VB.net 简单的处理图片,黑白(类库——7)
flink1.13 sql基础语法(一)DDL、DML
模拟小根堆