The array is split into three non-empty contiguous subarrays - named left, mid, right respectively from left to right.
The sum of the elements in left is less than or equal to the sum of the elements in mid, and the sum of the elements in mid is less than or equal to the sum of the elements in right.
Given nums, an array of non-negative integers, return the number of good ways to splitnums. As the number may be too large, return it modulo109 + 7.
Example 1:
Input: nums = [1,1,1]
Output: 1
Explanation: The only good way to split nums is [1] [1] [1].
Example 2:
Input: nums = [1,2,2,2,5,0]
Output: 3
Explanation: There are three good ways of splitting nums:
[1] [2] [2,2,5,0]
[1] [2,2] [2,5,0]
[1,2] [2,2] [5,0]
Example 3:
Input: nums = [3,2,1]
Output: 0
Explanation: There is no good way to split nums.
Constraints:
3 <= nums.length <= 105
0 <= nums[i] <= 104
嘛,這題,跟著提示大体想出了做法。但特么的二分分了两个星期还没分对。其实难点是,我们二分找的范围和找到的是什么。一开始,没想清楚二分的条件,以为是leftSum <= midSum <= rightSum。所以很多corner case逃不掉,以为如果不能切的地方我们也要同时判断,所以很麻烦。最后看了答案,发现只要简单数学转换一下,就知道,我们要找的是min i >= leftSum和max i <= remain/2。然后把range规定好就能套九章模板了。