当前位置:网站首页>724. Find the central subscript of the array
724. Find the central subscript of the array
2022-07-04 05:28:00 【anieoo】
Original link :724. Find the central subscript of the array
solution:
Left summation *2+ Central index value = The sum of the
class Solution {
public:
int pivotIndex(vector<int>& nums) {
int sum = 0;
for(auto &x : nums) sum += x; // Find the sum
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;
}
};
边栏推荐
- 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
- LM小型可编程控制器软件(基于CoDeSys)笔记二十二:错误4268/4052
- 2022 t elevator repair operation certificate examination question bank and simulation examination
- 2022 Guangdong provincial competition - code information acquisition and analysis flag
- 2022g2 power station boiler stoker special operation certificate examination question bank and answers
- Analysis of classical pointer and array written test questions in C language
- VB.net 简单的处理图片,黑白(类库——7)
- IP时代来临,电竞酒店如何借好游戏的“东风”?
- Supplement the JS of a video website to decrypt the video
- 2022危险化学品经营单位安全管理人员上岗证题库及答案
猜你喜欢
Principle and practice of common defects in RSA encryption application
2022G2电站锅炉司炉特种作业证考试题库及答案
[interested reading] advantageous filtering modeling on long term user behavior sequences for click through rate pre
Just do it with your hands 7 - * project construction details 2 - hook configuration
Zhanrui tankbang | jointly build, cooperate and win-win zhanrui core ecology
BUU-Real-[PHP]XXE
What is MQ?
Simulink与Arduino串口通信
SQL injection - injection based on MSSQL (SQL Server)
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
随机推荐
Enterprise level log analysis system elk (if things backfire, there must be other arrangements)
(4) Canal multi instance use
[技术发展-25]:广播电视网、互联网、电信网、电网四网融合技术
Integer type of C language
Unity is connected to the weather system
Li Kou's 300th weekly match
Introduction To AMBA 简单理解
【QT】制作MyComboBox点击事件
cmake
Graduation design of small programs -- small programs of food and recipes
RSA加密应用常见缺陷的原理与实践
VB.net 调用FFmpeg简单处理视频(类库——6)
Etcd database source code analysis - initialization overview
LM small programmable controller software (based on CoDeSys) note 22: error 4268/4052
小程序毕业设计---美食、菜谱小程序
Risc-v-qemu-virt in FreeRTOS_ Lock mechanism analysis of GCC
光模塊字母含義及參數簡稱大全
June 2022 summary
Daily question brushing record (12)
flink1.13 sql基础语法(二)join操作