8 line C++ DP


  • 0
    F
    struct Solution {
        int combinationSum4(vector<int>& nums, int target) {
            int dp[target + 1] = {1} ;
            for (int i = 1; i <= target; ++i)
                for (int j = 1; j <= nums.size(); ++ j)
                    if (nums[j - 1] <= i)
                        dp[i] += dp[i - nums[j - 1]];
            return dp[target];
        }
    };
    

Log in to reply
 

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