码迷,mamicode.com
首页 >  
搜索关键字:stock    ( 973个结果
LeedCode --- Best Time to Buy and Sell Stock
题目链接题意: find the maximum positive difference between the price on the ith day and the jth day附上代码: 1 class Solution { 2 public: 3 int maxProfit(ve...
分类:其他好文   时间:2014-05-28 03:49:45    阅读次数:307
【leetcode】Best Time to Buy and Sell Stock III
题目:这个题目里要求最多交易2次。也就是说可以只交易一次,不交易也可以。 分析:将整个交易序列分割成两部分,求出这样的一种分割,使得两部分连续子序列的和相加的结果最大,当然,如果不进行分割,就是求出整个序列的最大连续子序列的和。 那么分割点就可能是任意位置。找出取得最大值的分割点,返回最大值。 int maxProfit(vector &prices) { const int le...
分类:其他好文   时间:2014-05-24 20:54:57    阅读次数:402
【leetcode】Best Time to Buy and Sell Stock II
问题:股票交易,交易的次数不限,但是要求在购买新的股票前,必须将旧的股票卖出,即同一时间,最多只能持有一只股票。要求在给定的交易价格序列中,计算出最大的收益。 分析: 保证利润最大,就要求在局部的价格波动中,能在低价买进,高价卖出,也就是说,找个价格走势的递增区间,并且这里可以交易多次,所以可以找到多个价格走势的递增区间,所有区间的收益的和就是最大的利润。 再看下不完全是递增区间的...
分类:其他好文   时间:2014-05-24 19:49:02    阅读次数:349
Best Time to Buy and Sell Stock III
Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete a...
分类:其他好文   时间:2014-05-21 17:27:55    阅读次数:252
leetcode Best Time to Buy and Sell Stock III
思路:知道要用DP做,但是一开始思路是错的。后来参考了http://blog.csdn.net/pickless/article/details/12034365才意识到可以在整个区间的每一点切开,然后分别计算左子区间和右子区间的最大值,然后再用O(n)时间找到整个区间的最大值。看来以后碰到与2相关...
分类:其他好文   时间:2014-05-19 14:13:38    阅读次数:286
【leetcode】Best Time to Buy and Sell Stock
Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (ie...
分类:其他好文   时间:2014-05-18 20:30:16    阅读次数:301
Best Time to Buy and Sell Stock I && II && III
题目1: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,...
分类:其他好文   时间:2014-05-16 01:46:15    阅读次数:460
Leetcode:Best Time to Buy and Sell Stock
Best Time to Buy and Sell Stock1Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to comp...
分类:其他好文   时间:2014-05-14 22:36:11    阅读次数:353
Best Time to Buy and Sell Stock III
Total Accepted: 8400 Total Submissions: 38235 My Submissions Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profi...
分类:其他好文   时间:2014-05-14 19:39:53    阅读次数:275
Leetcode 贪心 Best Time to Buy and Sell StockII
本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie Best Time to Buy and Sell Stock II  Total Accepted: 13030 Total Submissions: 36467 Say you have an array for which the ith ...
分类:其他好文   时间:2014-05-13 14:08:39    阅读次数:414
973条   上一页 1 ... 94 95 96 97 98 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!