Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1e6a9b8

Browse files
Merge pull requestyoungyangyang04#487 from jackeyjia/patch-11
add js solution for maxProfit with fee
2 parentsc2e3d10 +69e54d9 commit1e6a9b8

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

‎problems/0714.买卖股票的最佳时机含手续费(动态规划).md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,18 @@ class Solution:
153153

154154
Go:
155155

156-
156+
Javascript:
157+
```javascript
158+
constmaxProfit= (prices,fee)=> {
159+
let dp=Array.from(Array(prices.length), ()=>Array(2).fill(0));
160+
dp[0][0]=0- prices[0];
161+
for (let i=1; i<prices.length; i++) {
162+
dp[i][0]=Math.max(dp[i-1][0], dp[i-1][1]- prices[i]);
163+
dp[i][1]=Math.max(dp[i-1][0]+ prices[i]- fee, dp[i-1][1]);
164+
}
165+
returnMath.max(dp[prices.length-1][0], dp[prices.length-1][1]);
166+
}
167+
```
157168

158169

159170
-----------------------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp