Add tests SumOfSubset (#5021)

* Updated main and test

* removed

* style: reorder test cases

---------

Co-authored-by: Piotr Idzik <65706193+vil02@users.noreply.github.com>
This commit is contained in:
Bhishmadev Ghosh
2024-01-27 00:00:26 +05:30
committed by GitHub
parent a216cb8a59
commit 55f08cc013
2 changed files with 18 additions and 12 deletions

View File

@ -0,0 +1,18 @@
package com.thealgorithms.dynamicprogramming;
public class SumOfSubset {
public static boolean subsetSum(int[] arr, int num, int Key) {
if (Key == 0) {
return true;
}
if (num < 0 || Key < 0) {
return false;
}
boolean include = subsetSum(arr, num - 1, Key - arr[num]);
boolean exclude = subsetSum(arr, num - 1, Key);
return include || exclude;
}
}