My LeetCode grinding. Trying to do a problem a day.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223
  1. class Solution:
  2. def __init__(self):
  3. self.memo = dict()
  4. def isHappy(self, n):
  5. return self.recIsHappy(n)
  6. def recIsHappy(self, n):
  7. if n in self.memo:
  8. return False
  9. elif n == 1:
  10. return True
  11. else:
  12. self.memo[n] = True
  13. newN = 0
  14. for c in str(n):
  15. newN += int(c) ** 2
  16. return self.recIsHappy(newN)
  17. s = Solution()
  18. print("Expected: True")
  19. print("Got:", s.isHappy(19))