Skip to content

Commit a07a44d

Browse files
committed
Fix: Dynamic Programming - Subset Sum Problem
1 parent 27f5cd0 commit a07a44d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

DynamicProgramming/SubsetSumProblem/Solution.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// import java.util.*;
44

55
/**
6-
* * Subset Sum Problem
6+
* * Subset Sum Problem (Variation of 0/1 Knapsack)
77
*/
88
public class Solution {
99
public boolean hasSubsetSum(int[] array, int sum) {
@@ -72,7 +72,8 @@ private boolean hasSubsetSumDP(int[] array, int sum) {
7272
* * SC: O(ns)
7373
*/
7474
// private boolean hasSubsetSumMem(int index, int[] array, int sum, boolean[][] cache) {
75-
// if (index == 0) return sum == 0;
75+
// if (sum == 0) return true;
76+
// if (index == 0) return false;
7677

7778
// if (cache[index][sum]) return true;
7879

@@ -91,7 +92,8 @@ private boolean hasSubsetSumDP(int[] array, int sum) {
9192
* * SC: Exponential time
9293
*/
9394
// private boolean hasSubsetSumRec(int index, int[] array, int sum) {
94-
// if (index == 0) return sum == 0;
95+
// if (sum == 0) return true;
96+
// if (index == 0) return false;
9597

9698
// if (array[index] <= sum)
9799
// return hasSubsetSumRec(index - 1, array, sum - array[index])

0 commit comments

Comments
 (0)