当前位置:网站首页>寻找数组的中心下标
寻找数组的中心下标
2022-07-17 03:23:00 【蓝染k9z】
class Solution {
public int pivotIndex(int[] nums) {
int total = Arrays.stream(nums).sum();
int sum = 0;
for (int i = 0; i < nums.length; i++) {
//总和已经算了,如果sum的两倍加上nums[i]=total,就说明i位置的前后相等
//从0开始遍历,则可以保证返回最靠近左边的那一个中心下标
if (sum * 2 + nums[i] == total)
return i;
sum += nums[i];
}
return - 1;
}
}
边栏推荐
- [Paper Abstract] screenshots of methods for recording abstracts of interest and papers in special fields.
- 无心剑汉英双语诗005.《抒怀》
- 1. PostgreSQL queries the data of nearly 24 hours according to the dynamic table name
- Go environment installation
- Openresty 做静态资源服务器
- Record a troubleshooting when overseas pictures cannot be loaded
- 【超能云终端创领先机】本地计算云端管理,英特尔助力教育数字化
- Use of anti shake debounce and throttling throttle
- 厉害,竟然把VSCode玩成了IDEA的效果,有点哇塞
- Teaching reform and software platform of entrepreneurship practice simulation
猜你喜欢
Timeline components
英特尔助力开立医疗推动超声产检智能化
Container adapter - stack, queue, priority queue
FTXUI基础笔记(botton按钮组件基础)
英特尔专家分享:如何在XPU架构上高效编程?丨至强研究所
HCIP实验5
Group convolution
(21) blender source code analysis: click the mouse to add the message to the queue
Sword Finger offer 59 - II. Valeur maximale de la file d'attente
Awesome. It turns vscode into idea. It's a little wow
随机推荐
程序员生涯写过最大的Bug!网友:高低是个P8水平!
[untitled]
最小生成树
GNN系列 GCN简述 推导理解 及 DGL 源码解析
Tutorial: Adaptive Replication and Partitioning in Data Systems
HCIP实验4
《云智面对面》直播等你来: 算力重新定义生产力
lc marathon 7.16
Tutorial: Adaptive Replication and Partitioning in Data Systems
【数据库】期末必知必会-----第九章 数据库设计
【数据库】期末必知必会-----第十章 数据库编程
Asp.NetCore 中使用grpc
Use of anti shake debounce and throttling throttle
IN Tech 2022|英特尔技术产品创新速览
剑指 Offer 60. n个骰子的点数
1. PostgreSQL queries the data of nearly 24 hours according to the dynamic table name
H5 embedded app, how to communicate with the web? H5 and web communication
Leetcode 931: minimum sum of descent path
Use case of TS - Snake Eater
【数据库】期末必知必会-----第十一章 并发控制