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 #373

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 6 commits into AlgorithmAndLeetCode:master from youngyangyang04:master
Nov 6, 2023
Merged
Changes from 1 commit
Commits
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
fix: 0053.最大子序和原typescript过不了leetcode,更新代码逻辑
  • Loading branch information
xin authored and xin committed Oct 28, 2023
commit 22ac5d47548c0f6d8d1dcc2f0649c5bb297862c5
24 changes: 13 additions & 11 deletions problems/0053.最大子序和(动态规划).md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -226,18 +226,20 @@ object Solution {

```typescript
function maxSubArray(nums: number[]): number {
/**
dp[i]:以nums[i]结尾的最大和
*/
const dp: number[] = []
dp[0] = nums[0];
let resMax: number = 0;
for (let i = 1; i < nums.length; i++) {
dp[i] = Math.max(dp[i - 1] + nums[i], nums[i]);
resMax = Math.max(resMax, dp[i]);
const len = nums.length
if (len === 1) return nums[0]

const dp: number[] = new Array(len)
let resMax: number = dp[0] = nums[0]

for (let i = 1; i < len; i++) {
dp[i] = Math.max(dp[i - 1] + nums[i], nums[i])
// 注意值为负数的情况
if (dp[i] > resMax) resMax = dp[i]
}
return resMax;
};

return resMax
}
```


Expand Down

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