public boolean canThreePartsEqualSum(int[] A) {
int s = 0;
for (int num : A) {
s += num;
}
if (s % 3 != 0) {
return false;
}
int target = s / 3;
int n = A.length;
int i = 0;
int cur = 0;
while (i < n) {
cur += A[i];
if (cur == target) {
break;
}
i++;
}
if (cur != target) {
return false;
}
int j = i + 1;
while (j < n -1) {
cur += A[j];
if (cur == target * 2) {
return true;
}
j++;
}
return false;
}