auto commit
This commit is contained in:
parent
2967bdb192
commit
5e0c5ef1f0
@ -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) - f(n-1) = f(n-1)
|
||||||
|
```
|
||||||
|
|
||||||
|
即
|
||||||
|
|
||||||
|
```
|
||||||
f(n) = 2*f(n-1)
|
f(n) = 2*f(n-1)
|
||||||
```
|
```
|
||||||
|
|
||||||
所以 f(n) 是一个等比数列:
|
所以 f(n) 是一个等比数列
|
||||||
```
|
|
||||||
f(n) = 2^(n-1)
|
|
||||||
```
|
|
||||||
|
|
||||||
```java
|
```source-java
|
||||||
public int JumpFloorII(int target) {
|
public int JumpFloorII(int target) {
|
||||||
return (int) Math.pow(2, target - 1);
|
return (int) Math.pow(2, target - 1);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
# 11. 旋转数组的最小数字
|
# 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)
|
[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)
|
||||||
|
@ -1477,7 +1477,7 @@ public class Client {
|
|||||||
|
|
||||||
```java
|
```java
|
||||||
public interface Subject {
|
public interface Subject {
|
||||||
void resisterObserver(Observer o);
|
void registerObserver(Observer o);
|
||||||
|
|
||||||
void removeObserver(Observer o);
|
void removeObserver(Observer o);
|
||||||
|
|
||||||
@ -1504,7 +1504,7 @@ public class WeatherData implements Subject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resisterObserver(Observer o) {
|
public void registerObserver(Observer o) {
|
||||||
observers.add(o);
|
observers.add(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1535,7 +1535,7 @@ public interface Observer {
|
|||||||
public class StatisticsDisplay implements Observer {
|
public class StatisticsDisplay implements Observer {
|
||||||
|
|
||||||
public StatisticsDisplay(Subject weatherData) {
|
public StatisticsDisplay(Subject weatherData) {
|
||||||
weatherData.resisterObserver(this);
|
weatherData.reisterObserver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1549,7 +1549,7 @@ public class StatisticsDisplay implements Observer {
|
|||||||
public class CurrentConditionsDisplay implements Observer {
|
public class CurrentConditionsDisplay implements Observer {
|
||||||
|
|
||||||
public CurrentConditionsDisplay(Subject weatherData) {
|
public CurrentConditionsDisplay(Subject weatherData) {
|
||||||
weatherData.resisterObserver(this);
|
weatherData.registerObserver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -2558,9 +2558,9 @@ public class Client {
|
|||||||
remoteControl1.off();
|
remoteControl1.off();
|
||||||
remoteControl1.tuneChannel();
|
remoteControl1.tuneChannel();
|
||||||
RemoteControl remoteControl2 = new ConcreteRemoteControl2(new Sony());
|
RemoteControl remoteControl2 = new ConcreteRemoteControl2(new Sony());
|
||||||
remoteControl2.on();
|
remoteControl2.on();
|
||||||
remoteControl2.off();
|
remoteControl2.off();
|
||||||
remoteControl2.tuneChannel();
|
remoteControl2.tuneChannel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user