Merge pull request #1930 from ZerenZhang2022/patch-13
Update 0202.快乐数.md
This commit is contained in:
commit
2d557254a1
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in New Issue