1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
// @Title: 寻找数组的中心索引 (Find Pivot Index)
// @Author: 15816537946@163.com
// @Date: 2021-01-28 09:27:12
// @Runtime: 8 ms
// @Memory: 6.1 MB
func pivotIndex(nums []int) int {
	var total, sum int
	for _, v := range nums {
		total += v
	}

	for i, v := range nums {
		if total == sum*2+v {
			return i
		}
		sum += v
	}
	return -1

}