题目要求:

最多交易两次,并且只能买卖完之后再买。

总思路:

在数组中找一个适当的点i,使得i左右两边profit之和最大。

思路:

1、从左往右扫描,left[i]记录包括i元素以内的左部的maxprofit,用Best Time to Buy and Sell Stock 1可得到。

2、从右往左扫描,right[i]记录i+1到尾部元素的maxprofit,将上面的low改成big即可

3、返回max(left[i],right[i])

注意:

1、考虑好,包括i与不包括i的情况

2、考虑好头尾,left[0]肯定是0,right[n-1]和right[n-2]也是0

Best Time to Buy and Sell Stock III 解题思路的更多相关文章

  1. LeetCode: Best Time to Buy and Sell Stock III 解题报告

    Best Time to Buy and Sell Stock IIIQuestion SolutionSay you have an array for which the ith element ...

  2. 【LeetCode】123. Best Time to Buy and Sell Stock III 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  3. 27. Best Time to Buy and Sell Stock && Best Time to Buy and Sell Stock II && Best Time to Buy and Sell Stock III

    Best Time to Buy and Sell Stock (onlineJudge: https://oj.leetcode.com/problems/best-time-to-buy-and- ...

  4. LeetCode 笔记23 Best Time to Buy and Sell Stock III

    Best Time to Buy and Sell Stock III Say you have an array for which the ith element is the price of ...

  5. Best Time to Buy and Sell Stock | & || & III

    Best Time to Buy and Sell Stock I Say you have an array for which the ith element is the price of a ...

  6. 【leetcode】Best Time to Buy and Sell Stock III

    Best Time to Buy and Sell Stock III Say you have an array for which the ith element is the price of ...

  7. LeerCode 123 Best Time to Buy and Sell Stock III之O(n)解法

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  8. 【leetcode】123. Best Time to Buy and Sell Stock III

    @requires_authorization @author johnsondu @create_time 2015.7.22 19:04 @url [Best Time to Buy and Se ...

  9. [leetcode]123. Best Time to Buy and Sell Stock III 最佳炒股时机之三

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

随机推荐

  1. Hadoop之hive安装过程以及运行常见问题

    Hive简介 1.数据仓库工具 2.支持一种与Sql类似的语言HiveQL 3.可以看成是从Sql到MapReduce的映射器 4.提供shall.Jdbc/odbc.Thrift.Web等接口 Hi ...

  2. PHP配置图文教程

    组合解释:lamp,其英文译为灯,可以方便记忆.其实每个字母代表的是一个英文缩写.l-->Linux,a-->Apache,m-->MySql,p-->PHP 由于以上资源都是 ...

  3. Java Stream 使用详解

    Stream是 Java 8新增加的类,用来补充集合类. Stream代表数据流,流中的数据元素的数量可能是有限的,也可能是无限的. Stream和其它集合类的区别在于:其它集合类主要关注与有限数量的 ...

  4. Lottery - CodeForces 589I(水)

    题目大意:有N个球K个人,现在要给这N个球涂上K种颜色,要求使抽到球的不同颜色的概率一致(N确保是K的倍数),求出来至少要给多少个球重新涂上颜色. 分析:先求出来所有球的每种颜色的个数,然后不到平均数 ...

  5. POJ 3125 Printer Queue

    题目: Description The only printer in the computer science students' union is experiencing an extremel ...

  6. MongoDB 复制集 (三) 内部数据同步

    一 数据同步        一个健康的secondary在运行时,会选择一个离自己最近的,数据比自己新的节点进行数据同步.选定节点后,它会从这个节点拉取oplog同步日志,具体流程是这样的:      ...

  7. 如何把select出来的一列数据放在第一个单元格

    有如下表: STORE_ID |  CUSTOMER_ID S001       |      C001 S001       |      C002 能不能把上表SELECT出来变成下面这种形式: ...

  8. Java-工厂设计模式

    引言: 工厂设计模式分为三种: 简单工厂 工厂方法 抽象工厂 联想四种情况 (1).还没有工厂时代:假如还没有工业革命,如果一个客户要一件产品,一般的做法是客户去创建一件产品,然后拿来用. (2).简 ...

  9. 记录IOS入门的过程

    先说点私话.再进入正题吧,顺便抒发下情绪.公司传统业务不景气,而互联网正如火如荼,无奈被逼上梁山.開始学起了IOS编程.后来想想闲着也是闲着就学习学习呗.无奈公司确实不希望投入了.不愿意提供苹果电脑. ...

  10. 再次轻度破解EXE文件

    在经历股市多年的大起大落.大赚大赔之后.痛定思痛.深切感到在金融市场拼搏.必须建立健全交易纪律守则,严格运行. 这套完整的纪律守则,就是"交易系统". 在很多方面,它与一般的专家系 ...