mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-11 06:04:27 +08:00
Update Knapsack.java
Added check if the arrays are null
This commit is contained in:
@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user