update 202

This commit is contained in:
sangge-rockpi 2024-01-22 16:04:13 +08:00
parent 530f995d46
commit a35d60437a

19
leetcode/202.py Normal file
View File

@ -0,0 +1,19 @@
# 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 += number * number
if total == 1:
return True
if str(total) in status:
return False
status.apepnd(str(total))
self.isHappy(total, status)