Given a binary array, find the maximum number of consecutive 1s in this array if you can flip at most one 0.
Note
- The input array will only contain 0 and 1.
- The length of input array is a positive integer and will not exceed 10,000.
Example
No.1
Input: nums = [1,0,1,1,0]
Output: 4
Explanation:
Flip the first zero will get the the maximum number of consecutive 1s.
After flipping, the maximum number of consecutive 1s is 4.
No.2
Input: nums = [1,0,1,0,1]
Output: 3
Explanation:
Flip each zero will get the the maximum number of consecutive 1s.
After flipping, the maximum number of consecutive 1s is 3.
Code
1 | public int findMaxConsecutiveOnes(int[] nums) { |