1 Star 0 Fork 0

syysui/Java

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Sum_Of_Subset.java 754 Bytes
一键复制 编辑 原始数据 按行查看 历史
Aitor Fidalgo Sánchez 提交于 2021-10-16 21:43 +08:00 . Fix package declarations (#2576)
package DynamicProgramming;
public class Sum_Of_Subset {
public static void main(String[] args){
int[] arr = { 7, 3, 2, 5, 8 };
int Key = 14;
if (subsetSum(arr, arr.length - 1, Key)) {
System.out.print("Yes, that sum exists");
}
else {
System.out.print("Nope, that number does not exist");
}
}
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;
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/syysui/Java.git
git@gitee.com:syysui/Java.git
syysui
Java
Java
master

搜索帮助