add #10.2 #10.3 #10.4 python implement
This commit is contained in:
parent
d173629829
commit
896127b035
@ -711,7 +711,17 @@ public int JumpFloor(int n) {
|
|||||||
```
|
```
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
# -*- coding:utf-8 -*-
|
||||||
|
class Solution:
|
||||||
|
def jumpFloor(self, number):
|
||||||
|
# write code here
|
||||||
|
if number == 0:
|
||||||
|
return number
|
||||||
|
pre1, pre2 = 1, 1
|
||||||
|
#result = 0
|
||||||
|
for i in range(number):
|
||||||
|
pre1, pre2 = pre2, pre1+pre2
|
||||||
|
return pre1
|
||||||
```
|
```
|
||||||
# 10.3 矩形覆盖
|
# 10.3 矩形覆盖
|
||||||
|
|
||||||
@ -739,7 +749,17 @@ public int RectCover(int n) {
|
|||||||
```
|
```
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
# -*- coding:utf-8 -*-
|
||||||
|
class Solution:
|
||||||
|
def rectCover(self, number):
|
||||||
|
# write code here
|
||||||
|
if number == 0:
|
||||||
|
return number
|
||||||
|
pre1, pre2 = 1, 1
|
||||||
|
#result = 0
|
||||||
|
for i in range(number):
|
||||||
|
pre1, pre2 = pre2, pre1+pre2
|
||||||
|
return pre1
|
||||||
```
|
```
|
||||||
# 10.4 变态跳台阶
|
# 10.4 变态跳台阶
|
||||||
|
|
||||||
@ -763,7 +783,13 @@ public int JumpFloorII(int target) {
|
|||||||
```
|
```
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
# -*- coding:utf-8 -*-
|
||||||
|
class Solution:
|
||||||
|
def jumpFloorII(self, number):
|
||||||
|
# write code here
|
||||||
|
if number <= 0:
|
||||||
|
return 0
|
||||||
|
return pow(2, number-1)
|
||||||
```
|
```
|
||||||
|
|
||||||
# 参考文献
|
# 参考文献
|
||||||
|
Loading…
x
Reference in New Issue
Block a user