Merge pull request #2443 from gdstzmy/master

Update 0053.最大子序和.md
This commit is contained in:
程序员Carl
2024-02-26 15:15:08 +08:00
committed by GitHub

View File

@ -230,7 +230,25 @@ class Solution:
```
### Go
贪心法
```go
func maxSubArray(nums []int) int {
max := nums[0]
count := 0
for i := 0; i < len(nums); i++{
count += nums[i]
if count > max{
max = count
}
if count < 0 {
count = 0
}
}
return max
}
```
动态规划
```go
func maxSubArray(nums []int) int {
maxSum := nums[0]