Last active
August 29, 2015 14:19
-
-
Save stephen-maina/383c6fae88c78ff6b2f7 to your computer and use it in GitHub Desktop.
Passing cars codility fast
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
class Solution { | |
public int solution(int[] A) { | |
// write your code in Java SE 8 | |
int count=0; | |
int pair=0; | |
for(int index=0;index<A.length;index++){ | |
if(A[index]==0){ | |
count++; | |
}else{ | |
pair+=count; | |
if(pair>1000000000){ | |
return -1; | |
} | |
} | |
} | |
return pair; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment