Java 10ms solution with O(n) time and O(1)space
It is obviously that if the array can be divided into three part. The 1\'s number in each should be same. Besides, the 0\'s number in the last part should be th
It is obviously that if the array can be divided into three part. The 1\'s number in each should be same. Besides, the 0\'s number in the last part should be the true 0\'s number in the end of each part.\nWe get the 1\'s number and divide them into 3 parts. If numOf1 % 3 is not a integer then just return [-1, -1]. Suppose the number of 1 is 3n. The three parts should shart from the first 1, the n + 1th 1 and the 2n + 1th 1. Then we just compare all of them with the last part and can get the answer easily.\n```\nclass Solution {\n    public int[] threeEqualParts(int[] A) {\n        int[] res = new int[2];\n        res[0] = -1;\n        res[1] = -1;\n        // num Of 1\n        int numOf1 = 0;\n        for (int a : A) {\n            if (a == 1) {\n                numOf1++;\n            }\n        }\n        \n        if (numOf1 == 0) {\n            return new int[]{0, 2};\n        }\n        \n        if (numOf1 % 3 != 0) {\n            return res;\n        }\n        \n        int partLength = numOf1 / 3;\n        int index0 = -1;\n        int index1 = -1;\n        int index2 = -1;\n        numOf1 = 0;\n        for (int i = 0; i < A.length; i ++) {\n            if (A[i] == 1) {\n                numOf1++;\n                if (numOf1 == partLength + 1) {\n                    index1 = i;\n                } else if (numOf1 == 2 * partLength + 1) {\n                    index2 = i;\n                } else if (numOf1 == 1) {\n                    index0 = i;\n                }\n            }\n        }\n       \n        while (index2 < A.length) {\n            if (A[index2] == A[index0] && A[index2] == A[index1]) {\n                index2++;\n                index1++;\n                index0++;\n            } else {\n                return res;\n            }\n        }\n        \n        return new int[]{index0 - 1, index1};\n    }\n}\n```
[]