[LeetCode][python3]Day02. Happy Number (30-Day LeetCoding Challenge)

30 days! Lets go Lets go!
N2I -2020.04.02

1. My Solution

  1. class Solution:
  2. def isHappy(self, n: int) -> bool:
  3. return self.check(n)
  4. def check(self,n):
  5. if n==1 or n==7:
  6. return True
  7. elif len(str(n))==1:
  8. return False
  9. s=0
  10. for i in str(n):
  11. s+=int(i)**2
  12. 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.