File tree 2 files changed +34
-0
lines changed
2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -232,6 +232,10 @@ Power by [logomakr](https://logomakr.com/).
232
232
<a href =" https://github.com/mafulong " >
233
233
<img src =" https://avatars1.githubusercontent.com/u/24795000?s=400&v=4 " width =" 50px " >
234
234
</a >
235
+ <a href =" https://github.com/yanglbme " >
236
+ <img src =" https://avatars1.githubusercontent.com/u/21008209?s=400&v=4 " width =" 50px " >
237
+ </a >
238
+
235
239
236
240
#### License
237
241
Original file line number Diff line number Diff line change @@ -587,6 +587,8 @@ public int RectCover(int n) {
587
587
588
588
## 解题思路
589
589
590
+ ### 动态规划
591
+
590
592
``` java
591
593
public int JumpFloorII(int target) {
592
594
int [] dp = new int [target];
@@ -598,6 +600,34 @@ public int JumpFloorII(int target) {
598
600
}
599
601
```
600
602
603
+ ### 数学式子推导
604
+
605
+ 跳上 n-1 级台阶,可以从 n-2 级跳 1 级上去,也可以从 n-3 级跳 2 级上去...也可以从 0 级跳上去。那么
606
+ ```
607
+ f(n-1) = f(n-2) + f(n-3) + ... + f(0) ①
608
+ ```
609
+
610
+ 同样,跳上 n 级台阶,可以从 n-1 级跳 1 级上去,也可以从 n-2 级跳 2 级上去...也可以从 0 级跳上去。那么
611
+ ```
612
+ f(n) = f(n-1) + f(n-2) + ... + f(0) ②
613
+ ```
614
+
615
+ ②-①:
616
+ ```
617
+ f(n) - f(n-1) = f(n-1)
618
+ f(n) = 2*f(n-1)
619
+ ```
620
+
621
+ 所以 f(n) 是一个等比数列:
622
+ ```
623
+ f(n) = 2^(n-1)
624
+ ```
625
+
626
+ ``` java
627
+ public int JumpFloorII(int target) {
628
+ return (int ) Math . pow(2 , target - 1 );
629
+ }
630
+ ```
601
631
602
632
# 11. 旋转数组的最小数字
603
633
You can’t perform that action at this time.
0 commit comments