Skip to content

Commit 8735bff

Browse files
authored
Improved tasks 430, 3044, 3426
1 parent 41c1d45 commit 8735bff

File tree

3 files changed

+27
-12
lines changed
  • src/main/kotlin
    • g0401_0500/s0430_flatten_a_multilevel_doubly_linked_list
    • g3001_3100/s3044_most_frequent_prime
    • g3401_3500/s3426_manhattan_distances_of_all_arrangements_of_pieces

3 files changed

+27
-12
lines changed

src/main/kotlin/g0401_0500/s0430_flatten_a_multilevel_doubly_linked_list/readme.md

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,36 @@ Return _the_ `head` _of the flattened list. The nodes in the list must have **al
1010

1111
**Example 1:**
1212

13-
![](https://assets.leetcode.com/uploads/2021/11/09/flatten11.jpg)
13+
![](https://leetcode-images.github.io/g0401_0500/s0430_flatten_a_multilevel_doubly_linked_list/flatten11.jpg)
1414

1515
**Input:** head = [1,2,3,4,5,6,null,null,null,7,8,9,10,null,null,11,12]
1616

1717
**Output:** [1,2,3,7,8,11,12,9,10,4,5,6]
1818

19-
**Explanation:** The multilevel linked list in the input is shown. After flattening the multilevel linked list it becomes: ![](https://assets.leetcode.com/uploads/2021/11/09/flatten12.jpg)
19+
**Explanation:** The multilevel linked list in the input is shown. After flattening the multilevel linked list it becomes: ![](https://leetcode-images.github.io/g0401_0500/s0430_flatten_a_multilevel_doubly_linked_list/flatten12.jpg)
2020

2121
**Example 2:**
2222

23-
![](https://assets.leetcode.com/uploads/2021/11/09/flatten2.1jpg)
23+
![](https://leetcode-images.github.io/g0401_0500/s0430_flatten_a_multilevel_doubly_linked_list/flatten21.jpg)
2424

2525
**Input:** head = [1,2,null,3]
2626

2727
**Output:** [1,3,2]
2828

29-
**Explanation:** The multilevel linked list in the input is shown. After flattening the multilevel linked list it becomes: ![](https://assets.leetcode.com/uploads/2021/11/24/list.jpg)
29+
**Explanation:**
30+
31+
The multilevel linked list in the input is shown.
32+
After flattening the multilevel linked list it becomes:
33+
34+
![](https://leetcode-images.github.io/g0401_0500/s0430_flatten_a_multilevel_doubly_linked_list/list.jpg)
3035

3136
**Example 3:**
3237

3338
**Input:** head = []
3439

3540
**Output:** []
3641

37-
**Explanation:** There could be empty list in the input.
42+
**Explanation:** There could be empty list in the input.
3843

3944
**Constraints:**
4045

@@ -45,16 +50,26 @@ Return _the_ `head` _of the flattened list. The nodes in the list must have **al
4550

4651
We use the multilevel linked list from **Example 1** above:
4752

48-
1---2---3---4---5---6--NULL | 7---8---9---10--NULL | 11--12--NULL
53+
1---2---3---4---5---6--NULL
54+
|
55+
7---8---9---10--NULL
56+
|
57+
11--12--NULL
4958

5059
The serialization of each level is as follows:
5160

52-
[1,2,3,4,5,6,null] [7,8,9,10,null] [11,12,null]
61+
[1,2,3,4,5,6,null]
62+
[7,8,9,10,null]
63+
[11,12,null]
5364

5465
To serialize all levels together, we will add nulls in each level to signify no node connects to the upper node of the previous level. The serialization becomes:
5566

56-
[1, 2, 3, 4, 5, 6, null] | [null, null, 7, 8, 9, 10, null] | [ null, 11, 12, null]
67+
[1, 2, 3, 4, 5, 6, null]
68+
|
69+
[null, null, 7, 8, 9, 10, null]
70+
|
71+
[ null, 11, 12, null]
5772

5873
Merging the serialization of each level and removing trailing nulls we obtain:
5974

60-
[1,2,3,4,5,6,null,null,null,7,8,9,10,null,null,11,12]
75+
[1,2,3,4,5,6,null,null,null,7,8,9,10,null,null,11,12]

src/main/kotlin/g3001_3100/s3044_most_frequent_prime/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Return _the most frequent prime number **greater** than_ `10` _out of all the nu
1414

1515
**Example 1:**
1616

17-
**![](https://assets.leetcode.com/uploads/2024/02/15/south)**
17+
**![](https://leetcode-images.github.io/g3001_3100/s3044_most_frequent_prime/south.png)**
1818

1919
**Input:** mat = [[1,1],[9,9],[1,1]]
2020

src/main/kotlin/g3401_3500/s3426_manhattan_distances_of_all_arrangements_of_pieces/readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The Manhattan Distance between two cells <code>(x<sub>i</sub>, y<sub>i</sub>)</c
2222

2323
The valid arrangements of pieces on the board are:
2424

25-
![](https://assets.leetcode.com/uploads/2024/12/25/4040example1.drawio)![](https://assets.leetcode.com/uploads/2024/12/25/untitled-diagramdrawio.png)
25+
![](https://leetcode-images.github.io/g3401_3500/s3426_manhattan_distances_of_all_arrangements_of_pieces/untitled-diagramdrawio.png)
2626

2727
* In the first 4 arrangements, the Manhattan distance between the two pieces is 1.
2828
* In the last 2 arrangements, the Manhattan distance between the two pieces is 2.
@@ -39,7 +39,7 @@ Thus, the total Manhattan distance across all valid arrangements is `1 + 1 + 1 +
3939

4040
The valid arrangements of pieces on the board are:
4141

42-
![](https://assets.leetcode.com/uploads/2024/12/25/4040example2drawio.png)
42+
![](https://leetcode-images.github.io/g3401_3500/s3426_manhattan_distances_of_all_arrangements_of_pieces/4040example2drawio.png)
4343

4444
* The first and last arrangements have a total Manhattan distance of `1 + 1 + 2 = 4`.
4545
* The middle two arrangements have a total Manhattan distance of `1 + 2 + 3 = 6`.

0 commit comments

Comments
 (0)