Update 0202.快乐数.md

python的另一种写法 - 通过字符串来计算各位平方和
This commit is contained in:
ZerenZhang2022
2023-03-06 01:49:19 -05:00
committed by GitHub
parent 5ec197d1b4
commit 3a16650abe

View File

@ -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