LeetCode上twoSums的C语言代码

    xiaoxiao2021-03-25  236

    int* twoSum(int* nums, int numSize, int target){     int temp, t;     int i;     for(i = 0;i < numSize; i++){         temp = nums[i];         t = search(nums, target - temp, i + 1, numSize - 1);         if(t != -1){             break;         }     }     int* solution = (int *)malloc(sizeof(int) * 2);     if(t != -1){         solution[0] = i;         solution[1] = t;       }     return solution; }     int search(int* nums, int key, int low, int high){     int i;     for(i = low;i <= high;i ++){         if(nums[i] == key){             return i;         }     }     return -1; }
    转载请注明原文地址: https://ju.6miu.com/read-1041.html

    最新回复(0)