买卖股票的最佳时机 II
程序员文章站
2022-06-17 19:46:46
...
Python
class Solution(object):
def maxProfit(self, prices):
"""
:type prices: List[int]
:rtype: int
"""
ans = 0
for i in range(1, len(prices)):
price = - prices[i-1] + prices[i]
if price > 0:
ans += price
return ans