给定一个向量,该向量表示一只股票在第i天的价格,y要使得股票收益最大就应该在第i天买入,第i+n天卖出,求最大收益的值是多少 思路:用一个变量记录最小值,一个变量记录最大收益,从头到尾扫描一次价格,当扫描到第i天的价格时,如果这个价格比最小值小,则替换,如果比最小值大,则计算此刻的收益是否大于最大收...
分类:
其他好文 时间:
2015-04-07 23:03:23
阅读次数:
214
问题一 Best Time to Buy and Sell Stock
Say you have an array for which the ith element is the price of a given stock on day i.
If you were only permitted to complete at most one transaction (ie, buy on...
分类:
其他好文 时间:
2014-11-30 23:19:36
阅读次数:
232