121. Best Time to Buy and Sell Stock
来源:互联网 发布:西安广电网络营业厅 编辑:程序博客网 时间:2024/06/15 16:35
题目
题意
找到 max(nums[j] - nums[i]) , j > i && nums[j] > nums[i]
代码
class Solution {public: int maxProfit(vector<int>& prices) { if (prices.size() <= 1) return 0; int minp = prices[0], res = 0; for (int i = 1; i < prices.size(); i++) if (prices[i] > minp) res = max(res, prices[i]-minp); else minp = prices[i]; return res; }};
阅读全文
0 0
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time To Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- Best Time to Buy and Sell Stock
- vim的跨文件复制粘贴
- Spring Test 中重置自增字段
- 图片加载原理
- PHPExcel 读取Excel以xlsx格式的文件
- UVA 12657
- 121. Best Time to Buy and Sell Stock
- 北京师范大学第十四届ACM决赛- B Squared Permutation 三分
- Island Perimeter 经典解法
- BM服务器远程管理模块IMM接口IP设置
- JS中for 循环 与 for in 循环的区别
- Python 练习实例11
- try--catch--finally中return返回值执行的顺序
- getSimpleName,getCanonicalName和getName获取类名的区别
- CCF-训练50题-NO.24-个位数统计