Skip to content

Commit 58c7a78

Browse files
committed
Refactor code formatting in KnapsackMemoization.java and UnionFind.java
1 parent 2c147e9 commit 58c7a78

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/main/java/com/thealgorithms/dynamicprogramming/KnapsackMemoization.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ int solveKnapsackRecursive(int capacity, int[] weights, int[] profits, int numOf
4141
return dpTable[numOfItems][capacity];
4242
} else {
4343
// case 1. include the item, if it is less than the capacity
44-
int includeCurrentItem = profits[numOfItems - 1]
45-
+ solveKnapsackRecursive(capacity - weights[numOfItems - 1], weights, profits, numOfItems - 1, dpTable);
44+
int includeCurrentItem = profits[numOfItems - 1] + solveKnapsackRecursive(capacity - weights[numOfItems - 1], weights, profits, numOfItems - 1, dpTable);
45+
4646

4747
// case 2. exclude the item if it is more than the capacity
4848
int excludeCurrentItem = solveKnapsackRecursive(capacity, weights, profits, numOfItems - 1, dpTable);

src/main/java/com/thealgorithms/searches/UnionFind.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ public int find(int i) {
2525
return i;
2626
}
2727

28-
int result = find(parent);
29-
p[i] = result;
28+
int result = find(parent);
29+
p[i] = result;
30+
3031
return result;
3132
}
3233

0 commit comments

Comments
 (0)