Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. string balancedSums(vector<int> arr) {
  2.     if(arr.size() == 1){
  3.         return "YES";
  4.     }
  5.     else{
  6.         long sum = 0;
  7.         for(auto num: arr){
  8.             sum += num;
  9.         }
  10.  
  11.         if((sum - arr[0]) == 0){
  12.             return "YES";
  13.         }
  14.  
  15.         long sumLeft = 0;
  16.         for(size_t split = 1; split < arr.size(); split++){
  17.             sumLeft += arr[split-1];
  18.             long sumRight = sum-sumLeft-arr[split];
  19.  
  20.             if(sumLeft == sumRight){
  21.                 return "YES";
  22.             }
  23.         }
  24.     }
  25.  
  26.     return "NO";
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement