LeedCode --- Best Time to Buy and Sell Stock
2024-08-31 14:31:58
题意: 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;
}
};
最新文章
- DIV+CSS 图文混排的图片居中办法
- 处理handler中的内存泄漏
- D3(Data-Driven-Document)中的一些细节
- asp.net 自定义控件
- sql语句与 数据库
- SVN版本管理系统的安装 CentOS + Subversion + Apache + Jsvnadmin
- angular 模板 小例子
- JSP文件下载时文件名在ie和firefox下面文件名不一致极其超链接中文乱码的问题的改进
- [Papers]NSE, $\p_3u$, Lebesgue space [Penel-Pokorny, AM, 2004]
- JavaScript获取HTML页面源代码
- [Sequence Alignment Methods] Cross-Recurrent Plot (CRP)
- jquery1.9学习笔记 之选择器(基本元素四)
- C# 多线程 异步加载 窗体
- SVN配置文件详解
- android app 集成 支付宝支付 微信支付
- FB面经 Prepare: All Palindromic Substrings
- python-map的用法
- jQuery 异步上传插件 Uploadify302 使用 (JavaEE Spring MVC)
- listview reclyerview上下拉刷新
- <;自动化测试方案_6>;第六章、API自动化测试
热门文章
- Django项目:CRM(客户关系管理系统)--59--49PerfectCRM实现CRM客户报名流程学生合同表单验证
- RuntimeError: You called this URL via POST, but the URL doesn’t end in a slash and you have APPEND_SLASH set.
- vue 路由(二级)配置及详细步骤
- PAT甲级——A1062 Talent and Virtue
- add-apt-repository ppa:<;ppa_name>;
- IDEA的下载安装
- css 始终显示滚动条,内容超出显示有滑块的滚动条,内容没有超出显示空的滚动条
- 2019-8-31-dotnet-如何调试某个文件是哪个代码创建
- mysql本地导入数据
- js的Date()时间对象