首页
题库
面试
求职
学习
竞赛
More+
所有博客
搜索面经/职位/试题/公司
搜索
我要招人
去企业版
登录 / 注册
首页
>
试题广场
>
买卖股票的最好时机 iii
[编程题]买卖股票的最好时机 iii
热度指数:18904
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32M,其他语言64M
算法知识视频讲解
假设你有一个数组,其中第i个元素是某只股票在第i天的价格。
设计一个算法来求最大的利润。你最多可以进行两次交易。
注意:
你不能同时进行多个交易(即,你必须在再次购买之前出售之前买的股票)。
示例1
输入
[1,4,2]
输出
3
示例2
输入
[2,4,1]
输出
2
马上挑战
算法知识视频讲解
提交运行
算法知识视频讲解
添加笔记
求解答(18)
邀请回答
收藏(185)
分享
提交结果有问题?
0个回答
1篇题解
添加回答
这道题你会答吗?花几分钟告诉大家答案吧!
提交观点
问题信息
数组
难度:
0条回答
185收藏
30756浏览
热门推荐
通过挑战的用户
查看代码
阿阿
2022-09-14 14:26:44
牛客38441...
2022-09-13 20:32:06
牛客58603...
2022-09-09 20:46:01
说我这儿没问题...
2022-09-08 12:02:09
牛客68124...
2022-09-03 20:41:13
相关试题
あなたの蛙が帰っています
卡特兰数
评论
(1)
如果消费者收入增加引起野营设备需求...
经济学
评论
(1)
已知随机变量X∼B(1,0.2),...
概率论与数理统计
评论
(1)
来自
2024年秋招-蚂蚁集团...
下列字符串匹配算法中,( )是借助...
哈希
评论
(1)
大型语言模型的训练中,缩放定律(S...
大模型概念
评论
(1)
买卖股票的最好时机 iii
扫描二维码,关注牛客网
意见反馈
下载牛客APP,随时随地刷题
import java.util.*; public class Solution { /** * * @param prices int整型一维数组 * @return int整型 */ public int maxProfit (int[] prices) { // write code here } }
class Solution { public: /** * * @param prices int整型vector * @return int整型 */ int maxProfit(vector
& prices) { // write code here } };
# # # @param prices int整型一维数组 # @return int整型 # class Solution: def maxProfit(self , prices ): # write code here
/** * * @param prices int整型一维数组 * @return int整型 */ function maxProfit( prices ) { // write code here } module.exports = { maxProfit : maxProfit };
# # # @param prices int整型一维数组 # @return int整型 # class Solution: def maxProfit(self , prices ): # write code here
package main /** * * @param prices int整型一维数组 * @return int整型 */ func maxProfit( prices []int ) int { // write code here }
[1,4,2]
3
[2,4,1]
2