Nolimittotransactioncount,soitisarecursivesumcalculation.Takecareofboundarycondition.class No limit to transaction count, so it is a recursive sum calculation. Take care of boundary condition. class Solution {public: int maxProfit(vector if
No limit to transaction count, so it is a recursive sum calculation. Take care of boundary condition.
class Solution {public: int maxProfit(vector if (len = prices[1]) return 0; else return prices[1] - prices[0]; } int len1 = len / 2; int len2 = len - len1; vector v1; v1.assign(prices.begin(), prices.begin() + len1 + 1); int prof1 = maxProfit(v1); vector v2; v2.assign(prices.begin() + len1, prices.end()); int prof2 = maxProfit(v2); return prof1 + prof2; }};LeetCode "Best Time to Buy and Sell Stock II",,
LeetCode "Best Time to Buy and Sell Stock II"
【感谢龙石为本站提供数据治理平台技术支撑 http://www.longshidata.com/pages/government.html】