From 4a859ac6369e78ffb13772e66440d1605ac57afb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98=E5=B0=8F=E8=B4=BA?= Date: Sun, 16 May 2021 14:23:00 +0800 Subject: [PATCH] add go solution --- problems/0053.最大子序和.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/problems/0053.最大子序和.md b/problems/0053.最大子序和.md index b8a9d748..f5526a61 100644 --- a/problems/0053.最大子序和.md +++ b/problems/0053.最大子序和.md @@ -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 +} +```