Skip to content

Instantly share code, notes, and snippets.

@arkilis
Last active January 9, 2016 11:38
Show Gist options
  • Save arkilis/1730ece531567eb6f661 to your computer and use it in GitHub Desktop.
Save arkilis/1730ece531567eb6f661 to your computer and use it in GitHub Desktop.
class Solution(object):
def isHappy(self, n):
"""
:type n: int
:rtype: bool
"""
def rec_happy(n, ary_temp):
sz= str(n)
sum= 0
for e in sz:
sum+=int(e)**2
if(sum==1):
return True
else:
if(sum not in ary_temp):
ary_temp.append(sum)
return rec_happy(sum, ary_temp)
else:
return False
return rec_happy(n, [])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment