best_time_buy_sell_stock_ii

  • 2022-12-14
  • 浏览 (556)

best_time_buy_sell_stock_ii.py 源码

from typing import List


# 买卖股票的最佳时机II

class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        profit = 0
        for i in range(1, len(prices)):
            if prices[i] > prices[i - 1]:
                profit += prices[i] - prices[i - 1]
        return profit

你可能感兴趣的文章

best_time_buy_sell_stock

climb_statirs

container_with_most_water

0  赞