mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 15:45:40 +08:00
Update 0202.快乐数.md
python的另一种写法 - 通过字符串来计算各位平方和
This commit is contained in:
@ -132,6 +132,19 @@ class Solution:
|
||||
else:
|
||||
record.add(n)
|
||||
|
||||
# python的另一种写法 - 通过字符串来计算各位平方和
|
||||
class Solution:
|
||||
def isHappy(self, n: int) -> bool:
|
||||
record = []
|
||||
while n not in record:
|
||||
record.append(n)
|
||||
newn = 0
|
||||
nn = str(n)
|
||||
for i in nn:
|
||||
newn+=int(i)**2
|
||||
if newn==1: return True
|
||||
n = newn
|
||||
return False
|
||||
```
|
||||
|
||||
Go:
|
||||
|
Reference in New Issue
Block a user