114: Best time to buy and sell stock 2
Given stock prices, write a method to maximize profit. You can buy and sell as many transactions as you like
Note: it's not allowed to sell before buy
Example 1
Input: [5, 3, 6, 1, 9, 2, 16]
Output: 25
Explanation: [Buy = 3, Sell = 6], [Buy = 1, Sell = 9], [Buy = 2, Sell = 15] Profit = 3 + 8 + 14
Example 2
Input: [12, 6, 5, 3, 1]
Output: 0