STANAANDREY

combi sum 4 lc

Apr 21st, 2021
736
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2.     private int []nums;
  3.     public int combinationSum4(int[] nums, int target) {
  4.         this.nums = nums;
  5.         Arrays.sort(this.nums);
  6.         return bktr(target);
  7.     }
  8.     private int bktr(int remaining) {
  9.         if (remaining == 0) {
  10.             return 1;
  11.         }
  12.         int cnt = 0;
  13.         for (int num : nums) {
  14.             if (num > remaining) {
  15.                 break;
  16.             }
  17.             cnt += bktr(remaining - num);
  18.         }
  19.         return cnt;
  20.     }
  21. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×