题解 | 快乐数
快乐数
https://www.nowcoder.com/practice/293b9ddd48444fa493dd17da0feb192d
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param n int整型
# @return bool布尔型
#
class Solution:
def happynum(self , n: int) -> bool:
# write code here
seen=set()
while n!=1:
if n in seen:
return False
seen.add(n)
n = sum(int(d) ** 2 for d in str(n))
return True