File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed
best-time-to-buy-and-sell-stock-with-transaction-fee Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,8 @@ Step 2. Add the dependency
47
47
48
48
https://leetcode.cn/problems/minimum-limit-of-balls-in-a-bag/
49
49
50
+ https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-with-transaction-fee
51
+
50
52
https://leetcode.cn/problems/grumpy-bookstore-owner/
51
53
52
54
https://leetcode.cn/problems/add-edges-to-make-degrees-of-all-nodes-even/
Original file line number Diff line number Diff line change
1
+ function maxProfit ( prices : number [ ] , fee : number ) : number {
2
+ const n = prices . length ;
3
+ let buy = prices [ 0 ] + fee ;
4
+ let profit = 0 ;
5
+ for ( let i = 1 ; i < n ; i ++ ) {
6
+ if ( prices [ i ] + fee < buy ) {
7
+ buy = prices [ i ] + fee ;
8
+ } else if ( prices [ i ] > buy ) {
9
+ profit += prices [ i ] - buy ;
10
+ buy = prices [ i ] ;
11
+ }
12
+ }
13
+ return profit ;
14
+ }
15
+ export default maxProfit ;
You can’t perform that action at this time.
0 commit comments