1. 程式人生 > >377. Combination Sum IV (DP)

377. Combination Sum IV (DP)

++ ati class += tar spa ons i++ bin

 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 }

377. Combination Sum IV (DP)