Say you have an array for which the ith element is the price of a given stock on day i.
Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However, you may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).
====================================================================================
Imagine you are a day trader, just buy when the stock rises, and sell it tommorrow.
1 class Solution { 2 public: 3 int maxProfit(vector &prices) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 int max_profit = 0; 7 for(int i = 1; i < prices.size(); i++) { 8 if(prices[i] > prices[i - 1]) { 9 max_profit += prices[i] - prices[i - 1];10 }11 }12 return max_profit;13 14 }15 };