买卖股票的最佳时机 - C++
2024-10-19 22:35:56
class Solution {
public:
/**
* @param prices: Given an integer array
* @return: Maximum profit
*/
int maxProfit(vector<int> &price) {
int re = 0;
if(price.size()<2)
return re;
int lowest = price[0];
for(int i=1;i<price.size();i++)
{
int cur = price[i];
re = max(re,cur-lowest);
lowest = min(lowest,cur);
}
return re;
}
};
最新文章
- C++ 系列:设计模式研究
- [再寄小读者之数学篇](2014-11-26 广义 Schur 分解定理)
- hdu-4753-Fishhead’s Little Game-记忆化搜索
- BZOJ 2693 jzptab
- 学习sql基础注入的方法
- Activiti-06-.事件
- Jmeter+Ant+Jenkins接口自动化测试(一)_环境部署
- Linux系统 Cetos 7 中重置root密码
- Java_面向对象
- Python内置函数(21)——filter
- 20172328 2018-2019《Java软件结构与数据结构》第五周学习总结
- Effective Java 第三版——48. 谨慎使用流并行
- (转)Springboot邮件服务
- python 安装 Scrapy 模块
- servlet实现文件上传,预览,下载和删除
- 搭建iSCSI共享IPSAN
- get与post请求简单理解
- softmax回归(理论部分解释)
- Notes about Vue Style Guide
- virtio使用