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 }
原文地址:https://www.cnblogs.com/goPanama/p/9410842.html
时间: 2024-10-16 20:16:44