mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-06 01:15:57 +08:00
fix/209: clean up redundant code
This commit is contained in:
@ -1,24 +1,16 @@
|
||||
package leetcode
|
||||
|
||||
func minSubArrayLen(s int, nums []int) int {
|
||||
n := len(nums)
|
||||
if n == 0 {
|
||||
return 0
|
||||
}
|
||||
left, right, res, sum := 0, -1, n+1, 0
|
||||
for left < n {
|
||||
if (right+1) < n && sum < s {
|
||||
right++
|
||||
sum += nums[right]
|
||||
} else {
|
||||
func minSubArrayLen(target int, nums []int) int {
|
||||
left, sum, res := 0, 0, len(nums)+1
|
||||
for right, v := range nums {
|
||||
sum += v
|
||||
for sum >= target {
|
||||
res = min(res, right-left+1)
|
||||
sum -= nums[left]
|
||||
left++
|
||||
}
|
||||
if sum >= s {
|
||||
res = min(res, right-left+1)
|
||||
}
|
||||
}
|
||||
if res == n+1 {
|
||||
if res == len(nums)+1 {
|
||||
return 0
|
||||
}
|
||||
return res
|
||||
|
Reference in New Issue
Block a user