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 n > 9:
a = 0
while n != 0:
a = a + (n%10) *(n%10)
n = n/10
n = a
if n == 1 or n == 7:
return True
else:
return False
lintcode:快乐数
最新推荐文章于 2019-06-26 21:58:03 发布