2024-01-22 16:05:44 +08:00

20 lines
501 B
Python

# Happy Number
# Repeat the process until the number equal to 1, these are happy
# OR LOOP ENDLESS in a cycle, these are not happy
class Solution:
def isHappy(self, n: int, status: list = []) -> bool:
str_n = str(n)
total = 0
for number in str_n:
total += str(number) * str(number)
if total == 1:
return True
if str(total) in status:
return False
status.apepnd(str(total))
self.isHappy(total, status)