class Solution:
def isHappy(self, n):
"""
:type n: int
:rtype: bool
"""
unhappy = [4,16,37,58,89,145,42,20]
if n in unhappy:
return False
he = 0
for i in str(n):
he += int(i)**2
if he == 1:
return True
else:
return self.isHappy(he)
key: 找出不快乐数特征
class Solution:
def isHappy(self, n):
"""
:type n: int
:rtype: bool
"""
unhappy = [4,16,37,58,89,145,42,20]
if n in unhappy:
return False
he = 0
for i in str(n):
he += int(i)**2
if he == 1:
return True
else:
return self.isHappy(he)
key: 找出不快乐数特征