码迷,mamicode.com
首页 > 其他好文 > 详细

Best Time to Buy and Sell Stock II

时间:2014-12-31 06:16:24      阅读:159      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!