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 profit. You may complete at most two transactions.
Note:
You may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).
算法思想:
dp1[i]存儲前i個元素的最長連續子序列和;
dp2[i]存儲i至n-1元素的最長連續子序列和
那麼最後答案為max{dp1[i],dp2[i]},0<=iclass Solution{
public:
int maxProfit(vector