Share my 8ms c++ solution


  • 1
    L
    class Solution {
    public:
        int maxProfit(vector<int>& prices) {
            int sum = 0;
            for(int i = 1; i < prices.size(); i ++)
            {
                if(prices[i] > prices[i - 1]) sum += prices[i] - prices[i - 1];
            }
            return sum;
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.