题目链接

题意: find the maximum positive difference between the price on the ith day and the jth day

附上代码:

 class Solution {
public:
int maxProfit(vector<int> &prices) {
if (prices.size() == )
return ;
// "minimum" holds the minimum price before the ith day.
// "max_diff" holds the maximum difference between prices[i] and prices[j]
// where 0 <= i < j < prices.size()
int minimum = prices[], max_diff = ;
for (unsigned int i = ; i < prices.size(); i++) {
if (prices[i] - minimum > max_diff) {
max_diff = prices[i] - minimum;
}
if (prices[i] < minimum) {
minimum = prices[i];
}
}
return max_diff;
}
};

最新文章

  1. DIV+CSS 图文混排的图片居中办法
  2. 处理handler中的内存泄漏
  3. D3(Data-Driven-Document)中的一些细节
  4. asp.net 自定义控件
  5. sql语句与 数据库
  6. SVN版本管理系统的安装 CentOS + Subversion + Apache + Jsvnadmin
  7. angular 模板 小例子
  8. JSP文件下载时文件名在ie和firefox下面文件名不一致极其超链接中文乱码的问题的改进
  9. [Papers]NSE, $\p_3u$, Lebesgue space [Penel-Pokorny, AM, 2004]
  10. JavaScript获取HTML页面源代码
  11. [Sequence Alignment Methods] Cross-Recurrent Plot (CRP)
  12. jquery1.9学习笔记 之选择器(基本元素四)
  13. C# 多线程 异步加载 窗体
  14. SVN配置文件详解
  15. android app 集成 支付宝支付 微信支付
  16. FB面经 Prepare: All Palindromic Substrings
  17. python-map的用法
  18. jQuery 异步上传插件 Uploadify302 使用 (JavaEE Spring MVC)
  19. listview reclyerview上下拉刷新
  20. &lt;自动化测试方案_6&gt;第六章、API自动化测试

热门文章

  1. Django项目:CRM(客户关系管理系统)--59--49PerfectCRM实现CRM客户报名流程学生合同表单验证
  2. RuntimeError: You called this URL via POST, but the URL doesn’t end in a slash and you have APPEND_SLASH set.
  3. vue 路由(二级)配置及详细步骤
  4. PAT甲级——A1062 Talent and Virtue
  5. add-apt-repository ppa:&lt;ppa_name&gt;
  6. IDEA的下载安装
  7. css 始终显示滚动条,内容超出显示有滑块的滚动条,内容没有超出显示空的滚动条
  8. 2019-8-31-dotnet-如何调试某个文件是哪个代码创建
  9. mysql本地导入数据
  10. js的Date()时间对象