LintCode:快乐数

LintCode:快乐数

Python代码

class Solution:
    # @param {int} n an integer
    # @return {boolean} true if this is a happy number or false
    n_list = []
    def isHappy(self, n):
        # Write your code here
        if n==1:
            return True
        elif n in self.n_list:
            return False
        else:
            self.n_list.append(n)
            n1 = 0
            for i in str(n):
                n1 += int(i)*int(i)
            return self.isHappy(n1)

你可能感兴趣的:(python)