1. Title
1. Topic description
You are given an array of integers prices
, which prices[i]
represents the price of a certain stock on i
day 1.
On each day, you can decide whether to buy and/or sell stocks. You can only hold a maximum of one share at any time . You can also buy first and then sell on the same day .
Return the maximum profit you can make .
Example 1 :
Input: prices = [7,1,5,3,6,4]
Output: 7
Explanation: Buy on day 2 (stock price = 1) and sell on day 3 (stock price = 5) Out, the profit from this transaction = 5 - 1 = 4.
Subsequently, if you buy on the 4th day (stock price = 3) and sell on the 5th day (stock price = 6), the profit from this transaction = 6 - 3 = 3.
The total profit is 4 + 3 = 7.
Example 2 :
Input: prices = [1,2,3,4,5]
Output: 4
Explanation: Buy on day 1 (stock price = 1), sell on day 5 (stock price = 5), This amount