1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| // @Title: 寻找数组的中心下标 (Find Pivot Index)
// @Author: 15816537946@163.com
// @Date: 2022-03-19 19:15:22
// @Runtime: 16 ms
// @Memory: 6 MB
func pivotIndex(nums []int) int {
var sum, total int
for _,v := range nums {
total+=v
}
for i,v := range nums {
if 2 *sum +v == total {
return i
}
sum+=v
}
return -1
}
|