Skip to content

Instantly share code, notes, and snippets.

@chirag-shinde
Created April 2, 2020 18:27
Show Gist options
  • Save chirag-shinde/dd31ce993dc4c782368cb1409f10ebf7 to your computer and use it in GitHub Desktop.
Save chirag-shinde/dd31ce993dc4c782368cb1409f10ebf7 to your computer and use it in GitHub Desktop.
class Solution:
def sum_of_squares(self, n: int) -> int:
total = 0
while n > 0:
total += (n % 10) ** 2
n = int(n / 10)
return total
def isHappy(self, n: int) -> bool:
fast = self.sum_of_squares(n)
while n != 1 and fast != 1:
if n == fast:
return False
n = self.sum_of_squares(n)
fast = self.sum_of_squares(self.sum_of_squares(fast))
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment