mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 08:50:15 +08:00
Merge branch 'youngyangyang04:master' into master
This commit is contained in:
@ -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]应该是多少呢,这个可以有很多解释,但基本都是直接奔着答案去解释的。
|
||||
|
||||
|
@ -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