Skip to content

Commit de039b2

Browse files
refactor 410
1 parent 88fffe6 commit de039b2

File tree

1 file changed

+2
-29
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+2
-29
lines changed

src/main/java/com/fishercoder/solutions/_410.java

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,15 @@
11
package com.fishercoder.solutions;
22

3-
/**
4-
* 410. Split Array Largest Sum
5-
*
6-
* Given an array which consists of non-negative integers and an integer m,
7-
* you can split the array into m non-empty continuous subarrays.
8-
* Write an algorithm to minimize the largest sum among these m subarrays.
9-
10-
Note:
11-
If n is the length of array, assume the following constraints are satisfied:
12-
13-
1 ≤ n ≤ 1000
14-
1 ≤ m ≤ min(50, n)
15-
16-
Examples:
17-
18-
Input:
19-
nums = [7,2,5,10,8]
20-
m = 2
21-
22-
Output:
23-
18
24-
25-
Explanation:
26-
There are four ways to split nums into two subarrays.
27-
The best way is to split it into [7,2,5] and [10,8],
28-
where the largest sum among the two subarrays is only 18.
29-
*/
303
public class _410 {
314

325
public static class Solution1 {
336
/**
347
* credit: https://discuss.leetcode.com/topic/61324/clear-explanation-8ms-binary-search-java
35-
*
8+
* <p>
369
* The answer is between maximum value of input array numbers and sum of those numbers. Use
3710
* binary search to approach the correct answer. We have l = max number of array; r = sum of all
3811
* numbers in the array; Every time we do mid = (l + r) / 2;
39-
*
12+
* <p>
4013
* Use greedy to narrow down left and right boundaries in binary search. 3.1 Cut the array from
4114
* left. 3.2 Try our best to make sure that the sum of numbers between each two cuts (inclusive)
4215
* is large enough but still less than mid. 3.3 We'll end up with two results: either we can

0 commit comments

Comments
 (0)