标签:
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.
Best Time to Buy and Sell Stock II
标签:
原文地址:http://www.cnblogs.com/jinagyuanhk/p/4194901.html