首先,原谅我这个菜狗子用的中文版。紧接着上题目。
这是一道easy的题目。一开始,我还是很懵逼的。用两个指针,分别指向两端,向中间移动。对应的左边和与右边和相等时,查看中间部分的情况即可。很显然结果是没通过。所以当时就简单暴力了一下。哎,暴力出真知啊。
class Solution {
public boolean canThreePartsEqualSum(int[] A) {
int threeSum=0;
for (int i=0;i<A.length;i++) {
threeSum+=A[i];
}
int sum=threeSum/3;
if (threeSum%3!=0) {
return false;
}
int count=0;int temp=0;
for (int i=0;i<A.length;i++) {
temp+=A[i];
if (temp==sum) {
count++;
temp=0;
}
}
return count==3;
}
}