Beat 97% easy to understand Python solution. Used recursion


  • 0
    Y

    Beat 97% easy to understand Python solution. Used recursion

    class Solution(object):
        def isHappy(self, n):
            return(self.helper(n,[n]))
    
        def helper(self,n,looped):
            new=0
            num=list(str(n))
            for i in num:
                new=new+int(i)*int(i)
            if new == 1:
                return True
            elif new in looped:
                return False
            else:
                looped.append(new)
                return(self.helper(new,looped))
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.