LeetCode-1-Two Sum(C语言实现)

来源:互联网 发布:mac电脑磁盘在哪里 编辑:程序博客网 时间:2024/05/16 18:22
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* twoSum(int* nums, int numsSize, int target) {
    int i, j;
    int *get;
    get = (int*)malloc(2 * sizeof(int));
    
    for (i = 0; i < numsSize - 1; ++i)
        for(j = i + 1; j < numsSize; ++j)
            if(nums[i] + nums[j] == target)
            {
                get[0] = i;
                get[1] = j;
                break;
                break;
            }
    return get;
}