mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-10-26 21:13:43 +00:00
Update 10.4 变态跳台阶.md
代码块语言 source-java 改为 java,公式代码块标注语言。
This commit is contained in:
+5
-5
@@ -29,31 +29,31 @@ public int jumpFloorII(int target) {
|
||||
|
||||
跳上 n-1 级台阶,可以从 n-2 级跳 1 级上去,也可以从 n-3 级跳 2 级上去...,那么
|
||||
|
||||
```
|
||||
```text
|
||||
f(n-1) = f(n-2) + f(n-3) + ... + f(0)
|
||||
```
|
||||
|
||||
同样,跳上 n 级台阶,可以从 n-1 级跳 1 级上去,也可以从 n-2 级跳 2 级上去... ,那么
|
||||
|
||||
```
|
||||
```text
|
||||
f(n) = f(n-1) + f(n-2) + ... + f(0)
|
||||
```
|
||||
|
||||
综上可得
|
||||
|
||||
```
|
||||
```text
|
||||
f(n) - f(n-1) = f(n-1)
|
||||
```
|
||||
|
||||
即
|
||||
|
||||
```
|
||||
```text
|
||||
f(n) = 2*f(n-1)
|
||||
```
|
||||
|
||||
所以 f(n) 是一个等比数列
|
||||
|
||||
```source-java
|
||||
```java
|
||||
public int JumpFloorII(int target) {
|
||||
return (int) Math.pow(2, target - 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user