mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 04:06:51 +08:00
add go solution
This commit is contained in:
@ -145,7 +145,20 @@ Python:
|
||||
|
||||
|
||||
Go:
|
||||
|
||||
```go
|
||||
func maxSubArray(nums []int) int {
|
||||
maxSum := nums[0]
|
||||
for i := 1; i < len(nums); i++ {
|
||||
if nums[i] + nums[i-1] > nums[i] {
|
||||
nums[i] += nums[i-1]
|
||||
}
|
||||
if nums[i] > maxSum {
|
||||
maxSum = nums[i]
|
||||
}
|
||||
}
|
||||
return maxSum
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user