Skip to content

Instantly share code, notes, and snippets.

@yesidays
Created April 3, 2020 03:38
Show Gist options
  • Save yesidays/468d0973756fab8c2d31543133c42b74 to your computer and use it in GitHub Desktop.
Save yesidays/468d0973756fab8c2d31543133c42b74 to your computer and use it in GitHub Desktop.
Happy Number - Leetcode
#https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/528/week-1/3284/
class Solution(object):
def isHappy(self, n):
"""
:type n: int
:rtype: bool
"""
exists = set()
while n != 1:
n = sum( [int(i)**2 for i in str(n)] )
if n in exists:
return False
else:
exists.add(n)
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment