(int[] nums, int i, int k, int subsetSum, boolean[] used)
| 15 | } |
| 16 | |
| 17 | private boolean backtrack(int[] nums, int i, int k, int subsetSum, boolean[] used){ |
| 18 | if(k == 0) |
| 19 | return true; |
| 20 | if(subsetSum == target) |
| 21 | return backtrack(nums, 0, k-1, 0, used); |
| 22 | |
| 23 | for(int j = i; j < nums.length; j++){ |
| 24 | if(j > 0 && !used[j-1] && nums[j] == nums[j-1]) |
| 25 | continue; |
| 26 | if(used[j] || subsetSum + nums[j] > target) |
| 27 | continue; |
| 28 | |
| 29 | used[j] = true; |
| 30 | if(backtrack(nums, j+1, k, subsetSum + nums[j], used)) |
| 31 | return true; |
| 32 | |
| 33 | used[j] = false; |
| 34 | } |
| 35 | return false; |
| 36 | } |
| 37 | } |
no outgoing calls
no test coverage detected