第一题

/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* twoSum(int* nums, int numsSize, int target, int* returnSize){
    int i,j,key;
    int *result=NULL;
    for(i=0;i<numsSize-1;i++)
    {
        key = target - nums[i];
        for(j=i+1;j<numsSize;j++)
        {
            if(key == nums[j])
            {
                 result=(int*)malloc(sizeof(int)*2);
                 result[0]=i;
                 result[1]=j;
                 *returnSize = 2; 
                 return result;
            }
        }
    }
    *returnSize = 0;
    return result;
}

 

posted @ 2022-11-19 14:19  Anita光子  阅读(19)  评论(0编辑  收藏  举报