1. 程式人生 > >leetcode-happy number implemented in python

leetcode-happy number implemented in python

n-n etc leet pow pytho app 分析 hide i++

視頻分析:
http://v.youku.com/v_show/id_XMTMyODkyNDA0MA==.html?from=y1.7-1.2



class Solution(object):
    def isHappy(self, n):
        if n==1:
            return True
        elif n==4:
            return False
        else:
            return self.isHappy(self.Happy(n))

    def Happy(self,n)
:
z=0 while n!=0: d=n%10 z+=pow(d,2) n=(n-n%10)//10 return z def HappySeq(self,start,cnt): tmp=start print (tmp,end=‘ ‘) for x in range(1, cnt): tmp=self.Happy(tmp) print (tmp,end=‘ ‘) if
tmp==4 or tmp==1: break
‘).text(i)); }; $numbering.fadeIn(1700); }); });

leetcode-happy number implemented in python