Merge pull request #88 from LiangDazhu/master

添加 0122.买卖股票的最佳时机II 0055.跳跃游戏 python版本
This commit is contained in:
Carl Sun
2021-05-14 09:49:41 +08:00
committed by GitHub
2 changed files with 21 additions and 2 deletions

View File

@ -107,7 +107,19 @@ class Solution {
```
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

View File

@ -154,7 +154,14 @@ class Solution {
```
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