202. Happy Number
Question 202
Input: 19
Output: true
Explanation:
1**2 + 9**2 = 82
8**2 + 2**2 = 68
6**2 + 8**2 = 100
1**2 + 0**2 + 0**2 = 1Answer
class Solution:
def isHappy(self, n):
res = 0
HappyNum = [1,7]
print(n)
while ( n > 0 ):
res += (n%10)**2
n = n // 10
if(res < 10):
if res in HappyNum:
return True
else:
return False
return self.isHappy(res)Last updated