寻找数组的中心索引
int pivotIndex(int* nums, int numsSize){ int sum = 0,left=0; for(int i =0; i<numsSize;++i){ sum+=nums[i]; } int j; for(j=0;j<numsSize;++j){ left+=nums[j]; if(sum==left) return j; sum-=nums[j]; } return -1; }
int pivotIndex(int* nums, int numsSize){ int sum = 0,left=0; for(int i =0; i<numsSize;++i){ sum+=nums[i]; } int j; for(j=0;j<numsSize;++j){ left+=nums[j]; if(sum==left) return j; sum-=nums[j]; } return -1; }