mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 08:50:15 +08:00
@ -230,7 +230,25 @@ class Solution:
|
|||||||
|
|
||||||
```
|
```
|
||||||
### Go
|
### 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
|
```go
|
||||||
func maxSubArray(nums []int) int {
|
func maxSubArray(nums []int) int {
|
||||||
maxSum := nums[0]
|
maxSum := nums[0]
|
||||||
|
Reference in New Issue
Block a user