leetcode1004】的更多相关文章

Given an array A of 0s and 1s, we may change up to K values from 0 to 1. Return the length of the longest (contiguous) subarray that contains only 1s. Example 1: Input: A = [1,1,1,0,0,0,1,1,1,1,0], K = 2 Output: 6 Explanation: [1,1,1,0,0,1,1,1,1,1,1]…
class Solution: def getMax(self,B:'List[int]'): n = len(B) maxlen = 0 curlen = 0 for i in range (n): if B[i] == 1: curlen += 1 else: maxlen = max(maxlen,curlen) curlen = 0 return max(maxlen,curlen) def longestOnes(self, A: 'List[int]', K: int) -> int…