Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. #include<math.h>
  2. int solution(vector<int> &A) {
  3. // write your code in C++14 (g++ 6.2.0)
  4. int size = (int)A.size();
  5. int cnt = 0, res = 0;
  6. for (int i = 0; i < size; i++) {
  7. if (A[i] == 0) {
  8. cnt++;
  9. } else {
  10. res += cnt;
  11. }
  12. }
  13. if (abs(res) > 1000000000) {
  14. return -1;
  15. }
  16.  
  17. return res;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement