Created
April 2, 2020 18:27
-
-
Save chirag-shinde/dd31ce993dc4c782368cb1409f10ebf7 to your computer and use it in GitHub Desktop.
This file contains 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: | |
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