leetcode -. 202 happy number

Someone so smart, why I can only think of ideas but do not realize it. . . .

Still much to do before it

class Solution:
    def isHappy(self, n: int) -> bool:
        n=str(n)
        v=set()
        while 1:
            n=str(sum(int(i)**2 for i in n))
            if n=='1':
                return True
            if n in v:
                return False
            v.add(n)
When execution: 32 ms, defeated 100.00% of users in all Python3 submission
Memory consumption: 13.8 MB, beat the 5.56% of users in all Python3 submission
 
Read other people's answer was to do it.
A very weak.
To point to note:
1. The string can be converted to an integer;
2. To cycle has been going on with
while 1:
3. For the set, by adding add ()
                                                                                                                    ——2019.9.30
 
 
 
 
 

Guess you like

Origin www.cnblogs.com/taoyuxin/p/11613859.html