LeetCode_best-time-to-buy-and-sell-stock
2015-09-15 19:55
375 查看
https://leetcode.com/problems/best-time-to-buy-and-sell-stock/
class Solution { public: int maxProfit(vector<int>& prices) { int len = prices.size(); if(len == 0) return 0; int profit = 0,low = prices[0];//low记录当前最小的股价 for(int i = 1;i < len;i++){ if(prices[i] < low)//一旦发现更小的股价,更新 low = prices[i]; else if(prices[i] - low > profit) profit = prices[i] - low; } return profit; } };
相关文章推荐
- iOS程序启动的完整过程
- 植物大战僵尸无限版轮数地址
- HTML 标题、水平线、注释、查看网页源码
- javascript中的function
- Python简明教程---学习笔记
- HDOJ 2609How many
- JSP第一次运行tomcat7.0的404错误
- 跟马哥学linux (lesson 7)Bash脚本基础知识
- MongoDB学习日记 - java代码(二):建立连接
- hdu1018(求n!的位数)
- SQL学习记录
- SoundPool提示音铃声
- Linux 下的yum的配置
- OC - NSString
- Serializable序列化与session
- 获得桌面图标所在窗口--兼容Win7
- Android程序启动画面之Splash
- jsp的九大内置对象
- [BT_Books]《低功耗蓝牙开发权威指南》笔记(待续)
- AFNetworking 使用指南