首页 > 其他 > 详细

Best Time to Buy and Sell Stock II

时间:2014-12-31 06:13:08      阅读:257      评论:0      收藏:0      [点我收藏+]

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!