Skip to content

Commit 9743e75

Browse files
authored
Update Knapsack.java
Added check if the arrays are null
1 parent 23ca716 commit 9743e75

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

DynamicProgramming/Knapsack.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
public class Knapsack {
88

9-
private static int knapSack(int W, int wt[], int val[], int n) {
9+
private static int knapSack(int W, int wt[], int val[], int n) throws IllegalArgumentException {
10+
if(wt == null || val == null)
11+
throw new IllegalArgumentException();
1012
int i, w;
1113
int rv[][] = new int[n + 1][W + 1]; //rv means return value
1214

0 commit comments

Comments
 (0)