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
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!