LeetCode122 买卖股票的最佳时机 II(贪心)
贪心计算爬峰收益
class Solution:
def maxProfit(self, prices: List[int]) -> int:
ans, l = 0, len(prices)
for i in range(1, l): ans += max(0, prices[i] - prices[i - 1])
return ans
贪心计算爬峰收益
class Solution:
def maxProfit(self, prices: List[int]) -> int:
ans, l = 0, len(prices)
for i in range(1, l): ans += max(0, prices[i] - prices[i - 1])
return ans