Created
June 16, 2018 15:09
-
-
Save adicuco/83e104975c62170f2c34253c7161d081 to your computer and use it in GitHub Desktop.
100 % solution for Passing Cars Task on Codility
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
function solution(A) { | |
var zero = 0; | |
var count = 0; | |
for (var i = 0; i < A.length; i++) { | |
if (A[i] == 0) zero++; | |
else { | |
count += 1 * zero; | |
if (count > 1000000000) return -1; | |
} | |
} | |
return count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
count += zero
without multiply would work too :-)