@@ -8,29 +8,27 @@ You want to **maximize** your profit by choosing **a single day** to buy one sto
88
99Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return ` 0 ` .
1010
11- ```
12- ------------------------------------------------------------------------------------------------------
13- [Example 1]
11+ ### [ Example 1]
12+ ** Input** : ` prices = [7,1,5,3,6,4] `
1413
15- Input: prices = [7,1,5,3,6,4]
16- Output: 5
14+ ** Output** : ` 5 `
1715
18- Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5.
16+ ** Explanation**
17+ ```
18+ Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5.
1919Note that buying on day 2 and selling on day 1 is not allowed because you must buy before you sell.
20- ------------------------------------------------------------------------------------------------------
21- [Example 2]
20+ ```
2221
23- Input: prices = [7,6,4,3,1 ]
24- Output: 0
22+ ### [ Example 2 ]
23+ ** Input ** : ` prices = [7,6,4,3,1] `
2524
26- Explanation: In this case, no transactions are done and the max profit = 0.
27- ------------------------------------------------------------------------------------------------------
28- [Constraints]
25+ ** Output** : ` 0 `
2926
30- 1 <= prices.length <= 100000
31- 0 <= prices[i] <= 10000
32- ------------------------------------------------------------------------------------------------------
33- ```
27+ ** Explanation** : ` In this case, no transactions are done and the max profit = 0. `
28+
29+ ### [ Constraints]
30+ - ` 1 <= prices.length <= 100000 `
31+ - ` 0 <= prices[i] <= 10000 `
3432
3533## Thoughts
3634This problem can be solved using ** Dynamic programming** .
0 commit comments