LeetCode Best Time to Buy and Sell Stock II C 4ms
来源:互联网 发布:数据分析师笔试逻辑 编辑:程序博客网 时间:2024/06/06 09:40
int maxProfit(int* prices, int pricesSize) { int max=0,i=0,muturs=0,buy=0,sell=0; for(i;i<pricesSize-1;i++){ if(prices[i]<=prices[i+1]) { if(muturs&&sell) { max+=prices[i-sell]; sell=0; muturs=0; } if(!muturs) buy++; } else if(prices[i]>=prices[i+1]) { if(!muturs&&buy) { max-=prices[i-buy]; buy=0; muturs=1; } if(muturs) sell++; } } if(prices[i-1]<=prices[i]&&!muturs&&buy) { max-=prices[i-buy]; max+=prices[i]; } else if(prices[i-1]>=prices[i]&&muturs&&sell) max+=prices[i-sell]; return max;}
利用的同步机制原理设计改程序。
C语言4ms。
2016/1/31
0 0
- LeetCode Best Time to Buy and Sell Stock II C 4ms
- Best Time to Buy and Sell Stock II - LeetCode 4
- [LeetCode]Best Time to Buy and Sell Stock II
- LeetCode Best Time to Buy and Sell Stock II
- Leetcode: Best Time to Buy and Sell Stock II
- [Leetcode] Best Time to Buy and Sell Stock II
- LeetCode : Best Time to Buy and Sell Stock II
- LeetCode Best Time to Buy and Sell Stock II
- [LeetCode] Best Time to Buy and Sell Stock II
- leetcode 61: Best Time to Buy and Sell Stock II
- [LeetCode] Best time to buy and sell a stock II
- 【leetcode】Best Time to Buy and Sell Stock II
- LeetCode - Best Time to Buy and Sell Stock II
- LeetCode之Best Time to Buy and Sell Stock II
- [LeetCode]Best Time to Buy and Sell Stock II
- [Leetcode]Best Time to Buy and Sell Stock II
- [leetcode]Best Time to Buy and Sell Stock II
- [LeetCode] Best Time to Buy and Sell Stock II
- android TP(触摸屏)问题现象分析和解决方案汇总
- SQLite事务示例
- Linq to SQL 中datetime 和string转换
- android *** Layout 01
- hdoj 4411 Arrest 【费用流 + 最短路】
- LeetCode Best Time to Buy and Sell Stock II C 4ms
- leetcode系列(73)Insertion Sort List
- 王学岗Fragment(五)
- hdu 2544最短路(Dijkstra)
- 数据结构(寒假小结)--3.3串
- ajax与Jquery中的Ajax
- python 模块(module)基础讲解
- POJ 1062 昂贵的聘礼(dijkstra)
- svm