题目要求:

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

总思路:

在数组中找一个适当的点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. MVC Model Binder 规则

    http://www.cnblogs.com/mszhangxuefei/archive/2012/05/15/mvcnotes_30.html 使用默认的Model Binder(Using the ...

  2. [ZETCODE]wxWidgets教程五:布局管理

    本教程原文链接:http://zetcode.com/gui/wxwidgets/layoutmanagement/ 翻译:瓶哥 日期:2013年12月4日星期三 邮箱:414236069@qq.co ...

  3. 关于ASSERT(断言)的作用

    程序一般分为Debug 版本和Release 版本,Debug 版本用于内部调试,Release 版本发行给用户使用.断言assert 是仅在Debug 版本起作用的宏,它用于检查“不应该”发生的情况 ...

  4. Android——Cocosd2d-x手机游戏开发学习思路

    手机APP应用如雨后春笋般冒了出来,而在众多的APP应用中,游戏占据了半壁江山.它丰富着人们的业余生活,增进了人们之间的沟通交流.也有许多开发的朋友对游戏开发情有独钟,他们不止是享受着有很多的人们去下 ...

  5. Morris Traversal 二叉树遍历。

    那天做了个SWAP NODE的题,要求constant space,不得不Morris Traversal. 稍微研究了一下,真正意义上的O(1)space对二叉树进行遍历.好像是1979年的算法. ...

  6. Oracle数据库中将一个数据库中一张表的数据导入到另外一张表

    INSERT INTO DBTHNEW.L_MEMBER_ROLE_REL SELECT    *FROM    DBTH.L_MEMBER_ROLE_REL

  7. Ajax页面跳转

    <script type="text/javascript" >    $(document).ready(function () {            $(&qu ...

  8. selenuim +python环境配置遇到的诸多问题

    自动化测试入门,总结一下安装selenium.python以及配置webdriver遇到的问题: 准备工作: 1.下载火狐浏览器并安装插件selenium IDE.Firebug~~ 2.下载安装py ...

  9. (转) html块级元素和内联元素区别详解

    http://blog.csdn.net/chen_zw/article/details/8713205 块级元素(block)特性: 总是独占一行,表现为另起一行开始,而且其后的元素也必须另起一行显 ...

  10. 06 MDB将数据和dataGridView1绑定

    附件:http://files.cnblogs.com/xe2011/dataGridView1_bindingNavigator1_bindingSource1.rar 实现功能 对.MDB文件进行 ...