Best Time to Buy and Sell Stock III
来源:互联网 发布:淘宝客云建站怎么样 编辑:程序博客网 时间:2024/06/05 13:34
class Solution {public: int maxProfit(vector<int> &prices) { if(prices.size()<=1) return 0; int left[prices.size()]; int minp=prices[0]; left[0]=0; for(int i=1;i<prices.size();i++) { minp=min(minp,prices[i]); left[i]=max(left[i-1],prices[i]-minp); } int maxp=prices[prices.size()-1]; int maxprofit=0; for(int i=prices.size()-2;i>=0;i--) { maxp=max(maxp,prices[i]); maxprofit=max(maxprofit,left[i]+maxp-prices[i]); } return maxprofit; }};
0 0
- LeetCode Best Time to Buy and Sell Stock III
- LeetCode Best Time to Buy and Sell Stock III
- [Leetcode] Best Time to Buy and Sell Stock III
- leetcode 16: Best Time to Buy and Sell Stock III
- LeetCode Best Time to Buy and Sell Stock III
- Best Time to Buy and Sell Stock III
- Best Time to Buy and Sell Stock III
- [LeetCode] Best Time to Buy and Sell Stock III
- leetcode 62: Best Time to Buy and Sell Stock III
- [LeetCode] Best Time to Buy and Sell Stock III
- Best Time to Buy and Sell Stock III
- 【leetcode】Best Time to Buy and Sell Stock III
- Best Time to Buy and Sell Stock III
- LeetCode - Best Time to Buy and Sell Stock III
- Best Time to Buy and Sell Stock III
- Best Time to Buy and Sell Stock III
- LeetCode之Best Time to Buy and Sell Stock III
- [LeetCode]Best Time to Buy and Sell Stock III
- 如何使用开源的Android组件
- 搜狗诗词
- Servlet生命周期详解
- LA3713--Astronauts(2-sat)
- Java虚拟机(JVM)内存参数调优
- Best Time to Buy and Sell Stock III
- 杭电1302 The Snail
- JVM内存参数详解以及配置调优
- 如何在cocos2d 游戏中添加 移动广告
- 逆波兰实现计算器
- tomcat内存设置及jvm参数调优
- IO流的概念与使用
- Android改变监听端口
- AsynkTask结合线程池的使用