Why my program has a runtime error when the arrays are too long!


  • 0
    K

    double findMedianSortedArrays(int* nums1, int nums1Size, int* nums2, int nums2Size) {
    int mid1;
    int mid2;
    double big;
    int flag=0,flag1=0;
    if(nums1Size==0)
    {
    if(nums2Size%2)
    return (nums2+(nums2Size+1)/2-1);
    else
    {
    big=
    (nums2+nums2Size/2-1)+
    (nums2+nums2Size/2);
    return big/2;
    }
    }
    if(nums2Size==0)
    {
    if(nums1Size%2)
    return (nums1+(nums1Size+1)/2-1);
    else
    {
    big=
    (nums1+nums1Size/2-1)+
    (nums1+nums1Size/2);
    return big/2;
    }
    }
    if(nums1Size%2)
    mid1=(nums1+(nums1Size+1)/2-1);
    else
    mid1=(nums1+nums1Size/2);
    if(nums2Size%2)
    mid2=(nums2+(nums2Size+1)/2-1);
    else
    mid2=(nums2+(nums2Size/2));
    if(*mid1>*mid2)
    flag=1;
    if(!(nums1Size%2||nums2Size%2))
    flag1=1;
    if(flag1)
    {
    if(nums1Size>nums2Size)
    mid1--;
    else
    mid2--;
    }
    while(1)
    {
    if(mid1==mid2)
    {
    big=
    (mid2);
    return big;
    }
    else if((
    (mid1+1)==mid2&&(mid2-1)==mid1)||((mid2+1)==mid1&&(mid1-1)==*mid2))
    {
    big=*mid1+*mid2;
    return big/2;
    }
    if(flag)
    {
    mid1--;
    mid2++;
    }
    else
    {
    mid1++;
    mid2--;
    }
    }

    }


  • 0
    J

    Can you read your code ? 0.0
    Just click the bracket button to write code, like this:

    void test() {
        cout << "hello world" << endl;
    }
    

    And maybe I can take a look!


  • 0
    K

    oh,I'm sorry,it's my first time to ask question.I forget the bracket button!


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.