diff --git a/Day-11/q2_Combination_sum_II/Anushreebasics--java.md b/Day-11/q2_Combination_sum_II/Anushreebasics--java.md new file mode 100644 index 00000000..8aa73999 --- /dev/null +++ b/Day-11/q2_Combination_sum_II/Anushreebasics--java.md @@ -0,0 +1,29 @@ +``` +class Solution { + List> ans; + public void helper(int arr[], int idx, List a, int target){ + if(target==0){ + System.out.println(a); + ans.add(new ArrayList<>(a)); + return; + } + if(idx==arr.length) return; + + if(arr[idx]<=target){ + a.add(arr[idx]); + helper(arr,idx+1,a,target-arr[idx]); + a.remove(a.size()-1); + } + int j = idx+1; + while(j> combinationSum2(int[] arr, int target) { + Arrays.sort(arr); + List a = new ArrayList<>(); + ans = new ArrayList<>(); + helper(arr,0,a,target); + return ans; + } +} +```