Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1868c3f

Browse files
and-starlabuladong
authored andcommitted
Fix qing-wa-tiao-tai-jie-wen-ti-lcof
1 parent 97a8ad3 commit 1868c3f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

‎多语言解法代码/solution_code.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50869,7 +50869,7 @@ var dp = function(n, memo) {
5086950869
class Solution:
5087050870
# 备忘录
5087150871
memo = []
50872-
50872+
MOD = 1e9 + 7
5087350873
def numWays(self, n: int) -> int:
5087450874
self.memo = [-1] * (n + 1)
5087550875
return self.dp(n)
@@ -50878,15 +50878,15 @@ class Solution:
5087850878
def dp(self, n: int) -> int:
5087950879
# base case
5088050880
if n <= 2:
50881-
return n
50881+
return n if n else 1
5088250882

5088350883
if self.memo[n] != -1:
5088450884
return self.memo[n]
5088550885

5088650886
# 状态转移方程:
5088750887
# 爬到第 n 级台阶的方法个数等于爬到 n - 1 的方法个数和爬到 n - 2 的方法个数之和。
5088850888
self.memo[n] = self.dp(n - 1) + self.dp(n - 2)
50889-
return self.memo[n]
50889+
return round(self.memo[n] % self.MOD)
5089050890
```
5089150891

5089250892
https://leetcode.cn/problems/qing-wa-tiao-tai-jie-wen-ti-lcof 的多语言解法👆

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /