1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| // @Title: 连续子数组的最大和 (连续子数组的最大和 LCOF)
// @Author: 15816537946@163.com
// @Date: 2022-02-13 10:43:04
// @Runtime: 16 ms
// @Memory: 6.9 MB
func maxSubArray(nums []int) int {
max := 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] > max {
max = nums[i]
}
}
return max
}
|