Skip to content

Commit

Permalink
add js solution for maxProfit with fee
Browse files Browse the repository at this point in the history
  • Loading branch information
jackeyjia authored Jul 10, 2021
1 parent a9344c2 commit 1c583ae
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,18 @@ class Solution:

Go:


Javascript:
```javascript
const maxProfit5 = (prices,fee) => {
let dp = Array.from(Array(prices.length), () => Array(2).fill(0));
dp[0][0] = 0 - prices[0];
for (let i = 1; i < prices.length; i++) {
dp[i][0] = Math.max(dp[i - 1][0], dp[i - 1][1] - prices[i]);
dp[i][1] = Math.max(dp[i - 1][0] + prices[i] - fee, dp[i - 1][1]);
}
return Math.max(dp[prices.length - 1][0], dp[prices.length - 1][1]);
}
```


-----------------------
Expand Down

0 comments on commit 1c583ae

Please sign in to comment.