Leetcode 122 Solution
This article provides solution to leetcode question 122 (best-time-to-buy-and-sell-stock-ii)
Access this page by simply typing in "lcs 122" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
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;
}
};