77* [ Find Disappeared Numbers] ( #find-disappeared-numbers )
88* [ Find Index of Largest Number] ( #find-index-of-largest-number )
99* [ Find Max Consecutive Ones] ( #find-max-consecutive-ones )
10+ * [ Find Max Consecutive Ones With One Flip] ( #find-max-consecutive-ones-with-1-flip )
1011* [ Find Smallest Positive Integer] ( #find-smallest-positive-integer )
1112* [ First Duplicate] ( #first-duplicate )
1213* [ First Not Repeating Character] ( #first-not-repeating-character )
@@ -44,7 +45,7 @@ More formally check if there exists two indices i and j such that :
4445
4546` i != j `
4647` arr[i] == 2 * arr[j] `
47-
48+
4849Example 1:
4950
5051Input: ` [10,2,5,3] `
@@ -198,6 +199,42 @@ def find_index_largest_number(numbers: List[int]) -> int:
198199
199200## Find Max Consecutive Ones
200201
202+ You are given a binary array nums, return the maximum number of consecutive 1's in the array.
203+
204+ Example 1:
205+
206+ Input: nums = [ 1,1,0,1,1,1]
207+
208+ Output: 3
209+
210+ Example 2:
211+
212+ Input: nums = [ 1,0,1,1,0,1]
213+
214+ Output: 2
215+
216+ ``` python
217+ def find_max_consecutive_ones (nums : List[int ]) -> int :
218+ max_ones = 0
219+
220+ if not nums:
221+ return max_ones
222+
223+ ones_count = 0
224+
225+ for num in nums:
226+ if num == 1 :
227+ ones_count += 1
228+ else :
229+ ones_count = 0
230+
231+ max_ones = max (max_ones, ones_count)
232+
233+ return max_ones
234+ ```
235+
236+ ## Find Max Consecutive Ones With 1 Flip
237+
201238Given a binary array, find the maximum number of consecutive 1s in this array if you can flip at most one 0.
202239
203240Example 1:
@@ -207,7 +244,7 @@ Output: `4`
207244Explanation: Flip the first zero will get the the maximum number of consecutive 1s. After flipping, the maximum number of consecutive 1s is 4.
208245
209246``` python
210- def find_max_consecutive_ones (nums : List[int ]) -> int :
247+ def find_max_consecutive_ones_with_flip (nums : List[int ]) -> int :
211248 zero = - 1
212249 ones = 0
213250 highest = 0
0 commit comments