Problem Description: http://oj.leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/

Basic idea: from code below, it seems super easy. But intuitively, we may use one more variable "tmp_max_profit" to record every times we get the max profit.

 class Solution {
public:
int maxProfit(vector<int> &prices) {
// Note: The Solution object is instantiated only once and is reused by each test case.
int max_profit = ;
for(int i = ; i < prices.size(); i ++) {
if(i + >= prices.size())
break; if(prices[i + ] > prices[i])
max_profit += prices[i + ] - prices[i];
} return max_profit;
}
};

Best Time to Buy and Sell Stock II [LeetCode]的更多相关文章

  1. Best Time to Buy and Sell Stock II ——LeetCode

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

  2. Best Time to Buy and Sell Stock II leetcode java

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

  3. 122. Best Time to Buy and Sell Stock II ——LeetCode

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

  4. [LintCode] Best Time to Buy and Sell Stock II 买股票的最佳时间之二

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

  5. LEETCODE —— Best Time to Buy and Sell Stock II [贪心算法]

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

  6. 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- ...

  7. Leetcode-122 Best Time to Buy and Sell Stock II

    #122  Best Time to Buy and Sell Stock II Say you have an array for which the ith element is the pric ...

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

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

  9. 31. leetcode 122. Best Time to Buy and Sell Stock II

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

随机推荐

  1. C#无需IIS构建XmlRpc服务器

    准备 我们使用CookComputing.XmlRpcServerV2 3.0.0来构建XmlRpc服务器. 新建一个控制台项目,在项目中添加对CookComputing.XmlRpcServerV2 ...

  2. C# POST与Get数据

    引用DLL 普通Get数据和Post数据 public static string Get(string URL) { String ReCode = string.Empty; try { Http ...

  3. 基本的DMA控制器

    DMA的基本概念 直接内存访问(DMA)是一种完全由硬件执行I/O交换的工作方式.在这种方式中,DMA控制器从CPU完全接管对总线的控制,数据交换不经过CPU,而直接在内存和I/O设备之间进行 .DM ...

  4. [SAP ABAP开发技术总结]反射,动态创建内表、结构、变量

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  5. [SAP ABAP开发技术总结]Form(subroutine)、Function参数传值传址

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  6. SQL——存储过程实例 循环

    --循环 create or replace procedure p_xunhuan(input in number,output out number) is ); begin ; ..input ...

  7. Entity Framework 学习初级篇--基本操作:增加、更新、删除、事务(转)

    摘自:http://www.cnblogs.com/xray2005/archive/2009/05/17/1458568.html 本节,直接写通过代码来学习.这些基本操作都比较简单,与这些基本操作 ...

  8. Windows Internals学习笔记(一)概念与工具

    参考资料: 1. <Windows Internals> 2. Windows Drive Kit 3. Microsoft Windows SDK 4. WDK下载地址 知识点: 1. ...

  9. Java I/O 对象序列化

    我们知道对象的持持久化有三种方式: 1: 对象序列化 2: XML 3: 数据库技术 序列化可以帮助使得对象的生命周期不取决与程序是否正在执行,它可以生存于程序的调用之间. 只要将任何对象序列化到单一 ...

  10. read 计时命令

    使用read命令存在潜在危险,脚本很可能会停下来一直等待脚本用户输入数据,如果无论是否输入数据脚本的必须继续执行,那么可以使用-t选项指定一个计时器.-t选项指定read命令等待输入的秒数,当计数器计 ...