程式語言 - LeetCode - C - 1. Two Sum



題目:


解答:

int* twoSum(int *nums, int numsSize, int target, int *returnSize)
{
    int c0 = 0;
    int c1 = 0;

    *returnSize = 2;
    for (c0 = 0; c0 < numsSize; c0++) {
        for (c1 = c0 + 1; c1 < numsSize; c1++) {
            if ((nums[c0] + nums[c1]) == target) {
                nums[0] = c0;
                nums[1] = c1;
                return nums;
            }
        }
    }
    return NULL;
}