mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-06 09:06:51 +08:00
Add edge case to handle negative rod length in RodCutting algorithm (#5904)
This commit is contained in:
@ -22,6 +22,10 @@ public final class RodCutting {
|
||||
if (price == null || price.length == 0) {
|
||||
throw new IllegalArgumentException("Price array cannot be null or empty.");
|
||||
}
|
||||
if (n < 0) {
|
||||
throw new IllegalArgumentException("Rod length cannot be negative.");
|
||||
}
|
||||
|
||||
// Create an array to store the maximum obtainable values for each rod length.
|
||||
int[] val = new int[n + 1];
|
||||
val[0] = 0;
|
||||
|
Reference in New Issue
Block a user