Merge pull request #58 from QuinnDK/添加0053最大子序和Go版本

添加0053最大子序和 Go版本
This commit is contained in:
Carl Sun 2021-05-13 17:28:33 +08:00 committed by GitHub
commit 82e80f7ee1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 1 deletions

View File

@ -175,8 +175,29 @@ class Solution:
```
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
}
}
```
-----------------------