添加Go语言题解

This commit is contained in:
zouxinyao
2021-07-28 02:26:32 +08:00
parent 7eb8b4a9fd
commit 575b7612f0
52 changed files with 1679 additions and 104 deletions

View File

@@ -119,3 +119,35 @@ class Solution {
}
}
```
Go Code:
```go
func minSubArrayLen(target int, nums []int) int {
length := len(nums)
winLen := length + 1
i := 0
sum := 0
for j := 0; j < length; j++ {
sum += nums[j]
for sum >= target {
winLen = min(winLen, j - i + 1)
sum -= nums[i]
i++
}
}
if winLen == length + 1 {
return 0
}
return winLen
}
func min(a, b int) int {
if a < b {
return a
}
return b
}
```