C solution


  • 0
    W
    bool isInArray(int *nums,int numsSize,int num){
    	if(nums==NULL) return false;
    	for(int i=0;i<numsSize;i++){
    		if(nums[i]==num) return true;
    	}
    
    }
    int* intersection(int* nums1, int nums1Size, int* nums2, int nums2Size, int* returnSize) {
    	if(nums2Size==0 || nums1Size==0) return NULL;
    	int *ReturnArray=NULL;
    	int count=0;
        if(nums1Size<=nums2Size){
        	for(int i=0;i<nums1Size;i++){
        		if(isInArray(nums2,nums2Size,nums1[i]) && !isInArray(ReturnArray,count,nums1[i])){
        			ReturnArray=realloc(ReturnArray,sizeof(int)*(count+1));
        			ReturnArray[count]=nums1[i];
        			count++;
        		}
        	}
        	* returnSize=count;
        	return ReturnArray;
        }else {
        	return intersection(nums2,nums2Size,nums1,nums1Size,returnSize);
        }
    }
    

  • 0
    W

    函数isInArray 最后少了个return FALSE;


Log in to reply
 

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