mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
@ -175,8 +175,29 @@ class Solution:
|
|||||||
```
|
```
|
||||||
|
|
||||||
Go:
|
Go:
|
||||||
|
```Go
|
||||||
|
func maxSubArray(nums []int) int {
|
||||||
|
if len(nums)<1{
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
dp:=make([]int,len(nums))
|
||||||
|
result:=nums[0]
|
||||||
|
dp[0]=nums[0]
|
||||||
|
for i:=1;i<len(nums);i++{
|
||||||
|
dp[i]=max(dp[i-1]+nums[i],nums[i])
|
||||||
|
result=max(dp[i],result)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func max(a,b int)int{
|
||||||
|
if a>b{
|
||||||
|
return a
|
||||||
|
}else{
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
-----------------------
|
-----------------------
|
||||||
|
Reference in New Issue
Block a user