[leetcode]Best Time to Buy and Sell Stock
来源:互联网 发布:捷速扫描文字识别软件 编辑:程序博客网 时间:2024/06/05 02:44
class Solution {
public:
int maxProfit(vector<int> &prices) {
// Note: The Solution object is instantiated only once and is reused by each test case.
int min_price = INT_MAX;
int res = 0;
for (size_t i = 0; i < prices.size(); i++) {
min_price = min(min_price, prices[i]);
res = max(res, prices[i] - min_price);
}
return res;
}
};
public:
int maxProfit(vector<int> &prices) {
// Note: The Solution object is instantiated only once and is reused by each test case.
int min_price = INT_MAX;
int res = 0;
for (size_t i = 0; i < prices.size(); i++) {
min_price = min(min_price, prices[i]);
res = max(res, prices[i] - min_price);
}
return res;
}
};
- 【LeetCode】Best Time to Buy and Sell Stock & Best Time to Buy and Sell Stock
- [LeetCode] [LeetCode]Best Time to Buy and Sell Stock
- 【LeetCode with Python】 Best Time to Buy and Sell Stock
- [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 III
- Leetcode: Best time to buy and sell a stock I
- 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 III
- LeetCode : Best Time to Buy and Sell Stock II
- [leetcode] Best Time to Buy and Sell Stock
- leetcode 16: Best Time to Buy and Sell Stock III
- LeetCode Best Time to Buy and Sell Stock
- 使用PXE+DHCP+Apache+Kickstart无人值守安装CentOS5.8 x86_64
- eclipse修改字体
- differences between dp , sp, px, pt
- tomcat下配置https环境
- Dijkstra 证明
- [leetcode]Best Time to Buy and Sell Stock
- oracle中高水位(HWM)的问题
- 十进制转换为十六进制
- [leetcode]Best Time to Buy and Sell Stock II
- 9 STL算法
- Ubuntu sudo 免密码之 sudoers 修改
- 不借助库函数 字符串逆转
- 【源码】java中图片和Base64互相转换源码
- POJ2965 The Pilots Brothers' refrigerator(枚举)