> For the complete documentation index, see [llms.txt](https://dfine.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dfine.gitbook.io/leetcode/1013.partition_array_into_three_parts_with_equal_sum.md).

# 1013.Partition Array Into Three Parts with Equal Sum

**1013.Partition Array Into Three Parts with Equal Sum**

难度:Easy

> 给定一个整数数组 A，只有我们可以将其划分为三个和相等的非空部分时才返回 true，否则返回 false。

形式上，如果我们可以找出索引 i+1 < j 且满足 (A\[0] + A\[1] + ... + A\[i] == A\[i+1] + A\[i+2] + ... + A\[j-1] == A\[j] + A\[j-1] + ... + A\[A.length - 1]) 就可以将数组三等分。

```
示例 1：

输出：[0,2,1,-6,6,-7,9,1,2,0,1]
输出：true
解释：0 + 2 + 1 = -6 + 6 - 7 + 9 + 1 = 2 + 0 + 1
示例 2：

输入：[0,2,1,-6,6,7,9,-1,2,0,1]
输出：false
示例 3：

输入：[3,3,6,5,-2,2,5,1,-9,4]
输出：true
解释：3 + 3 = 6 = 5 - 2 + 2 + 5 + 1 - 9 + 4
 

提示：

3 <= A.length <= 50000
-10000 <= A[i] <= 10000
```

直接遍历，碰到前面两个和为sum/3的序列判断结束后，看最后剩下的和是不是sum/3。

```
class Solution {
public:
    bool canThreePartsEqualSum(vector<int>& A) {
        int sum=accumulate(A.begin(),A.end(),0);
       // cout<<sum<<endl;
        if(sum%3)
        return false;
           int start=0;
        for(int i=0;i<3;i++){
     
        int s=0;
        for( ;start<A.size();start++)
        {
            s+=A[start];
            if(s==sum/3) { ++start; break;}
        }
          //  cout<<s<< "   "<< start<<endl;
            if(s!=sum/3) return false;
        }
        return true;
    }
};
```

> 执行用时 :96 ms, 在所有 C++ 提交中击败了35.54%的用户\
> 内存消耗 :12.6 MB, 在所有 C++ 提交中击败了22.02%的用户


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://dfine.gitbook.io/leetcode/1013.partition_array_into_three_parts_with_equal_sum.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
