Merge pull request #88 from LiangDazhu/master
添加 0122.买卖股票的最佳时机II 0055.跳跃游戏 python版本
This commit is contained in:
commit
2bfd4ce68e
|
|
@ -107,7 +107,19 @@ class Solution {
|
||||||
```
|
```
|
||||||
|
|
||||||
Python:
|
Python:
|
||||||
|
```python
|
||||||
|
class Solution:
|
||||||
|
def canJump(self, nums: List[int]) -> bool:
|
||||||
|
cover = 0
|
||||||
|
if len(nums) == 1: return True
|
||||||
|
i = 0
|
||||||
|
# python不支持动态修改for循环中变量,使用while循环代替
|
||||||
|
while i <= cover:
|
||||||
|
cover = max(i + nums[i], cover)
|
||||||
|
if cover >= len(nums) - 1: return True
|
||||||
|
i += 1
|
||||||
|
return False
|
||||||
|
```
|
||||||
|
|
||||||
Go:
|
Go:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -154,7 +154,14 @@ class Solution {
|
||||||
```
|
```
|
||||||
|
|
||||||
Python:
|
Python:
|
||||||
|
```python
|
||||||
|
class Solution:
|
||||||
|
def maxProfit(self, prices: List[int]) -> int:
|
||||||
|
result = 0
|
||||||
|
for i in range(1, len(prices)):
|
||||||
|
result += max(prices[i] - prices[i - 1], 0)
|
||||||
|
return result
|
||||||
|
```
|
||||||
|
|
||||||
Go:
|
Go:
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue