mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-24 04:54:21 +08:00
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:
@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user