老师你好。
我在做leetcode第377题时,想用dfs解决,但是怎么想backtrack的时候got stuck不知道咋做了,老师能帮看下么?
https://leetcode.com/problems/combination-sum-iv
class Solution {
private int count;
public int combinationSum4(int[] nums, int target) {
Arrays.sort(nums);
this.count = 0;
_find(nums, target, 0);
return count;
}
private void _find(int[] nums, int target, int start) {
if (target == 0) {
count++;
return;
}
for (int i = start; i < nums.length; i++) {
if(nums[i] > target) {
break;
}
_find(nums, target - nums[i], i);
//how to backtrack?
}
}
}