Python, LintCode, 488. 快乐数

class Solution:
    """
    @param n: An integer
    @return: true if this is a happy number or false
    """
    def isHappy(self, n):
        # write your code here
        while True:
            tmp = 0
            n = str(n)
            for i in n:
                tmp += int(i) ** 2
            n = tmp
            if tmp == 1:
                return True
            if tmp == 4:
                return False

猜你喜欢

转载自blog.csdn.net/u010342040/article/details/80289741