Created
February 3, 2022 10:43
-
-
Save x1001000/5978b4d1a74ed7421d8276c626512063 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 isHappy(self, n: int) -> bool: | |
cycle = [] | |
while n not in cycle and n != 1: | |
cycle.append(n) | |
n = sum(map(lambda x: int(x)**2, str(n))) | |
return True if n == 1 else False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment