There was an error while loading. Please reload this page.
1 parent 8a20fa9 commit 2c1ec6cCopy full SHA for 2c1ec6c
1 file changed
src/main/java/com/thealgorithms/maths/SumOfSquares.java
@@ -18,8 +18,13 @@ private SumOfSquares() {
18
*
19
* @param n the target number
20
* @return minimum number of squares needed
21
+ * @throws IllegalArgumentException if {@code n} is negative
22
*/
23
public static int minSquares(int n) {
24
+ if (n < 0) {
25
+ throw new IllegalArgumentException("Input must be non-negative");
26
+ }
27
+
28
if (isPerfectSquare(n)) {
29
return 1;
30
}
0 commit comments