377. Combination Sum IV (DP)

 1 class Solution {
 2     public int combinationSum4(int[] nums, int target) {
 3         int[] res = new int[target + 1];
 4         res[0] = 1;
 5         for(int i = 1; i <= target; i++) {
 6             for(int j = 0; j < nums.length; j++) {
 7                 if(nums[j] <= i && res[i - nums[j]] > 0) {
 8                     res[i] += res[i - nums[j]] ;
 9                 }
10             }
11         }
12         return res[target];
13 
14         
15     }
16 }

 

posted @ 2018-08-02 23:18  jasoncool1  阅读(153)  评论(0编辑  收藏  举报