
class Solution(object):
def longestOnes(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: int
"""
max_len = float('-inf')
star = 0
count = 0
for end in range(len(nums)):
if nums[end] == 1:
count += 1
while count + k < end-star+1:
if nums[star] == 1:
count -= 1
star += 1
max_len = max(max_len, end-star+1)
return max_len if max_len != float('-inf') else 0
本文介绍了一种Python实现的方法,用于寻找给定整数数组中长度最长的连续1子数组。通过遍历和动态调整计数器,解决了如何在数组中找到满足特定条件的子数组问题。
849

被折叠的 条评论
为什么被折叠?



