[LeetCode][python3]Day02. Happy Number (30-Day LeetCoding Challenge)
30 days! Lets go Lets go!
N2I -2020.04.02
- My solution
class Solution:
def isHappy(self, n: int) -> bool:
return self.check(n)
def check(self,n):
if n==1 or n==7:
return True
elif len(str(n))==1:
return False
s=0
for i in str(n):
s+=int(i)**2
return self.check(int(s))
Explanation:
Remember to use return self.check(s)
instead of self.check(s)
, or else you will get a return None
in the answer.