diff --git a/problems/0070.爬楼梯.md b/problems/0070.爬楼梯.md index ed9be618..d8246223 100644 --- a/problems/0070.爬楼梯.md +++ b/problems/0070.爬楼梯.md @@ -72,7 +72,7 @@ dp[i]: 爬到第i层楼梯,有dp[i]种方法 3. dp数组如何初始化 -在回顾一下dp[i]的定义:爬到第i层楼梯,有dp[i]中方法。 +再回顾一下dp[i]的定义:爬到第i层楼梯,有dp[i]中方法。 那么i为0,dp[i]应该是多少呢,这个可以有很多解释,但基本都是直接奔着答案去解释的。 diff --git a/problems/0202.快乐数.md b/problems/0202.快乐数.md index 1a7d53a3..2687574f 100644 --- a/problems/0202.快乐数.md +++ b/problems/0202.快乐数.md @@ -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: