auto commit

This commit is contained in:
CyC2018 2018-12-16 22:12:44 +08:00
parent 2967bdb192
commit 5e0c5ef1f0
2 changed files with 24 additions and 18 deletions

View File

@ -600,35 +600,41 @@ public int JumpFloorII(int target) {
}
```
### 数学式子推导
### 数学推导
跳上 n-1 级台阶,可以从 n-2 级跳 1 级上去,也可以从 n-3 级跳 2 级上去...,那么
跳上 n-1 级台阶,可以从 n-2 级跳 1 级上去,也可以从 n-3 级跳 2 级上去...也可以从 0 级跳上去。那么
```
f(n-1) = f(n-2) + f(n-3) + ... + f(0)
f(n-1) = f(n-2) + f(n-3) + ... + f(0)
```
同样,跳上 n 级台阶,可以从 n-1 级跳 1 级上去,也可以从 n-2 级跳 2 级上去...也可以从 0 级跳上去。那么
同样,跳上 n 级台阶,可以从 n-1 级跳 1 级上去,也可以从 n-2 级跳 2 级上去... ,那么
```
f(n) = f(n-1) + f(n-2) + ... + f(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)
```
所以 f(n) 是一个等比数列
```java
```source-java
public int JumpFloorII(int target) {
return (int) Math.pow(2, target - 1);
}
```
# 11. 旋转数组的最小数字
[NowCoder](https://www.nowcoder.com/practice/9f3231a991af4f55b95579b44b7a01ba?tpId=13&tqId=11159&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking)

View File

@ -1477,7 +1477,7 @@ public class Client {
```java
public interface Subject {
void resisterObserver(Observer o);
void registerObserver(Observer o);
void removeObserver(Observer o);
@ -1504,7 +1504,7 @@ public class WeatherData implements Subject {
}
@Override
public void resisterObserver(Observer o) {
public void registerObserver(Observer o) {
observers.add(o);
}
@ -1535,7 +1535,7 @@ public interface Observer {
public class StatisticsDisplay implements Observer {
public StatisticsDisplay(Subject weatherData) {
weatherData.resisterObserver(this);
weatherData.reisterObserver(this);
}
@Override
@ -1549,7 +1549,7 @@ public class StatisticsDisplay implements Observer {
public class CurrentConditionsDisplay implements Observer {
public CurrentConditionsDisplay(Subject weatherData) {
weatherData.resisterObserver(this);
weatherData.registerObserver(this);
}
@Override
@ -2558,9 +2558,9 @@ public class Client {
remoteControl1.off();
remoteControl1.tuneChannel();
RemoteControl remoteControl2 = new ConcreteRemoteControl2(new Sony());
remoteControl2.on();
remoteControl2.off();
remoteControl2.tuneChannel();
remoteControl2.on();
remoteControl2.off();
remoteControl2.tuneChannel();
}
}
```