int maxProfit(int* prices, int pricesSize){ int ans = 0; for (int i = 1; i < pricesSize; ++i) { /* 当天价格大于前一天价格,前一天买入,当天卖出,利润累加 */ ans += fmax(0, prices[i] - prices[i - 1]); } return ans; }
【leetcode】122. 买卖股票的最佳时机 II
原文:https://www.cnblogs.com/ganxiang/p/14066385.html