update 202

This commit is contained in:
sangge-rockpi 2024-01-22 16:19:44 +08:00
parent 85b45fcbfe
commit eff95054a8

View File

@ -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))