Update Knapsack.java

Added check if the arrays are null
This commit is contained in:
qwerty50000a
2019-09-25 17:21:54 -04:00
committed by GitHub
parent 23ca7169e8
commit 9743e7506f

View File

@ -6,7 +6,9 @@ package DynamicProgramming;
public class Knapsack {
private static int knapSack(int W, int wt[], int val[], int n) {
private static int knapSack(int W, int wt[], int val[], int n) throws IllegalArgumentException {
if(wt == null || val == null)
throw new IllegalArgumentException();
int i, w;
int rv[][] = new int[n + 1][W + 1]; //rv means return value