python
class Solution:
def maxProfit(self, prices: List[int]) -> int:
profix = 0
for i in range(1, len(prices)):
diff = prices[i] - prices[i - 1]
if diff > 0:
profix += diff
return profix
python
class Solution:
def canJump(self, nums: List[int]) -> bool:
farthest = 0
n = len(nums)
for i in range(n):
if i > farthest:
return False
farthest = max(farthest, i + nums[i])
if farthest >= n - 1:
return True
return False
python
class Solution:
def jump(self, nums: List[int]) -> int:
step = 0
n = len(nums)
if n == 1:
return 0
end = 0
farthest = 0
for i in range(n):
farthest = max(farthest, i + nums[i])
if i == end:
# 跳到最远的距离,此时需要再跳一次
step += 1
end = farthest
if end >= n - 1:
break
return step