Skip to content

Commit 5320bec

Browse files
authored
style: mark includeCurrentItem and excludeCurrentItem as final
1 parent 2dce946 commit 5320bec

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ 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] + solveKnapsackRecursive(capacity - weights[numOfItems - 1], weights, profits, numOfItems - 1, dpTable);
44+
final int includeCurrentItem = profits[numOfItems - 1] + solveKnapsackRecursive(capacity - weights[numOfItems - 1], weights, profits, numOfItems - 1, dpTable);
4545

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

4949
// Store the value of function call stack in table and return
5050
dpTable[numOfItems][capacity] = Math.max(includeCurrentItem, excludeCurrentItem);

0 commit comments

Comments
 (0)