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

[pull] master from youngyangyang04:master #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
pull merged 18 commits into AlgorithmAndLeetCode:master from youngyangyang04:master
Jun 4, 2022
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
abe0023
添加 0001.两数之和.md Scala版本
wzqwtt May 13, 2022
53379c0
添加 0454.四数相加II.md Scala版本
wzqwtt May 13, 2022
16c6abf
添加 0383.赎金信.md Scala版本
wzqwtt May 13, 2022
ca27111
添加(0714.买卖股票的最佳时机含手续费动态规划.md):增加typescript版本
xiaofei-2020 May 13, 2022
a53da7b
添加 0015.三数之和.md Scala版本
wzqwtt May 14, 2022
68eed4a
添加 0018.四数之和.md Scala版本
wzqwtt May 14, 2022
e4da60a
添加 0344.反转字符串.md Scala版本
wzqwtt May 14, 2022
f2dcdbe
添加 0541.反转字符串II.md Scala版本
wzqwtt May 14, 2022
037bebb
添加 剑指Offer05.替换空格.md Scala版本
wzqwtt May 14, 2022
1c369bb
102 in rust
3Xpl0it3r May 14, 2022
b8b62ff
树深度 rust实现
3Xpl0it3r May 18, 2022
9611896
Merge branch 'youngyangyang04:master' into master
3Xpl0it3r May 18, 2022
8c2737d
Merge branch 'master' into patch08
youngyangyang04 Jun 4, 2022
71a9111
Merge pull request #1326 from wzqwtt/patch08
youngyangyang04 Jun 4, 2022
b91d3c2
Merge pull request #1327 from xiaofei-2020/dp39
youngyangyang04 Jun 4, 2022
83726ac
Merge pull request #1328 from wzqwtt/patch09
youngyangyang04 Jun 4, 2022
dab44f5
Merge pull request #1329 from wzqwtt/patch10
youngyangyang04 Jun 4, 2022
9c32528
Merge pull request #1330 from 3Xpl0it3r/master
youngyangyang04 Jun 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
添加(0714.买卖股票的最佳时机含手续费动态规划.md):增加typescript版本
  • Loading branch information
xiaofei-2020 committed May 13, 2022
commit ca2711164dfd39b51f1e6d96207673ffba29d3f1
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,29 @@ const maxProfit = (prices,fee) => {
}
```

TypeScript:

```typescript
function maxProfit(prices: number[], fee: number): number {
/**
dp[i][0]:持有股票
dp[i][1]: 不持有
*/
const length: number = prices.length;
if (length === 0) return 0;
const dp: number[][] = new Array(length).fill(0).map(_ => []);
dp[0][0] = -prices[0];
dp[0][1] = 0;
for (let i = 1; i < 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][1], dp[i - 1][0] + prices[i] - fee);
}
return dp[length - 1][1];
};
```




-----------------------
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>

AltStyle によって変換されたページ (->オリジナル) /