Skip to content

Commit 385654d

Browse files
committed
121-best-time-to-buy-and-sell-stock.md Perfected examples.
1 parent 07b8aa1 commit 385654d

2 files changed

Lines changed: 16 additions & 18 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Lane's best practice for the LeetCode problems
1+
# Best practices for LeetCode solutions
22
Hi there! I'm Lane.
33
Do you feel that there are too many problems (over 3,300) on the LeetCode and you can't finish them all?
44
Or do you forget how to solve the problems you did last time?

solutions/1-1000/121-best-time-to-buy-and-sell-stock.md

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,27 @@ You want to **maximize** your profit by choosing **a single day** to buy one sto
88

99
Return 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.
1919
Note 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
3634
This problem can be solved using **Dynamic programming**.

0 commit comments

Comments
 (0)