LeetCode-216-组合总和III-C语言

/**
 * 算法思想:
 * 套用回溯算法框架
 *
 * 
 */

void get_one_ret(int *stack, int len, int target, int **ret, int *ret_index) {
    int cnt = 0;
    int i=0;
    
    while(i len) return;
    
    /* there are len numbers in stack, so try to get one result */
    if(index == len){
        get_one_ret(stack, len, target, ret, ret_index);
        return;
    }
    
    /* try to set num from last+1 to 9, because last used num is last,
     * we can't use it again, so try next one.
     */
    for(i=last+1; i<=9; i++) {
        stack[index] = i;
        rec(len, target, i, stack, index+1, ret, ret_index);
    }
}

#define LEN 0xffff
int** combinationSum3(int len, int target, int* returnSize, int** returnColumnSizes){
    int **ret = (int **)malloc(sizeof(int) * LEN);
    int *rcs = (int *)malloc(sizeof(int) * LEN);
    int ret_index = 0;
    int arr[len];
    int i;

    rec(len, target, 0, arr, 0, ret, &ret_index);

    for(i=0; i

你可能感兴趣的:(LeetCode)