Last active
April 2, 2020 17:58
-
-
Save chirag-shinde/11e2701810e96418af3bf84284d74690 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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