首页 > 其他分享 >第一题

第一题

时间:2022-11-19 14:34:17浏览次数:45  
标签:numsSize returned 第一 int twoSum assume NULL

/**
 * 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;
}

 

标签:numsSize,returned,第一,int,twoSum,assume,NULL
From: https://www.cnblogs.com/anitaguangzi/p/16906052.html

相关文章