LeetCode-Best Time to Buy and Sell Stock
来源:互联网 发布:ubuntu cp复制文件夹 编辑:程序博客网 时间:2024/06/05 19:03
class Solution {public: int maxProfit(vector<int> &prices) { // Start typing your C/C++ solution below // DO NOT write int main() function int maxPrft = 0; if (prices.size() > 1) { int maxRight = prices[prices.size() - 1]; maxPrft = max(0, maxRight - prices[0]); for (int i = prices.size() - 2; i > 0; --i) { if (prices[i] < prices[0]) maxPrft = max(maxPrft, maxRight - prices[i]); if (prices[i] > maxRight) { maxRight = prices[i]; maxPrft = max(maxPrft, maxRight - prices[0]); } } } return maxPrft; }};
- 【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
- ExcelApplication.WorkBook.SaveAs function
- VB中,叹号“!”和“.”的区别
- uva 10274 Fans and Gems(隐式图搜索+模拟)
- 最大值最小化--uva714
- iOS单例学习笔记整理
- LeetCode-Best Time to Buy and Sell Stock
- 解决缩略图模式下有些白色图片看不清的问题
- MemCache深入学习(二)
- swift开放一个容器供公共下载
- 我的书架
- 存储过程的创建
- AndroidManifest文件详解(uses-feature)
- 树相关
- 在ubuntn中apache配制虚拟目录域名