Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- private int []nums;
- public int combinationSum4(int[] nums, int target) {
- this.nums = nums;
- Arrays.sort(this.nums);
- return bktr(target);
- }
- private int bktr(int remaining) {
- if (remaining == 0) {
- return 1;
- }
- int cnt = 0;
- for (int num : nums) {
- if (num > remaining) {
- break;
- }
- cnt += bktr(remaining - num);
- }
- return cnt;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement