Best Time to Buy and Sell Stock II
时间:2014-12-31 06:13:08
收藏:0
阅读:257
Algorithm:
Scan through the array, keep finding
1. prices[i] with the condition: prices[i] < prices[i+1] or at the end of a descending trend, treat it as buying point
2. prices[i] with the condition: prices[i] > prices[i+1], or at the end of an ascending trend, treat it as selling point
keeping till reach the end of the array;
Note:
1. if a buying point is recorded and not reach the end, then must exist a selling point after it ( must exist some point larger than buying point)
2. if reach the end when finding the buying point, then stop and finish the whole programe.
原文:http://www.cnblogs.com/jinagyuanhk/p/4194901.html
评论(0)