题目描述
思路
- 二分
class Solution:
def splitArray(self, nums: List[int], m: int) -> int:
def check(x: int) -> bool:
total, cnt = 0, 1
for one in nums:
if total + one > x:
cnt += 1
total = one
else:
total += one
return cnt <= m
left = max(nums)
right = sum(nums)
while left < right:
mid = left + (right-left) // 2
if check(mid): # True
right = mid
else:
left = mid+1
return left