-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathL410.py
More file actions
37 lines (27 loc) · 841 Bytes
/
Copy pathL410.py
File metadata and controls
37 lines (27 loc) · 841 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
36
37
# 410. 分割数组的最大值
from typing import List
class Solution:
def dfs(self, start, partition, nums):
if partition == 0 and start != len(nums):
s = 0
for i in range(start, len(nums)):
s += nums[i]
return s
if len(nums) - 1 - start < partition:
return
ans = 0
for i in range(start, len(nums)):
t = self.dfs(i, partition - 1, nums)
ans = ans if ans >= t else t
return ans
def splitArray(self, nums: List[int], k: int) -> int:
n = len(nums)
# array = [0] * n
ans = nums[0]
s = nums[0]
for i in range(1, n):
t = self.dfs(i, k - 1, nums)
ans = ans if ans < t else t
s += nums[i]
if __name__ == '__main__':
pass