Guest User

Untitled

a guest
Jul 22nd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. // you can also use includes for example:
  2. // #include <algorithm>
  3.  
  4. unsigned long long sum(const vector<int> v) {
  5.     unsigned long long total = 0;
  6.     for(int i = 0; i < v.size(); ++i) {
  7.         total += v[i];
  8.     }
  9.    
  10.     return total;
  11. }
  12.  
  13. int equi ( const vector<int> &A ) {
  14.     int size = A.size();
  15.     unsigned long long front = 0, back = sum(A);
  16.    
  17.     for(int i = 0; i < size; ++i) {
  18.        
  19.        
  20.         back -= A[i];
  21.         if(front == back) return i;
  22.        
  23.        
  24.         front += A[i];
  25.        
  26.     }
  27.    
  28.     return -1;
  29. }
Add Comment
Please, Sign In to add comment