leetcode - 202 - 快乐数

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: 找出不快乐数特征

猜你喜欢

转载自blog.csdn.net/hustwayne/article/details/85227708