【LeetCode 面试经典150题】123. Best Time to Buy and Sell Stock III 买卖股票的最佳时机 III

123. Best Time to Buy and Sell Stock III(买卖股票的最佳时机 III)

题目大意

You are given an array prices where prices[i] is the price of a given stock on the ith day.

Find the maximum profit you can achieve. You may complete at most two transactions.

Note: You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).

中文释义

给定一个数组 prices,其中 prices[i] 是第 i 天给定股票的价格。

找出你能获得的最大利润。你最多可以完成两笔交易。

注意:你不能同时进行多笔交易(即,你必须在再次购买前出售股票)。

示例

  • 示例 1:
    • 输入:prices = [3,3,5,0,0,3,1,4]
    • 输出:6
    • 解释:第 4 天买入(价格 = 0)并在第 6 天卖出(价格 = 3),利润 = 3-0 = 3。
      然后在第 7 天买入(价格 = 1)并在第 8 天卖出(价格 = 4),利润 = 4-1 = 3。
  • 示例 2:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值