标签:++ 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; }
标签:++ amp size rgba mss ons oid const sort
原文地址:https://www.cnblogs.com/ganxiang/p/14111468.html