Created
April 3, 2020 06:00
-
-
Save vamsitallapudi/0eec6d7bf8d5f1610b16707cf60e4c95 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 isHappy(self, n: int) -> bool: | |
result = False | |
visited = set() | |
while not result and n not in visited: | |
visited.add(n) | |
p = [int(_) for _ in str(n)] | |
n = sum(list(map(lambda a: a ** 2, p))) | |
if n == 1: | |
result = True | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment