class Solution:
def isHappy(self, n: int) -> bool:
visit = set()
def happy(n):
temp = n
n = 0
for i in str(temp):
n += int(i)**2
if n == 1:
return True
elif n in visit:
return False
else:
visit.add(n)
happy(n)
return happy(n)
hello guys.
input is 19
n will be 100 > 82 > 68 > 1
but result is False
can somebody explain why?
End of the
happy()function:You're discarding the result of calling
happy(n), you need to return that value.