We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ce26e1b commit 9d92c13Copy full SHA for 9d92c13
problems/0714.买卖股票的最佳时机含手续费.md
@@ -217,7 +217,29 @@ class Solution: # 贪心思路
217
218
Go:
219
220
+Javascript:
221
+```Javascript
222
+// 贪心思路
223
+var maxProfit = function(prices, fee) {
224
+ let result = 0
225
+ let minPrice = prices[0]
226
+ for(let i = 1; i < prices.length; i++) {
227
+ if(prices[i] < minPrice) {
228
+ minPrice = prices[i]
229
+ }
230
+ if(prices[i] >= minPrice && prices[i] <= minPrice + fee) {
231
+ continue
232
233
234
+ if(prices[i] > minPrice + fee) {
235
+ result += prices[i] - minPrice - fee
236
+ // 买入和卖出只需要支付一次手续费
237
+ minPrice = prices[i] -fee
238
239
240
+ return result
241
+};
242
+```
243
244
245
-----------------------
0 commit comments