C code question?


  • 0
    Z

    Why input nums1=[], the if code doesn't work?
    output should be [] but it output [0].

    int* intersection(int* nums1, int nums1Size, int* nums2, int nums2Size, int* returnSize) {
        if((*nums1==NULL)||(*nums2==NULL))
        {  * returnSize=0;
            return NULL;
        }
        else{
        
        
        int* result=(int*)malloc(sizeof(int));
        for(int i=0;i<nums1Size;i++)
        {
            for(int j=0;i<nums2Size;i++)
            {
                if(nums1[i]==nums2[j]) 
                {
                    *result=nums1[i]; 
                    break;
                }
            }
        }
        *returnSize=1;
        return result;
        }
    }
    

Log in to reply
 

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