Merge branch 'master' into greedy02

This commit is contained in:
程序员Carl
2022-07-19 11:26:14 +08:00
committed by GitHub
176 changed files with 5174 additions and 514 deletions

View File

@@ -6,7 +6,7 @@
## 53. 最大子序和
[力扣题目链接](https://leetcode-cn.com/problems/maximum-subarray/)
[力扣题目链接](https://leetcode.cn/problems/maximum-subarray/)
给定一个整数数组 nums 找到一个具有最大和的连续子数组子数组最少包含一个元素返回其最大和。
@@ -186,6 +186,7 @@ const maxSubArray = nums => {
};
```
Scala:
```scala
@@ -203,5 +204,24 @@ object Solution {
}
```
TypeScript
```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]);
}
return resMax;
};
```
-----------------------
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>