Runtime error on large input


  • 0
    L

    I have seen this problem some answers, but still make mistakes.I have noticed the problem about the input negative number.

    int* twoSum(int* nums, int numsSize, int target, int* returnSize) {
    	int i,j;
        int result[2] = {};
        //int bucket[50000] = {};
    	int temptemp[200000] = {0};
        int *bucket = &temptemp[100000];
        for(i = 0;i < numsSize;i++){
            bucket[*(nums+i)] = 1;
        }
    	
        for(i = 0;i < numsSize;i++){
            if(bucket[target - *(nums+i)]==1)
    		{
               	for(j = numsSize - 1;j > i;j--){
                    if(*(nums+i) + *(nums+j) == target){
    					if(i < j)
                        result[0] = i + 1,result[1] = j + 1;
    					else
    					result[0] = j + 1,result[1] = i + 1;
    					
                    }
                }
    			break;
    		}
        }
    	*returnSize = result[0];
    	*(returnSize+1) = result[1];
        return returnSize;
    }

Log in to reply
 

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