← 返回 bloomberg 的题目列表Max Consecutive Ones II
类型:online_judge
Max Consecutive Ones II
Given a binary array, you can flip at most one 0 to 1. Find the maximum number of consecutive 1s after the flip.
Input
A binary array nums.
Output
An integer representing the maximum number of consecutive 1s after the flip.
Example
Input: [1,0,1,1,0]
Output: 4
Follow up
Implement a follow up where you can flip at most K 0s to 1s and find the maximum consecutive 1s.
Constraints
The length of the array is between 1 and 10^5.
The elements in the array are either 0 or 1.
Example
Input
5
1 0 1 1 0
1