Skip to content

Commit 03003e8

Browse files
refactor(math): input validation
Input validation Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent f9d1ab9 commit 03003e8

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

pymath/perfect_square/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ def num_squares(n: int) -> int:
3737
Returns:
3838
int: The least number of perfect square numbers that sum to n.
3939
"""
40+
if n < 0:
41+
raise ValueError("n must be non-negative")
42+
if n == 0:
43+
return 0
44+
4045
dp = [float("inf")] * (n + 1)
4146
dp[0] = 0
4247

0 commit comments

Comments
 (0)