auto commit
This commit is contained in:
parent
52033af3dc
commit
2d9d6813a1
|
@ -469,15 +469,15 @@ public class Solution {
|
|||
一只青蛙一次可以跳上 1 级台阶,也可以跳上 2 级。求该青蛙跳上一个 n 级的台阶总共有多少种跳法。
|
||||
|
||||
```java
|
||||
public int JumpFloor(int target) {
|
||||
if (target == 1) return 1;
|
||||
int[] dp = new int[target];
|
||||
public int JumpFloor(int n) {
|
||||
if (n == 1) return 1;
|
||||
int[] dp = new int[n];
|
||||
dp[0] = 1;
|
||||
dp[1] = 2;
|
||||
for (int i = 2; i < dp.length; i++) {
|
||||
for (int i = 2; i < n; i++) {
|
||||
dp[i] = dp[i - 1] + dp[i - 2];
|
||||
}
|
||||
return dp[target - 1];
|
||||
return dp[n - 1];
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -488,15 +488,15 @@ public int JumpFloor(int target) {
|
|||
一只青蛙一次可以跳上 1 级台阶,也可以跳上 2 级……它也可以跳上 n 级。求该青蛙跳上一个 n 级的台阶总共有多少种跳法。
|
||||
|
||||
```java
|
||||
public int JumpFloorII(int target) {
|
||||
int[] dp = new int[target];
|
||||
public int JumpFloorII(int n) {
|
||||
int[] dp = new int[n];
|
||||
Arrays.fill(dp, 1);
|
||||
for (int i = 1; i < target; i++) {
|
||||
for (int j = 0; j < i; j++) {
|
||||
for(int i = 1; i < n; i++) {
|
||||
for(int j = 0; j < i; j++) {
|
||||
dp[i] += dp[j];
|
||||
}
|
||||
}
|
||||
return dp[target - 1];
|
||||
return dp[n - 1];
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -507,9 +507,15 @@ public int JumpFloorII(int target) {
|
|||
我们可以用 2\*1 的小矩形横着或者竖着去覆盖更大的矩形。请问用 n 个 2\*1 的小矩形无重叠地覆盖一个 2\*n 的大矩形,总共有多少种方法?
|
||||
|
||||
```java
|
||||
public int RectCover(int target) {
|
||||
if (target <= 2) return target;
|
||||
return RectCover(target - 1) + RectCover(target - 2);
|
||||
public int RectCover(int n) {
|
||||
if (n < 2) return n;
|
||||
int[] dp = new int[n];
|
||||
dp[0] = 1;
|
||||
dp[1] = 2;
|
||||
for (int i = 2; i < n; i++) {
|
||||
dp[i] = dp[i - 1] + dp[i - 2];
|
||||
}
|
||||
return dp[n - 1];
|
||||
}
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user