diff --git a/leetcode/202.py b/leetcode/202.py index 50d57c1..61773b6 100644 --- a/leetcode/202.py +++ b/leetcode/202.py @@ -4,11 +4,14 @@ class Solution: - def isHappy(self, n: int, status: list = []) -> bool: + def isHappy(self, n: int, status=None) -> bool: + if status is None: + status = [] + str_n = str(n) total = 0 for number in str_n: - total += int(number) * int(number) + total += int(number) ** 2 if total == 1: return True if str(total) in status: @@ -19,5 +22,5 @@ class Solution: if __name__ == "__main__": - number = 19 - print(Solution().isHappy(19)) + number = 13 + print(Solution().isHappy(number))