Java O(n) simple solution (don't know why official solution is that long)
Key obseration is that three parts must have same number and pattern of 1s except the leading part.  My idea is to:\n\n1. count how many ones  (if num%3!=0 retu
Key obseration is that three parts must have same number and pattern of 1s except the leading part.  My idea is to:\n\n1. count how many ones  (if num%3!=0 return [-1,-1])\n2. search from right side to left, until we found num/3 1s.  This index is not final answer, but it defines patten of 1s\n3. from feft, ignore leading 0s, and then match the pattern found in step 2, to get the first EndIndex\n4. do another matching to found second EndIndex\n\n\n```\npublic int[] threeEqualParts(int[] A) {\n\t\tint numOne = 0;\n\t\tfor (int i: A){\n\t\t\tif (i==1) numOne++;\n\t\t}\n        \n        int[] noRes = {-1, -1};\n        if (numOne == 0) return new int[]{0,2};\n        if (numOne%3 != 0) return noRes;\n        \n        //find index of starting 1 of third string\n        int idxThird=0;\n\t\tint temp = 0;\n        for (int i = A.length-1; i>=0; i--){\n            if (A[i]==1){\n                temp++;\n                if (temp == numOne / 3){\n                    idxThird = i;\n                    break;\n                }\n            } \n        }\n        \n        int res1 = findEndIdx(A, 0, idxThird);\n        if (res1<0) return noRes;\n        \n        int res2 = findEndIdx(A, res1+1, idxThird);\n        if (res2<0) return noRes;\n        \n        return new int[]{res1, res2+1};\n    }\n    \n\t//right is the pattern to compare to.  \n\t//return EndIdx of left pattern that matches right side.\n    private int findEndIdx(int[] A, int left, int right){\n        while (A[left]==0) left++;\n        while (right < A.length){\n            if (A[left]!=A[right]) return -1;\n            left++;\n            right++;            \n        }\n        return left-1;\n    }\n```
['Java']