mirror of
https://github.com/chefyuan/algorithm-base.git
synced 2025-08-06 15:32:12 +00:00
添加Go语言题解
This commit is contained in:
@@ -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
|
||||
}
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user