Skip to content

Commit 2967bdb

Browse files
authored
Merge pull request #496 from yanglbme/coding-interview
docs(notes): update coding-interview 10.4
2 parents 26d0142 + 49a5bc5 commit 2967bdb

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ Power by [logomakr](https://logomakr.com/).
232232
<a href="https://github.com/mafulong">
233233
​ <img src="https://avatars1.githubusercontent.com/u/24795000?s=400&v=4" width="50px">
234234
</a>
235+
<a href="https://github.com/yanglbme">
236+
​ <img src="https://avatars1.githubusercontent.com/u/21008209?s=400&v=4" width="50px">
237+
</a>
238+
235239

236240
#### License
237241

notes/剑指 offer 题解.md

+30
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,8 @@ public int RectCover(int n) {
587587

588588
## 解题思路
589589

590+
### 动态规划
591+
590592
```java
591593
public int JumpFloorII(int target) {
592594
int[] dp = new int[target];
@@ -598,6 +600,34 @@ public int JumpFloorII(int target) {
598600
}
599601
```
600602

603+
### 数学式子推导
604+
605+
跳上 n-1 级台阶,可以从 n-2 级跳 1 级上去,也可以从 n-3 级跳 2 级上去...也可以从 0 级跳上去。那么
606+
```
607+
f(n-1) = f(n-2) + f(n-3) + ... + f(0) ①
608+
```
609+
610+
同样,跳上 n 级台阶,可以从 n-1 级跳 1 级上去,也可以从 n-2 级跳 2 级上去...也可以从 0 级跳上去。那么
611+
```
612+
f(n) = f(n-1) + f(n-2) + ... + f(0) ②
613+
```
614+
615+
②-①:
616+
```
617+
f(n) - f(n-1) = f(n-1)
618+
f(n) = 2*f(n-1)
619+
```
620+
621+
所以 f(n) 是一个等比数列:
622+
```
623+
f(n) = 2^(n-1)
624+
```
625+
626+
```java
627+
public int JumpFloorII(int target) {
628+
return (int) Math.pow(2, target - 1);
629+
}
630+
```
601631

602632
# 11. 旋转数组的最小数字
603633

0 commit comments

Comments
 (0)