LeetCode之Best Time to Buy and Sell Stock
来源:互联网 发布:行程路线图制作软件 编辑:程序博客网 时间:2024/06/10 09:00
/*只能做一次交易。则对于在某天卖出的股票,获得最大盈利值的方法为:在这天之前中,股票价格最低的那天买进股票。比较每天卖出的股票,即可获得最大盈利。*/class Solution {public: int maxProfit(vector<int>& prices) { if(prices.size() <= 1) return 0; int min_price(prices[0]), res(INT_MIN); for(int i = 1; i < prices.size(); ++i){ min_price = min(min_price, prices[i-1]); res = max(res, prices[i] - min_price); } return max(res, 0); }};
0 0
- LeetCode之Best Time to Buy and Sell Stock
- LeetCode之Best Time to Buy and Sell Stock II
- LeetCode之Best Time to Buy and Sell Stock III
- LeetCode 之 Best Time to Buy and Sell Stock
- LeetCode 之 Best Time to Buy and Sell Stock II
- LeetCode之Best Time to Buy and Sell Stock
- LeetCode之Best Time to Buy and Sell Stock II
- leetcode之Best Time to Buy and Sell Stock
- leetcode之Best Time to Buy and Sell Stock III
- leetcode之Best Time to Buy and Sell Stock
- leetcode之Best Time to Buy and Sell Stock II
- Leetcode之Best Time to Buy and Sell Stock
- leetcode 之 Best Time to Buy and Sell Stock
- LeetCode之Best Time to Buy and Sell Stock III
- LeetCode之Best Time to Buy and Sell Stock
- LeetCode之Best Time to Buy and Sell Stock II
- leetcode之Best Time to Buy and Sell Stock
- LeetCode 之 Best Time to Buy and Sell Stock II
- xml文件解析并显示到Android手机 spinner的应用
- 快速创建九宫格
- HDU 1702 ACboy needs your help again!(模拟 队列 栈)
- Hive函数row_number实现
- Hibernate自学详细笔记
- LeetCode之Best Time to Buy and Sell Stock
- 间隔300ms第一次一个管亮流动一次,第二次两个管亮流动。依次到8个管亮,然后重复此过程
- android传递数据方式2--通过剪切板传数据
- Javascript基础(一)
- 今天又看到了一篇关于程序运行时内存方面的文章,特地来分享一下。
- HDU DFS
- 初进hp感想和目标
- linux select 模型详解
- java常用设计模式