Skip to content

Instantly share code, notes, and snippets.

@clarkdo
Created January 29, 2018 08:37
Show Gist options
  • Save clarkdo/0e4616952a754218cd28b6fc95daf569 to your computer and use it in GitHub Desktop.
Save clarkdo/0e4616952a754218cd28b6fc95daf569 to your computer and use it in GitHub Desktop.
class Solution {
public int solution(int[] A) {
int pairs = 0;
int easts = 0;
for (int i : A) {
if (i == 0) {
easts++;
} else {
pairs += easts;
}
if (pairs > 1e9) {
pairs = -1;
break;
}
}
return pairs;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment