Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 months ago
538 B
2
Indexable
Never
int **subsets(int *nums, int numsSize, int *returnSize, int **returnColumnSizes) {
    int n = numsSize;

    *returnSize = (1 << n);
    *returnColumnSizes = malloc(sizeof(int) * (1 << n));
    int **ans = malloc(sizeof(int *) * (1 << n));

    for (int i = 0; i < (1 << n); i++) {
        int *arr = malloc(sizeof(int) * n);
        int index = 0;
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) arr[index++] = nums[j];
        }
        (*returnColumnSizes)[i] = index;
        ans[i] = arr;
    }
    return ans;
}
Leave a Comment