Created
February 28, 2020 04:57
-
-
Save RP-3/25e6cb2f992e7856513c223914169b71 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var longestOnes = function(A, K) { | |
let result = 0; | |
let i=0; let j=0; let k=K; | |
while(j < A.length){ | |
if(A[j] === 1){ | |
result = Math.max(result, j-i+1); | |
j++; | |
} | |
else if(k>0){ | |
result = Math.max(result, j-i+1); | |
k--; | |
j++; | |
}else{ | |
if(A[i++] === 0) k++; | |
} | |
} | |
return result; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment