Skip to content

Commit a13cb85

Browse files
refactor 725
1 parent ebbeddc commit a13cb85

File tree

1 file changed

+6
-38
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+6
-38
lines changed

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

+6-38
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,11 @@
22

33
import com.fishercoder.common.classes.ListNode;
44

5-
/**
6-
* 725. Split Linked List in Parts
7-
*
8-
* Given a (singly) linked list with head node root,
9-
* write a function to split the linked list into k consecutive linked list "parts".
10-
* The length of each part should be as equal as possible:
11-
* no two parts should have a size differing by more than 1. This may lead to some parts being null.
12-
* The parts should be in order of occurrence in the input list,
13-
* and parts occurring earlier should always have a size greater than or equal parts occurring later.
14-
* Return a List of ListNode's representing the linked list parts that are formed.
15-
16-
Examples 1->2->3->4, k = 5 // 5 equal parts [ [1], [2], [3], [4], null ]
17-
18-
Example 1:
19-
Input:
20-
root = [1, 2, 3], k = 5
21-
Output: [[1],[2],[3],[],[]]
22-
Explanation:
23-
The input and each element of the output are ListNodes, not arrays.
24-
For example, the input root has root.val = 1, root.next.val = 2, \root.next.next.val = 3, and root.next.next.next = null.
25-
The first element output[0] has output[0].val = 1, output[0].next = null.
26-
The last element output[4] is null, but it's string representation as a ListNode is [].
27-
28-
Example 2:
29-
Input:
30-
root = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], k = 3
31-
Output: [[1, 2, 3, 4], [5, 6, 7], [8, 9, 10]]
32-
Explanation:
33-
The input has been split into consecutive parts with size difference at most 1, and earlier parts are a larger size than the later parts.
34-
35-
Note:
36-
The length of root will be in the range [0, 1000].
37-
Each value of a node in the input will be an integer in the range [0, 999].
38-
k will be an integer in the range [1, 50].
39-
40-
*/
415
public class _725 {
426
public static class Solution1 {
43-
/**My very original solution, but verbose.*/
7+
/**
8+
* My very original solution, but verbose.
9+
*/
4410
public ListNode[] splitListToParts(ListNode root, int k) {
4511
int len = getLength(root);
4612
int aveSize = len / k;
@@ -77,7 +43,9 @@ private int getLength(ListNode root) {
7743
}
7844

7945
public static class Solution2 {
80-
/**More concise version*/
46+
/**
47+
* More concise version
48+
*/
8149
public ListNode[] splitListToParts(ListNode root, int k) {
8250
int len = getLength(root);
8351
int aveSize = len / k;

0 commit comments

Comments
 (0)