类似于链表环中快慢指针的思想
class Solution(object):
def isHappy(self, n):
"""
:type n: int
:rtype: bool
"""
def squareSum(n):
res=0
while n:
yu=n%10
res+=yu*yu
n=n//10
return res
slow=fast=n
while 1:
slow = squareSum(slow)
fast = squareSum(fast)
fast = squareSum(fast)
if slow==fast: break
return slow==1