|
11 | 11 |
|
12 | 12 | ## [122. Best Time to Buy and Sell Stock II (Easy)](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii "买卖股票的最佳时机 II")
|
13 | 13 |
|
14 |
| -<p>Say you have an array <code>prices</code> for which the <em>i</em><sup>th</sup> element is the price of a given stock on day <em>i</em>.</p> |
| 14 | +<p>You are given an array <code>prices</code> for which the <code>i<sup>th</sup></code> element is the price of a given stock on day <code>i</code>.</p> |
15 | 15 |
|
16 |
| -<p>Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times).</p> |
| 16 | +<p>Find the maximum profit you can achieve. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times).</p> |
17 | 17 |
|
18 |
| -<p><strong>Note:</strong> You may not engage in multiple transactions at the same time (i.e., you must sell the stock before you buy again).</p> |
| 18 | +<p><strong>Note:</strong> You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).</p> |
19 | 19 |
|
| 20 | +<p> </p> |
20 | 21 | <p><strong>Example 1:</strong></p>
|
21 | 22 |
|
22 | 23 | <pre>
|
23 |
| -<strong>Input:</strong> [7,1,5,3,6,4] |
| 24 | +<strong>Input:</strong> prices = [7,1,5,3,6,4] |
24 | 25 | <strong>Output:</strong> 7
|
25 | 26 | <strong>Explanation:</strong> Buy on day 2 (price = 1) and sell on day 3 (price = 5), profit = 5-1 = 4.
|
26 |
| - Then buy on day 4 (price = 3) and sell on day 5 (price = 6), profit = 6-3 = 3. |
| 27 | +Then buy on day 4 (price = 3) and sell on day 5 (price = 6), profit = 6-3 = 3. |
27 | 28 | </pre>
|
28 | 29 |
|
29 | 30 | <p><strong>Example 2:</strong></p>
|
30 | 31 |
|
31 | 32 | <pre>
|
32 |
| -<strong>Input:</strong> [1,2,3,4,5] |
| 33 | +<strong>Input:</strong> prices = [1,2,3,4,5] |
33 | 34 | <strong>Output:</strong> 4
|
34 | 35 | <strong>Explanation:</strong> Buy on day 1 (price = 1) and sell on day 5 (price = 5), profit = 5-1 = 4.
|
35 |
| - Note that you cannot buy on day 1, buy on day 2 and sell them later, as you are |
36 |
| - engaging multiple transactions at the same time. You must sell before buying again. |
| 36 | +Note that you cannot buy on day 1, buy on day 2 and sell them later, as you are engaging multiple transactions at the same time. You must sell before buying again. |
37 | 37 | </pre>
|
38 | 38 |
|
39 | 39 | <p><strong>Example 3:</strong></p>
|
40 | 40 |
|
41 | 41 | <pre>
|
42 |
| -<strong>Input:</strong> [7,6,4,3,1] |
| 42 | +<strong>Input:</strong> prices = [7,6,4,3,1] |
43 | 43 | <strong>Output:</strong> 0
|
44 |
| -<strong>Explanation:</strong> In this case, no transaction is done, i.e. max profit = 0.</pre> |
| 44 | +<strong>Explanation:</strong> In this case, no transaction is done, i.e., max profit = 0. |
| 45 | +</pre> |
45 | 46 |
|
46 | 47 | <p> </p>
|
47 | 48 | <p><strong>Constraints:</strong></p>
|
48 | 49 |
|
49 | 50 | <ul>
|
50 |
| - <li><code>1 <= prices.length <= 3 * 10 ^ 4</code></li> |
51 |
| - <li><code>0 <= prices[i] <= 10 ^ 4</code></li> |
| 51 | + <li><code>1 <= prices.length <= 3 * 10<sup>4</sup></code></li> |
| 52 | + <li><code>0 <= prices[i] <= 10<sup>4</sup></code></li> |
52 | 53 | </ul>
|
53 | 54 |
|
54 | 55 | ### Related Topics
|
|
0 commit comments