Skip to content

Commit 6d44c84

Browse files
author
Shuo
authored
Merge pull request #740 from openset/develop
Add: new
2 parents e2b23f1 + 2f890ff commit 6d44c84

File tree

4 files changed

+130
-14
lines changed

4 files changed

+130
-14
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <[email protected]> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](https://github.com/openset/leetcode/tree/master/problems/minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix "Minimum Number of Flips to Convert Binary Matrix to Zero Matrix")
9+
                
10+
Next >
11+
12+
## [1285. Find the Start and End Number of Continuous Ranges (Medium)](https://leetcode.com/problems/find-the-start-and-end-number-of-continuous-ranges "")
13+
14+
<p>Table: <code>Logs</code></p>
15+
<pre>
16+
+---------------+---------+
17+
| Column Name | Type |
18+
+---------------+---------+
19+
| log_id | int |
20+
+---------------+---------+
21+
id is the primary key for this table.
22+
Each row of this table contains the ID in a log Table.
23+
</pre>
24+
25+
Since some IDs have been removed from Logs. Write an SQL query to find the start and end number of continuous ranges in table Logs.
26+
27+
Order the result table by start_id.
28+
29+
The query result format is in the following example:
30+
<pre>
31+
Logs table:
32+
+------------+
33+
| log_id |
34+
+------------+
35+
| 1 |
36+
| 2 |
37+
| 3 |
38+
| 7 |
39+
| 8 |
40+
| 10 |
41+
+------------+
42+
43+
Result table:
44+
+------------+--------------+
45+
| start_id | end_id |
46+
+------------+--------------+
47+
| 1 | 3 |
48+
| 7 | 8 |
49+
| 10 | 10 |
50+
+------------+--------------+
51+
The result table should contain all ranges in table Logs.
52+
From 1 to 3 is contained in the table.
53+
From 4 to 6 is missing in the table
54+
From 7 to 8 is contained in the table.
55+
Number 9 is missing in the table.
56+
Number 10 is contained in the table.
57+
</pre>
58+
59+
### Similar Questions
60+
1. [Report Contiguous Dates](https://github.com/openset/leetcode/tree/master/problems/report-contiguous-dates) (Hard)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Create table If Not Exists Logs (log_id int);
2+
Truncate table Logs;
3+
insert into Logs (log_id) values ('1');
4+
insert into Logs (log_id) values ('2');
5+
insert into Logs (log_id) values ('3');
6+
insert into Logs (log_id) values ('7');
7+
insert into Logs (log_id) values ('8');
8+
insert into Logs (log_id) values ('10');

problems/flatten-a-multilevel-doubly-linked-list/README.md

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,84 @@
1616
<p>Flatten the list so that all the nodes appear in a single-level, doubly linked list. You are given the head of the first level of the list.</p>
1717

1818
<p>&nbsp;</p>
19+
<p><strong>Example 1:</strong></p>
1920

20-
<p><strong>Example:</strong></p>
21+
<pre>
22+
<strong>Input:</strong> head = [1,2,3,4,5,6,null,null,null,7,8,9,10,null,null,11,12]
23+
<strong>Output:</strong> [1,2,3,7,8,11,12,9,10,4,5,6]
24+
<strong>Explanation:
25+
</strong>
26+
The multilevel linked list in the input is as follows:
27+
28+
<img src="https://assets.leetcode.com/uploads/2018/10/12/multilevellinkedlist.png" style="width: 640px;" />
29+
30+
After flattening the multilevel linked list it becomes:
31+
32+
<img src="https://assets.leetcode.com/uploads/2018/10/12/multilevellinkedlistflattened.png" style="width: 1100px;" />
33+
</pre>
34+
35+
<p><strong>Example 2:</strong></p>
36+
37+
<pre>
38+
<strong>Input:</strong> head = [1,2,null,3]
39+
<strong>Output:</strong> [1,3,2]
40+
<strong>Explanation:
41+
42+
</strong>The input multilevel linked list is as follows:
43+
44+
1---2---NULL
45+
|
46+
3---NULL
47+
</pre>
48+
49+
<p><strong>Example 3:</strong></p>
50+
51+
<pre>
52+
<strong>Input:</strong> head = []
53+
<strong>Output:</strong> []
54+
</pre>
55+
56+
<p>&nbsp;</p>
57+
58+
<p><strong>How&nbsp;multilevel linked list is represented in test case:</strong></p>
59+
60+
<p>We use the&nbsp;multilevel linked list from <strong>Example 1</strong> above:</p>
2161

2262
<pre>
23-
<strong>Input:</strong>
2463
1---2---3---4---5---6--NULL
2564
|
2665
7---8---9---10--NULL
2766
|
28-
11--12--NULL
67+
11--12--NULL</pre>
68+
69+
<p>The serialization of each level is as follows:</p>
2970

30-
<strong>Output:</strong>
31-
1-2-3-7-8-11-12-9-10-4-5-6-NULL
71+
<pre>
72+
[1,2,3,4,5,6,null]
73+
[7,8,9,10,null]
74+
[11,12,null]
3275
</pre>
3376

34-
<p>&nbsp;</p>
77+
<p>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:</p>
3578

36-
<p><strong>Explanation for the above example:</strong></p>
79+
<pre>
80+
[1,2,3,4,5,6,null]
81+
[null,null,7,8,9,10,null]
82+
[null,11,12,null]
83+
</pre>
3784

38-
<p>Given the following multilevel doubly linked list:</p>
85+
<p>Merging the serialization of each level and removing trailing nulls we obtain:</p>
3986

4087
<pre>
41-
<img src="https://assets.leetcode.com/uploads/2018/10/12/multilevellinkedlist.png" style="width: 640px;" /></pre>
88+
[1,2,3,4,5,6,null,null,null,7,8,9,10,null,null,11,12]</pre>
4289

4390
<p>&nbsp;</p>
91+
<p><strong>Constraints:</strong></p>
4492

45-
<p>We should return the following flattened doubly linked list:</p>
46-
47-
<pre>
48-
<img src="https://assets.leetcode.com/uploads/2018/10/12/multilevellinkedlistflattened.png" style="width: 1100px;" /></pre>
93+
<ul>
94+
<li>Number of Nodes will not exceed 1000.</li>
95+
<li><code>1 &lt;= Node.val &lt;= 10^5</code></li>
96+
</ul>
4997

5098
### Related Topics
5199
[[Depth-first Search](https://github.com/openset/leetcode/tree/master/tag/depth-first-search/README.md)]

problems/minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
[< Previous](https://github.com/openset/leetcode/tree/master/problems/find-the-smallest-divisor-given-a-threshold "Find the Smallest Divisor Given a Threshold")
99

10-
Next >
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/find-the-start-and-end-number-of-continuous-ranges "Find the Start and End Number of Continuous Ranges")
1111

1212
## [1284. Minimum Number of Flips to Convert Binary Matrix to Zero Matrix (Hard)](https://leetcode.com/problems/minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix "转化为全零矩阵的最少反转次数")
1313

0 commit comments

Comments
 (0)