best_time_buy_sell_stock_ii

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

best_time_buy_sell_stock_ii.go 源码

package main

// 买卖股票的最佳时机II

func maxProfit(prices []int) int {
	profit := 0
	for i := 1; i < len(prices); i++ {
		if prices[i] > prices[i-1] {
			profit += prices[i] - prices[i-1]
		}
	}
	return profit
}

你可能感兴趣的文章

best_time_buy_sell_stock

climb_stairs

container_with_most_water

0  赞