Thursday, October 23, 2014

Best Time to Buy and Sell Stock II

sum all the differences that are greater than 0.

    int maxProfit(vector<int> &prices) {
        int profit=0;
        for(int i=1;i<prices.size();i++){
            profit+=max(0,prices[i]-prices[i-1]);
        }
        return profit;
    }

No comments:

Post a Comment