【leetcode】122. 买卖股票的最佳时机 II

 

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;
}

 

posted @ 2020-12-01 09:45  温暖了寂寞  阅读(55)  评论(0编辑  收藏  举报