78. 서브집합(C 언어) 소급법
876 단어 제목에 힘쓰다
int** subsets(int* nums, int numsSize, int* returnSize, int** returnColumnSizes) {
int** ret = malloc(10000);
int* buf = malloc(10000);
*returnSize = 0;
*returnColumnSizes = malloc(10000);
backtrack(ret, buf, 0,0, nums, numsSize, returnSize, returnColumnSizes);
return ret;
}
void backtrack(int** ret, int* buf, int pos,int j, int* nums, int numsSize, int* returnSize, int** returnColumnSizes) {
if (pos == numsSize) {
if (j >= 0) {
ret[*returnSize] = malloc(numsSize * 4);
memcpy(ret[*returnSize], buf, 4 * j);
(*returnColumnSizes)[*returnSize] = j;
(*returnSize)++;
j = 0;
return;
}
}
else {
backtrack(ret, buf, pos + 1, j, nums, numsSize, returnSize, returnColumnSizes);
buf[j] = nums[pos];
backtrack(ret, buf, pos + 1, j + 1, nums, numsSize, returnSize, returnColumnSizes);
}
}