docs(notes): update coding-interview 10.4
- Update coding-interview 10.4(Jump Floor II) - Add a contributor @yanglbme in README.md
This commit is contained in:
parent
26d0142b4b
commit
49a5bc55b7
@ -232,6 +232,10 @@ Power by [logomakr](https://logomakr.com/).
|
|||||||
<a href="https://github.com/mafulong">
|
<a href="https://github.com/mafulong">
|
||||||
<img src="https://avatars1.githubusercontent.com/u/24795000?s=400&v=4" width="50px">
|
<img src="https://avatars1.githubusercontent.com/u/24795000?s=400&v=4" width="50px">
|
||||||
</a>
|
</a>
|
||||||
|
<a href="https://github.com/yanglbme">
|
||||||
|
<img src="https://avatars1.githubusercontent.com/u/21008209?s=400&v=4" width="50px">
|
||||||
|
</a>
|
||||||
|
|
||||||
|
|
||||||
#### License
|
#### License
|
||||||
|
|
||||||
|
@ -587,6 +587,8 @@ public int RectCover(int n) {
|
|||||||
|
|
||||||
## 解题思路
|
## 解题思路
|
||||||
|
|
||||||
|
### 动态规划
|
||||||
|
|
||||||
```java
|
```java
|
||||||
public int JumpFloorII(int target) {
|
public int JumpFloorII(int target) {
|
||||||
int[] dp = new int[target];
|
int[] dp = new int[target];
|
||||||
@ -598,6 +600,34 @@ public int JumpFloorII(int target) {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 数学式子推导
|
||||||
|
|
||||||
|
跳上 n-1 级台阶,可以从 n-2 级跳 1 级上去,也可以从 n-3 级跳 2 级上去...也可以从 0 级跳上去。那么
|
||||||
|
```
|
||||||
|
f(n-1) = f(n-2) + f(n-3) + ... + f(0) ①
|
||||||
|
```
|
||||||
|
|
||||||
|
同样,跳上 n 级台阶,可以从 n-1 级跳 1 级上去,也可以从 n-2 级跳 2 级上去...也可以从 0 级跳上去。那么
|
||||||
|
```
|
||||||
|
f(n) = f(n-1) + f(n-2) + ... + f(0) ②
|
||||||
|
```
|
||||||
|
|
||||||
|
②-①:
|
||||||
|
```
|
||||||
|
f(n) - f(n-1) = f(n-1)
|
||||||
|
f(n) = 2*f(n-1)
|
||||||
|
```
|
||||||
|
|
||||||
|
所以 f(n) 是一个等比数列:
|
||||||
|
```
|
||||||
|
f(n) = 2^(n-1)
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
public int JumpFloorII(int target) {
|
||||||
|
return (int) Math.pow(2, target - 1);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
# 11. 旋转数组的最小数字
|
# 11. 旋转数组的最小数字
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user