本文主要是介绍377. Combination Sum IV (Medium),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
class Solution {public int combinationSum4(int[] nums, int target) {int[] maximum = new int[target + 1];maximum[0] = 1;Arrays.sort(nums);//求解顺序的完全背包问题时,对物品的迭代应该放在最里层。for (int i = 1; i <= target; i++) {for (int j = 0; j < nums.length && nums[j] <= i; j++) {maximum[i] += maximum[i - nums[j]];} }return maximum[target];}
}
这篇关于377. Combination Sum IV (Medium)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!