Skip to content

Commit 563cf29

Browse files
committed
Dp subset sub problem
1 parent a3e35c6 commit 563cf29

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎src/algo/dp/SubsetSum.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ boolean subsetSum2(int[] set, int sum) {
1616
for (int i = 1; i < a.length; i++) {
1717
a[i - 1][0] = true;
1818
for (int j = 1; j < a[i].length; j++) {
19-
if (a[i - 1][j] || j < set[i])
19+
if (j < set[i])
2020
a[i][j] = a[i - 1][j];
2121
else
22-
a[i][j] = a[i - 1][j - set[i]];
22+
a[i][j] = a[i - 1][j] || a[i - 1][j - set[i]];
2323
}
2424
}
2525
return a[set.length - 1][sum];

0 commit comments

Comments
 (0)