Clean Java Binary Search O(N(logN))
\n\n# Code\n\nclass Solution {\n    int MOD = (int) (1e9 + 7);\n    public int waysToSplit(int[] nums) {\n        if (nums == null || nums.length < 3 ) {\n     
\n\n# Code\n```\nclass Solution {\n    int MOD = (int) (1e9 + 7);\n    public int waysToSplit(int[] nums) {\n        if (nums == null || nums.length < 3 ) {\n            return 0;\n        }\n        int n = nums.length;\n        int[] prefixSum = new int[n];\n        int curSum = 0;\n        for (int i = 0; i < n; i++) {\n            curSum += nums[i];\n            prefixSum[i] = curSum;\n        }\n\n        long res = 0;\n        for (int i = 0; i < n; i++) {\n            int part1 = prefixSum[i];\n            int left = i + 1;\n            int right = n - 2;\n\n            int cut1 = -1;\n            int cut2 = -1;\n            while (left <= right) {\n                int mid = left + (right - left) / 2;\n                int part2 = prefixSum[mid] - part1;\n                if (part2 >= part1) {  \n                // cut1 should be as left as possible\n                    cut1 = mid;\n                    right = mid - 1;\n                } else {\n                    left = mid + 1;\n                }\n            }\n\n            left = i + 1;\n            right = n - 2;\n            while (left <= right) {\n                int mid = left + (right - left) / 2;\n                int part2 = prefixSum[mid] - part1;\n                int part3 = prefixSum[n - 1] - prefixSum[mid];\n                if (part3 >= part2) {\n                // cut2 should be as right as possible\n                    cut2 = mid;\n                    left = mid + 1;\n                } else {\n                    right = mid - 1;\n                }\n            } \n\n            if (cut1 == -1 || cut2 == -1 || cut1 > cut2) {\n                continue;\n            }\n            int curcnt = cut2 - cut1 + 1;\n            res += curcnt;\n            res %= MOD;\n\n        } \n        return (int) res;\n\n    }\n}\n        \n\n\n```
['Java']