← 返回 linkedin 的题目列表Max Consecutive Ones II with Streaming Data Follow-up
类型:online_judge
Problem: Max Consecutive Ones II
Given a binary array nums containing only 0s and 1s.
You may flip at most one 0 to 1.
Return the maximum number of consecutive 1s obtainable.
Example
Input: nums = [1,0,1,1,0]
Output: 4
Explanation: Flip the first 0 to get [1,1,1,1,0], whose longest consecutive 1s length is 4.
Follow-up: Streaming Data
If the data arrives as a stream and the whole array cannot be stored, how would you optimize the solution?
Constraints
1 <= nums.length <= 10^5
nums[i] is either 0 or 1.
Example
Input
5
1 0 1 1 0
Output
4