File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 191
191
| 701| [ 二叉搜索树中的插入操作] ( https://leetcode.cn/problems/insert-into-a-binary-search-tree/ ) | [ JavaScript] ( ./algorithms/insert-into-a-binary-search-tree.js ) | Medium|
192
192
| 704| [ 二分查找] ( https://leetcode.cn/problems/binary-search/ ) | [ JavaScript] ( ./algorithms/binary-search.js ) | Easy|
193
193
| 707| [ 设计链表] ( https://leetcode.cn/problems/design-linked-list/ ) | [ JavaScript] ( ./algorithms/design-linked-list.js ) | Medium|
194
+ | 714| [ 买卖股票的最佳时机含手续费] ( https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-with-transaction-fee/ ) | [ JavaScript] ( ./algorithms/best-time-to-buy-and-sell-stock-with-transaction-fee.js ) | Medium|
194
195
| 738| [ 单调递增的数字] ( https://leetcode.cn/problems/monotone-increasing-digits/ ) | [ JavaScript] ( ./algorithms/monotone-increasing-digits.js ) | Medium|
195
196
| 763| [ 划分字母区间] ( https://leetcode.cn/problems/partition-labels/ ) | [ JavaScript] ( ./algorithms/partition-labels.js ) | Medium|
196
197
| 844| [ 比较含退格的字符串] ( https://leetcode.cn/problems/backspace-string-compare/ ) | [ JavaScript] ( ./algorithms/backspace-string-compare.js ) | Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {number[] } prices
3
+ * @param {number } fee
4
+ * @return {number }
5
+ */
6
+ var maxProfit = function ( prices , fee ) {
7
+ let minPrice = prices [ 0 ] ;
8
+ let result = 0 ;
9
+
10
+ for ( let i = 1 ; i < prices . length ; i ++ ) {
11
+ const curr = prices [ i ] ;
12
+ if ( minPrice > curr ) {
13
+ minPrice = curr ;
14
+ }
15
+ if ( curr - minPrice > fee ) {
16
+ result += curr - minPrice - fee ;
17
+ minPrice = curr - fee ;
18
+ }
19
+ }
20
+
21
+ return result ;
22
+ } ;
You can’t perform that action at this time.
0 commit comments