Skip to content
This repository was archived by the owner on Apr 20, 2024. It is now read-only.

Commit 85aa9cf

Browse files
committed
added problem65
1 parent 84f6d39 commit 85aa9cf

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

problem65/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# 714. Best Time to Buy and Sell Stock with Transaction Fee
2+
3+
You are given an array prices where prices[i] is the price of a given stock on the ith day, and an integer fee representing a transaction fee.
4+
5+
Find the maximum profit you can achieve. You may complete as many transactions as you like, but you need to pay the transaction fee for each transaction.
6+
7+
Note:
8+
9+
You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again).
10+
The transaction fee is only charged once for each stock purchase and sale.
11+
12+
13+
## Example 1:
14+
15+
Input: prices = [1,3,2,8,4,9], fee = 2
16+
Output: 8
17+
Explanation: The maximum profit can be achieved by:
18+
- Buying at prices[0] = 1
19+
- Selling at prices[3] = 8
20+
- Buying at prices[4] = 4
21+
- Selling at prices[5] = 9
22+
The total profit is ((8 - 1) - 2) + ((9 - 4) - 2) = 8.
23+
24+
## Example 2:
25+
26+
Input: prices = [1,3,7,5,10,3], fee = 3
27+
Output: 6
28+
29+
30+
## Constraints:
31+
32+
1 <= prices.length <= 5 * 104
33+
1 <= prices[i] < 5 * 104
34+
0 <= fee < 5 * 104

0 commit comments

Comments
 (0)