Leetcode 122 Solution

This article provides solution to leetcode question 122 (best-time-to-buy-and-sell-stock-ii)

https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii

Solution

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