E-202. Happy Number
# 0 O(?), O(?)
class Solution:
def isHappy(self, n: int) -> bool:
seen = set()
while n not in seen:
seen.add(n)
n = sum(int(i)**2 for i in str(n))
print(seen)
return n == 1
Last updated
Was this helpful?