寻找数组的中心索引 class Solution {public int pivotIndex(int[] nums) {int n = nums.length,sum = 0;for(int i = 0;i<n;i++){ //计算所有元素之和sum+=nums[i];}int sum_l = 0; //统计左边元素之和for(int i =0;i<n;i++){sum -= nums[i];if(sum_l == sum){return i;}sum_l += nums[i];}return -1;} }