Last active
January 9, 2016 11:38
-
-
Save arkilis/1730ece531567eb6f661 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(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