Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MARK: - Найти MIN подотрезок суммой X (все +)
- func minSubArrayLen(_ target: Int, _ nums: [Int]) -> Int {
- var r = 0
- var l = 0
- var summ = 0
- var minLength = Int.max
- while r < nums.count {
- summ += nums[r]
- while summ > target {
- summ -= nums[l]
- l += 1
- }
- if summ == target {
- minLength = min(minLength, r-l+1)
- }
- r += 1
- }
- return minLength == Int.max ? 0 : minLength
- }
- let numsMin = [1,2,3,4,5]
- minSubArrayLen(11, numsMin)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement