Skip to content

Instantly share code, notes, and snippets.

@chirag-shinde
Last active April 2, 2020 17:58
Show Gist options
  • Save chirag-shinde/11e2701810e96418af3bf84284d74690 to your computer and use it in GitHub Desktop.
Save chirag-shinde/11e2701810e96418af3bf84284d74690 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:
repeat_numbers = set()
while n != 1:
total = self.sum_of_squares(n)
if total in repeat_numbers:
return False
else:
repeat_numbers.add(total)
n = total
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment