```
class Solution(object):
def isHappy(self, n):
"""
:type n: int
:rtype: bool
"""
if n == 1:
return True
n = str(n)
s = set()
while int(n) != 1:
j = 0
for i in n:
j += int(i)**2
if j == 1:
return True
if j in s:
break
else:
s.add(int(n))
n = str(j)
return int(n) == 1
```