- 32ms
- 68%
class Solution:
def isHappy(self, n: int) -> bool:
visited = set()
while True:
if n in visited: return False
if n==1: return True
visited.add(n)
tmp = 0
while n:
tmp += (n%10)**2
n //= 10
n = tmp