最长连续递增
来源:互联网 发布:最流行的网络歌曲2017 编辑:程序博客网 时间:2024/05/21 06:55
class Solution {
public:
int maxProfit(vector<int> &prices) {
int n = prices.size() ;
int start = 0,end = 0 ;
int profit = 0 ;
int maxProfit = 0 ;
int minStart = 0 ;
if(prices.size() <= 1)
return 0;
if(prices[0] <= prices[1])
{
start = 0 ; end =1;
maxProfit = prices[1] - prices[0];
}
else
{
start = 1;end = 1;
}
while (start <= n-2)
{
while (end <= n-1 && prices[end]>= prices[end-1])
{
profit += prices[end]- prices[end-1];
end++ ;
}
if(profit > maxProfit){
minStart = start ;
maxProfit = profit ;
profit = 0 ;
}
while(end <= n-1 && prices[end] <= prices[end-1])
{
end ++ ;
}
start = end - 1;
}
return maxProfit;
}
};
0 0
- 最长连续递增
- 最长连续递增子序列
- 最长连续递增子序列
- 最长连续递增子序列
- 最长连续递增子序列
- 最长连续递增子序列
- 最长连续递增子序列
- 最长单调"连续"递增子序列
- 求最长连续递增子序列长度
- 单调递增连续最长子序列
- 最长递增子序列(非连续)
- 5-2 最长连续递增子序列
- 求最长连续递增公共子序列
- PTA 最长连续递增子序列
- 矩阵中最长连续递增子序列
- 习题3.4 最长连续递增子序列
- 用二分法寻找最长连续单调递增子序列
- hdu 3308 LCIS(线段树 最长连续递增)
- 【java语言】 编写应用程序,将给定字符串中的字符大写改小写,小写改大写。
- Android string 格式化
- Android菜鸟在成长-进度处理对话框:ProgressDialog水平进度条
- 雅虎网站页面性能优化的34条黄金守则
- Oracle分区-提高效率
- 最长连续递增
- 当ViewPager嵌套在ScrollView/ListView里时,手势冲突如何处理?
- ce.bib and Reginit.ini时怎么生成的——转载
- 每个程序员都必读的10篇文章
- Java笔记 (7.1)
- java进程内存占用超过xmx设置的问题
- linux查看日志常用命令
- 金额框(输入框限制)
- 学习linux内核能做什么?