a newbie's code


  • 0
    S

    hi,this is my code.maybe,it's not the best one.but I had to say,I tried my best, maybe next time it will be better!

    int* twoSum(int* nums, int numsSize, int target) {
    int i;
    int j;
    int back = (int)malloc(2 * sizeof(int));
    for (i = 0; i < numsSize; i++){
    for (j = i+1; j < numsSize; j++){
    if (target == nums[i] + nums[j]){
    if (i == j)
    break;
    else {
    back[0] = i;
    back[1] = j;
    return back;
    }
    }
    else if ((i == j)&&(i == numsSize-1)){
    printf("no match digit!\n");
    return NULL;
    }
    }
    }
    printf("no match digit\n");
    return NULL;
    }


Log in to reply
 

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