Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 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.         for(size_t split = 0; split < arr.size(); split++){
  12.             long sumLeft = 0;
  13.             long sumRight = 0;
  14.  
  15.             for(size_t j = 0; j < split; j++){
  16.                 sumLeft += arr[j];
  17.             }
  18.             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