Combination Sum IV思路:动态规划。
GitHub地址:https://github.com/corpsepiges/leetcode
目前java版本的答案大约进度是免费的差40题,python大约是一半,其他的等以后再补充。
public class Solution {
public int combinationSum4(int[] nums, int target) {
Arrays.sort(nums);
int[] ans=new int[target+1];
for (int i = 1; i < ans.length; i++) {
for (int j = 0; j < nums.length; j++) {
if (nums[j]<i) {
ans[i]+=ans[i-nums[j]];
}else{
ans[i]+=i/nums[j];
break;
}
}
}
return ans[target];
}
}