|
|
@ -24,3 +24,25 @@ class Solution { |
|
|
|
} |
|
|
|
} |
|
|
|
``` |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#### [10- II. 青蛙跳台阶问题](https://leetcode-cn.com/problems/qing-wa-tiao-tai-jie-wen-ti-lcof/) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```java |
|
|
|
|
|
|
|
class Solution { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int numWays(int n) { |
|
|
|
|
|
|
|
int result = 0; |
|
|
|
|
|
|
|
int start = 1; |
|
|
|
|
|
|
|
int end = 1; |
|
|
|
|
|
|
|
if (n == 0 || n == 1) { |
|
|
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for (int i = 2; i <= n; i++) { |
|
|
|
|
|
|
|
result = (start + end) % 1000000007; |
|
|
|
|
|
|
|
start = end; |
|
|
|
|
|
|
|
end = result; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|