docs(notes): update coding-interview 10.4

《剑指 Offer》题解新增
项目文档路径简化
Addtional.md 资源新增
This commit is contained in:
yanglbme
2018-12-16 20:36:32 +08:00
parent f41a1dbcfb
commit b08ff2d8a1
3 changed files with 67 additions and 36 deletions

View File

@ -90,7 +90,7 @@
# 2. 实现 Singleton
[单例模式](https://github.com/CyC2018/Interview-Notebook/blob/master/notes/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F.md)
[单例模式](/notes/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F.md)
# 3. 数组中重复的数字
@ -558,7 +558,7 @@ public int JumpFloor(int n) {
## 题目描述
我们可以用 2\*1 的小矩形横着或者竖着去覆盖更大的矩形。请问用 n 个 2\*1 的小矩形无重叠地覆盖一个 2\*n 的大矩形,总共有多少种方法?
我们可以用 `2*1` 的小矩形横着或者竖着去覆盖更大的矩形。请问用 n 个 `2*1` 的小矩形无重叠地覆盖一个 `2*n` 的大矩形,总共有多少种方法?
## 解题思路
@ -598,6 +598,32 @@ public int JumpFloorII(int target) {
}
```
另一种方法是通过数学式子推导。
跳上 `n-1` 级台阶,可以从 `n-2` 级跳 `1` 级上去,也可以从 `n-3` 级跳 `2` 级上去...也可以从 `0` 级跳上去。那么
```
f(n-1) = f(0) + f(1) + ... + f(n-2) ①
```
跳上 `n` 级台阶,可以从 `n-1` 级跳 `1` 级上去,也可以从 `n-2` 级跳 `2` 级上去...也可以从 `0` 级跳上去。那么
```
f(n) = f(0) + f(1) + ... + f(n-2) + f(n-1) ②
②-①:
f(n) - f(n-1) = f(n-1)
f(n) = 2f(n-1)
```
所以 f(n) 是一个等比数列:
```
f(n) = 2^(n-1)
```
```java
public int JumpFloorII(int target) {
return (int) Math.pow(2, target - 1);
}
```
# 11. 旋转数组的最小数字