File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed
Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change 11def is_automorphic (n : int ) -> bool :
22 """
33 Check if a number is an Automorphic Number.
4+
45 A number is automorphic if its square ends with the number itself.
56
7+ Args:
8+ n: A non-negative integer.
9+
10+ Returns:
11+ True if n is automorphic, False otherwise.
12+
613 Examples:
714 >>> is_automorphic(5)
815 True
@@ -12,9 +19,17 @@ def is_automorphic(n: int) -> bool:
1219 True
1320 >>> is_automorphic(7)
1421 False
22+ >>> is_automorphic(-5)
23+ Traceback (most recent call last):
24+ ...
25+ ValueError: n must be a non-negative integer
1526
16- Time Complexity: O(d) where d is number of digits
27+ Time Complexity:
28+ O(d) where d is the number of digits of n.
1729 """
30+ if n < 0 :
31+ raise ValueError ("n must be a non-negative integer" )
32+
1833 square = n * n
1934 return str (square ).endswith (str (n ))
2035
You can’t perform that action at this time.
0 commit comments