Wednesday, August 16, 2017

122. Best Time to Buy and Sell Stock II

https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/description/
    int maxProfit(vector<int>& prices) {
        int p=0;
       
        for(int i=1;i<prices.size();i++) {
            if(prices[i] > prices[i-1])
                p += prices[i]-prices[i-1];
        }
        return p;

    }

No comments:

Post a Comment