Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func longestOnes(_ arr: [Int], _ k: Int) -> Int {
- guard arr.count > 0 else {return 0}
- var left = 0
- var right = 0
- var res = 0
- var count = 0
- while right < arr.count{
- if arr[right] == 0 {
- count += 1
- }
- while count > k {
- if arr[left] == 0 {
- count -= 1
- }
- left += 1
- }
- res = max(res, right - left + 1)
- right += 1
- }
- return res
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement