python solution with my thinking process (very simple logic,with extra Chinese explanation)
you can get Chinese explanation in \nhttps://buptwc.github.io/2018/10/21/Leetcode-927-Three-Equal-Parts/\n\nI define the three part as a,b,c.\nNotice that the l
you can get Chinese explanation in \nhttps://buptwc.github.io/2018/10/21/Leetcode-927-Three-Equal-Parts/\n\nI define the three part as `a,b,c`.\nNotice that the length of A reaches 30000, so we cannot first determine the value of `a,b` separately and later compare with `c`, it\'s O(n^2) time! We need to find a way to directly determine the remaining two arrays based on the first array.\n\nI propose a definition here called the `effective length`, here it refers to the length of the array without leading `0`.For example, the `effective length` of [0,0,1,1] is `2`\n\nSo, if the value of `a,b,c` is same, the `effective length` of `a,b,c` should also be same.\n\nOK, follow this, I define the index at the end of `a` array is `e1`, and we know the index of first `1` in the array, as `s1`;So we get the `effective length` of `a` array, as `l = e1 - s1 + 1`(assume e1 >= s1)\n\nwe define `s2` as the effective begin index of `b` array, we have `s2 = the index of first 1 after e1`. Because the `effective length` should be same with `a` array. so the end index of `b` array should be `e2 = s2 + l `.  We can also use this method to determine the effective index of `c` array(`s3,e3`)\n\nNow we found some termination conditions.\n`if e2 >= n`, we can break\n`if e3 > n`, we can break\n`if e3 < n`, continue to find next `e1`\n`if e3 == n`, we compare `a == b == c`\n\nTo avoid double counting, I define left[i] refers to the index of first `1` before `i`, right[i] refers to the index of first `1` after `i`.\nso we have `s1 = left[e1], s2 = right[e1], e2 = s2 + l, s3 = right[e2], e3 = s3 + l`\n\n```python\n# 120ms\nclass Solution(object):\n    def threeEqualParts(self, A):\n        # Consider the case where no 0 exists\n        if A.count(1) == 0:\n            return [0,len(A)-1]\n\n        n = len(A)\n        # get left and right array\n        right = [-1] * n\n        index = n\n        for i in range(n-1,-1,-1):\n            right[i] = index\n            if A[i] == 1: index = i\n\n        left = [-1] * n\n        index = A.index(1)\n        for i in range(n):\n            if i >= index: left[i] = index\n\n        for e1 in range(n-2):\n            s1 = left[e1]\n            if s1 == -1: continue\n            l = e1 - s1 + 1\n\n            s2 = right[e1]\n            e2 = s2 + l - 1\n            if e2 >= n: break\n\n            s3 = right[e2]\n            if s3 >= n: break\n            if n - s3 != l: continue\n\n            if A[s1:e1+1] == A[s2:e2+1] == A[s3:n]:\n                return [i, e2 + 1]\n        return [-1, -1]\n```
[]