Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2b0a3b0

Browse files
authored
Update Knapsack.java
Changed OR condition to &&, OR may possibly result in ArrayIndexOutOfBoundException , (as it does for following input capacity : 60, weights: [10, 20, 33], values: [10, 3, 30])
1 parent 2adccbd commit 2b0a3b0

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

‎src/com/jwetherell/algorithms/mathematics/Knapsack.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static final int[] zeroOneKnapsack(int[] values, int[] weights, int capac
4040
final List<Integer> list = new ArrayList<Integer>();
4141
int i = height - 1;
4242
int j = width - 1;
43-
while (i != 0 || j != 0) {
43+
while (i != 0 && j != 0) {
4444
int current = output[i][j];
4545
int above = output[i - 1][j];
4646
if (current == above) {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /