Skip to content

docs(notes): update coding-interview 10.4 #496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -232,6 +232,10 @@ Power by [logomakr](https://logomakr.com/).
<a href="https://github.com/mafulong">
​ <img src="https://avatars1.githubusercontent.com/u/24795000?s=400&v=4" width="50px">
</a>
<a href="https://github.com/yanglbme">
​ <img src="https://avatars1.githubusercontent.com/u/21008209?s=400&v=4" width="50px">
</a>


#### License

30 changes: 30 additions & 0 deletions notes/剑指 offer 题解.md
Original file line number Diff line number Diff line change
@@ -587,6 +587,8 @@ public int RectCover(int n) {

## 解题思路

### 动态规划

```java
public int JumpFloorII(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. 旋转数组的最小数字