0 ms dp solution in C


  • 0
    D
    int combinationSum4(int* nums, int numsSize, int target) {
        int *dp = malloc(sizeof(int) * (target+1));
        memset(dp, 0, sizeof(int) * (target+1));
        int i;
        dp[0] = 1;
        for(i = 1; i <= target; i++){
            int j;
            for(j = 0; j < numsSize; j++){
                if(i >= nums[j]){
                    dp[i] = dp[i] + dp[i-nums[j]];
                }
            }
        }
        return dp[target];
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.