C++, simple


  • 0
    class Solution {
    public:
        int combinationSum4(vector<int>& nums, int target) {
            int len = nums.size();
            if(len==0 || target==0) return 0;
            vector<int> dp(target+1,0);
            dp[0] = 1;
            int cur = 1;
            int pt = 0;
            for(;cur<=target;cur++) {
                int sum = 0;
                for(int i=0;i<len;i++) {
                    if(cur-nums[i]>=0) dp[cur]+=dp[cur-nums[i]];
                }
            }
            return dp[target];
        }
    };
    

Log in to reply
 

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