Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Удалять один элемент из массива обязательно
- func longestSubarray(_ nums: [Int]) -> Int {
- var l = 0
- var r = 0
- var countZeros = 0
- var maxLenght = 0
- while r < nums.count {
- if nums[r] == 0 {
- countZeros += 1
- }
- while countZeros == 2 {
- // от левого
- if nums[l] == 0 {
- countZeros -= 1
- }
- l += 1
- }
- maxLenght = max(maxLenght, r-l)
- r += 1
- }
- return maxLenght
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement