Merge pull request #1930 from ZerenZhang2022/patch-13

Update 0202.快乐数.md
This commit is contained in:
程序员Carl 2023-03-15 09:56:17 +08:00 committed by GitHub
commit 2d557254a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 0 deletions

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