Skip to content

Commit

Permalink
review300: minimum size subarray sum
Browse files Browse the repository at this point in the history
  • Loading branch information
meooxx committed Mar 25, 2024
1 parent 1706579 commit 25e5bad
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions minimumSizeSubarraySum/review300.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

func minSubArrayLen(target int, nums []int) int {
l, r := 0, 0
sum := 0
count := len(nums) + 1
for ; r < len(nums); r++ {
sum += nums[r]
for sum >= target {
c := r - l + 1
sum -= nums[l]
l++
if c < count {
count = c
}
}
}
// Not found
if count == len(nums)+1 {
return 0
}
return count
}

0 comments on commit 25e5bad

Please sign in to comment.