TwoSum


  • 0
    Q

    int* twoSum(int* nums, int numsSize, int target) {
    int *res = (int *)malloc(sizeof(int) * 2);
    res[0] = 0;
    res[1] = 1;

    if (2 == numsSize)
        return res;
    
    int maybe = numsSize * (numsSize - 1)/2;
    
    int x = 0;
    int y = 1;
    for (; x < maybe;) {
        for (; y < numsSize;) {
            if ((nums[x] + nums[y]) == target) {
                res[0] = x;
                res[1] = y;
                return res;
            }
            ++y;
        }
    
        x += 1;
        y = x + 1;
    }
    
    return res;
    

    }


Log in to reply
 

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