銆恖eetcode銆?8. 鍏ㄦ帓鍒?2

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了銆恖eetcode銆?8. 鍏ㄦ帓鍒?2相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/_1__1_' title='++'>++   amp   size   rgba   mss   ons   oid   const   sort   

 

int cmp(const void* a, const void* b){
    return *(int*)a - *(int*)b;
}
void recursion(int* nums, int numsSize, int* returnSize, int* returnColumnSizes, int cnt, int** arr, int* temp, int* hash){
    if (cnt == numsSize){
        arr[(*returnSize)] = (int*)calloc(numsSize + 1, sizeof(int));
        memcpy(arr[(*returnSize)], temp, cnt*sizeof(int));
        returnColumnSizes[(*returnSize)++] = cnt;
        return;
    }
    for (int i = 0; i<numsSize; i++){
        if (hash[i]) continue;
        hash[i]++;
        temp[cnt] = nums[i];
        recursion(nums, numsSize, returnSize, returnColumnSizes, cnt + 1, arr, temp, hash);
        hash[i]--;
        while (i != numsSize-1 && nums[i] == nums[i + 1])
            i++;
    }
}
int** permuteUnique(int* nums, int numsSize, int* returnSize, int** returnColumnSizes){
    int** arr = (int**)calloc(sizeof(int*), 1000);
    int* hash = (int*)calloc(sizeof(int), numsSize);
    *returnSize = 0;
    *returnColumnSizes = (int*)calloc(sizeof(int), 1000);
    int temp[1000] = { 0 };
    qsort(nums, numsSize, sizeof(int), cmp);
    recursion(nums, numsSize, returnSize, *returnColumnSizes, 0, arr, temp, hash);
    return arr;
}

 

以上是关于銆恖eetcode銆?8. 鍏ㄦ帓鍒?2的主要内容,如果未能解决你的问题,请参考以下文章

銆恖eetcode銆戦潰璇曢 08.10. 棰滆壊濉厖

銆怢eetCode銆?. Longest Palindromic Substring

鍗庝负姝e湪鍔涙尯鐨凬B-IoT鏄粈涔堥锛?- 鍏ㄦ枃

銆岄潰璇曞繀闂€峫eetcode楂橀棰樼簿閫?/a>

鍖楀ぇ绠楁硶澶х鐨凩eetCode鍒烽妯℃澘.pdf鏉ヤ簡锛?/h1>