my O( N ) C++ solution
At first, we calculate the total number of \'1\', and check if it can be divided by 3. Because each part must contain the same number of \'1\'.\nIf not, we just
At first, we calculate the total number of \'1\', and check if it can be divided by 3. Because each part must contain the same number of \'1\'.\nIf not, we just return { -1, -1 }.\nThen, we calculate the number of \'0\' at the end of the array, which means that we won\'t stop until we find the first \'1\' at the end. If the array can be split into 3 parts, each part must has the same number of \'0\' as the end of the array.\nSince we have already got the total number of \'1\' and the number of \'0\' at the end of the array, we can check if the array can be divided into three parts with the exact number of 1 and 0 as we expected,  and whether the three parts are equal to each other ( pay attention that we should skip the leading zero ). If we can find the result, we record the index, and return it.\n```\nclass Solution {\npublic:\n    vector<int> threeEqualParts(vector<int>& A) {\n        vector<int> res;  \n        int n = A.size();\n        int zeros = 0; // number of zero at the end\n        int ones = 0; // total number of one\n        \n        // get number of zero at the end\n        for(int i = n - 1; i >= 0;i--)\n        {\n            if(A[i] == 1) break;\n            zeros++;\n        }\n        // get total number of one\n        for(int i = 0;i < n;i++)\n        {\n            if(A[i] == 1) nums++;\n        }\n        \n        // all data in this array is 0, we can divide the array at every place\n        if(nums == 0)\n        {\n            return {0, n - 1};\n        }\n        \n        // the total number of 1 can\'t be divided by 3. return false.\n        if(nums % 3) return {-1, -1};\n\n        int count = nums / 3;\n        string target;\n                \n        // check if the array can be split into 3 parts\n        // each parts has (ones/3)\'s 1, and has (zeros)\'s 0 at at the end\n        int i = 0;\n        for(int k = 0; k < 3;k++)\n        {\n            string str;\n            int one_nums = 0;\n            int zero_nums = 0;\n            for(;i < n; i++)\n            {\n                if(one_nums == count && zero_nums == zeros) break;\n                if(A[i] == 0)\n                {\n                    if(one_nums == count)\n                    {\n                        zero_nums++;\n                    }\n                    if(!str.empty()) // skip the leading 0.\n                        str.push_back(A[i]);\n                }\n                else if(A[i] == 1)\n                {\n                    if(one_nums == count) // the number of 0 at the end is not match\n                    {\n                        return {-1, -1};\n                    }\n                    one_nums++;\n                    str.push_back(A[i]);\n                }   \n            }\n\n            if(target.empty())\n            {\n                target = str;\n            }\n            else\n            {\n                if(target != str) return {-1, -1};  // current part and last part is not match             \n            }\n            if(k == 0) res.push_back(i - 1); // record the index\n            else if(k == 1) res.push_back(i);\n        }\n        \n        return res;\n    }\n};\n```
[]