Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string balancedSums(vector<int> arr) {
- if(arr.size() == 1){
- return "YES";
- }
- else{
- long sum = 0;
- for(auto num: arr){
- sum += num;
- }
- if((sum - arr[0]) == 0){
- return "YES";
- }
- long sumLeft = 0;
- for(size_t split = 1; split < arr.size(); split++){
- sumLeft += arr[split-1];
- long sumRight = sum-sumLeft-arr[split];
- if(sumLeft == sumRight){
- return "YES";
- }
- }
- }
- return "NO";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement