-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathq0410.py
More file actions
37 lines (32 loc) · 881 Bytes
/
q0410.py
File metadata and controls
37 lines (32 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/python3
from typing import List
class Solution:
def splitArray(self, nums: List[int], m: int) -> int:
def vaild(sum_try):
count = 1
sum = 0
for number in nums:
sum += number
if sum > sum_try:
sum = number
count += 1
return count <= m
sum = 0
maxVal = nums[0]
for number in nums:
sum += number
if maxVal < number:
maxVal = number
if m >= len(nums):
return maxVal
left = maxVal
right = sum
result = 0
while left <= right:
mid = (left + right) // 2
if vaild(mid):
result = mid
right = mid - 1
else:
left = mid + 1
return result