Method
splitArray
(self, nums: List[int], m: int)
Source from the content-addressed store, hash-verified
| 1 | class Solution: |
| 2 | def splitArray(self, nums: List[int], m: int) -> int: |
| 3 | def canSplit(largest): |
| 4 | subarray = 0 |
| 5 | curSum = 0 |
| 6 | for n in nums: |
| 7 | curSum += n |
| 8 | if curSum > largest: |
| 9 | subarray += 1 |
| 10 | curSum = n |
| 11 | return subarray + 1 <= m |
| 12 | |
| 13 | l, r = max(nums), sum(nums) |
| 14 | res = r |
| 15 | while l <= r: |
| 16 | mid = l + ((r - l) // 2) |
| 17 | if canSplit(mid): |
| 18 | res = mid |
| 19 | r = mid - 1 |
| 20 | else: |
| 21 | l = mid + 1 |
| 22 | return res |
Callers
nothing calls this directly
Tested by
no test coverage detected