摘要:
!由于题意是两次交易,而且这两次买卖不能再时间上重叠,是两个独立的问题,联想到分而治之的策略,将{0,1,...,i,...,n-1,n}的问题拆分为求{0,1,..,i}和{i+1,...,n-1,n}两个子问题,而这两个子问题又刚好是Best Time to Buy and Sell Stock I的解题思路。 1 int maxProfit(vector &prices) { 2 // IMPORTANT: Please reset any member data you declared, as 3 // the same Solution instan... 阅读全文
摘要:
符号 含义 !解题思路=感悟#犯错 阅读全文
摘要:
1 int maxProfit(vector &prices) { 2 // IMPORTANT: Please reset any member data you declared, as 3 // the same Solution instance will be reused for each test case. 4 int i; 5 int res=0; 6 if(prices.size() prices[i-1])13 res+=(prices[i]-prices[... 阅读全文