Partition Array Into Three Parts With Equal Sum
<-E 1013> Partition Array Into Three Parts With Equal Sum
class Solution {
public:
bool canThreePartsEqualSum(vector<int>& A) {
int target = accumulate(A.begin(), A.end(), 0);
if(target % 3 != 0)
return false;
int cur = 0, count = 0;
target /= 3;
for(int n : A) {
cur += n;
if(cur == target) {
count++;
cur = 0;
}
}
return count >= 3 ? true : false;
}
};