m0_53178143
m0_53178143
2021-01-27 22:15

Leecode报错 heap-buffer-overflow on address

  • c语言
int pivotIndex(int* nums, int numsSize){
    int i=0,j=0,num1,num2;
    num1=nums[i];
    j=numsSize-1;
    num2=nums[j];
    while(i!=j-2&&i<j){
        if(num1==num2){
            j--;
            i++;
            num2=num2+nums[j];
            num1=num1+nums[i];
        }else if(num1>num2){
            j--;
            num2=num2+nums[j];
        }else if(num1<num2){
            i++;
            num1=num1+nums[i];
        }
    }
    if(num1==num2) return i+1;
    else return -1;
}
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

0条回答

为你推荐

换一换