Skip to content

Commit ad35cf2

Browse files
author
Shuo
authored
Merge pull request #731 from openset/develop
Add: desc
2 parents 2e3e8b0 + f3f5293 commit ad35cf2

File tree

5 files changed

+220
-1
lines changed

5 files changed

+220
-1
lines changed

internal/leetcode/question_data.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ func (question *questionType) Restore() {
236236
if len(matches) >= 2 {
237237
return
238238
}
239-
question.Content = string(matches[1])
239+
question.Content = string(bytes.TrimSpace(matches[1]))
240240
name := fmt.Sprintf(questionDataFile, question.TitleSnake())
241241
filePutContents(getCachePath(name), jsonEncode(QuestionDataType{
242242
Data: dataType{Question: *question},

problems/all-people-report-to-the-given-manager/README.md

+51
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,55 @@
1111

1212
## [1270. All People Report to the Given Manager (Medium)](https://leetcode.com/problems/all-people-report-to-the-given-manager "")
1313

14+
<p>Table: <code>Employees</code></p>
15+
<pre>
16+
+---------------+---------+
17+
| Column Name | Type |
18+
+---------------+---------+
19+
| employee_id | int |
20+
| employee_name | varchar |
21+
| manager_id | int |
22+
+---------------+---------+
23+
employee_id is the primary key for this table.
24+
Each row of this table indicates that the employee with ID employee_id and name employee_name reports his work to his/her direct manager with manager_id
25+
The head of the company is the employee with employee_id = 1.
26+
</pre>
1427

28+
Write an SQL query to find employee_id of all employees that directly or indirectly report their work to the head of the company.
29+
30+
The indirect relation between managers will not exceed 3 managers as the company is small.
31+
32+
Return result table in any order without duplicates.
33+
34+
The query result format is in the following example:
35+
<pre>
36+
Employees table:
37+
+-------------+---------------+------------+
38+
| employee_id | employee_name | manager_id |
39+
+-------------+---------------+------------+
40+
| 1 | Boss | 1 |
41+
| 3 | Alice | 3 |
42+
| 2 | Bob | 1 |
43+
| 4 | Daniel | 2 |
44+
| 7 | Luis | 4 |
45+
| 8 | Jhon | 3 |
46+
| 9 | Angela | 8 |
47+
| 77 | Robert | 1 |
48+
+-------------+---------------+------------+
49+
50+
Result table:
51+
+-------------+
52+
| employee_id |
53+
+-------------+
54+
| 2 |
55+
| 77 |
56+
| 4 |
57+
| 7 |
58+
+-------------+
59+
60+
The head of the company is the employee with employee_id 1.
61+
The employees with employee_id 2 and 77 report their work directly to the head of the company.
62+
The employee with employee_id 4 report his work indirectly to the head of the company 4 --> 2 --> 1.
63+
The employee with employee_id 7 report his work indirectly to the head of the company 7 --> 4 --> 2 --> 1.
64+
The employees with employee_id 3, 8 and 9 don't report their work to head of company directly or indirectly.
65+
</pre>

problems/page-recommendations/README.md

+72
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,76 @@
1111

1212
## [1264. Page Recommendations (Medium)](https://leetcode.com/problems/page-recommendations "")
1313

14+
<p>Table: <code>Friendship</code></p>
15+
<pre>
16+
+---------------+---------+
17+
| Column Name | Type |
18+
+---------------+---------+
19+
| user1_id | int |
20+
| user2_id | int |
21+
+---------------+---------+
22+
(user1_id, user2_id) is the primary key for this table.
23+
Each row of this table indicates that there is a friendship relation between user1_id and user2_id.
24+
</pre>
25+
26+
<p>Table: <code>Likes</code></p>
27+
<pre>
28+
+-------------+---------+
29+
| Column Name | Type |
30+
+-------------+---------+
31+
| user_id | int |
32+
| page_id | int |
33+
+-------------+---------+
34+
(user_id, page_id) is the primary key for this table.
35+
Each row of this table indicates that user_id likes page_id.
36+
</pre>
37+
38+
Write an SQL query to recommend pages to the user with user_id = 1 using the pages that your friends liked. It should not recommend pages you already liked.
1439

40+
Return result table in any order without duplicates.
41+
42+
The query result format is in the following example:
43+
<pre>
44+
Friendship table:
45+
+----------+----------+
46+
| user1_id | user2_id |
47+
+----------+----------+
48+
| 1 | 2 |
49+
| 1 | 3 |
50+
| 1 | 4 |
51+
| 2 | 3 |
52+
| 2 | 4 |
53+
| 2 | 5 |
54+
| 6 | 1 |
55+
+----------+----------+
56+
57+
Likes table:
58+
+---------+---------+
59+
| user_id | page_id |
60+
+---------+---------+
61+
| 1 | 88 |
62+
| 2 | 23 |
63+
| 3 | 24 |
64+
| 4 | 56 |
65+
| 5 | 11 |
66+
| 6 | 33 |
67+
| 2 | 77 |
68+
| 3 | 77 |
69+
| 6 | 88 |
70+
+---------+---------+
71+
72+
Result table:
73+
+------------------+
74+
| recommended_page |
75+
+------------------+
76+
| 23 |
77+
| 24 |
78+
| 56 |
79+
| 33 |
80+
| 77 |
81+
+------------------+
82+
User one is friend with users 2, 3, 4 and 6.
83+
Suggested pages are 23 from user 2, 24 from user 3, 56 from user 3 and 33 from user 6.
84+
Page 77 is suggested from both user 2 and user 3.
85+
Page 88 is not suggested because user 1 already likes it.
86+
</pre>

problems/print-immutable-linked-list-in-reverse/README.md

+37
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,41 @@
1111

1212
## [1265. Print Immutable Linked List in Reverse (Medium)](https://leetcode.com/problems/print-immutable-linked-list-in-reverse "")
1313

14+
You are given an immutable linked list, print out all values of each node in reverse with the help of the following interface:
1415

16+
- ImmutableListNode: An interface of immutable linked list, you are given the head of the list.
17+
You need to use the following functions to access the linked list (you can't access the ImmutableListNode directly):
18+
19+
- ImmutableListNode.printValue(): Print value of the current node.
20+
- ImmutableListNode.getNext(): Return the next node.
21+
The input is only given to initialize the linked list internally. You must solve this problem without modifying the linked list. In other words, you must operate the linked list using only the mentioned APIs.
22+
23+
Follow up:
24+
25+
Could you solve this problem in:
26+
27+
- Constant space complexity?
28+
- Linear time complexity and less than linear space complexity?
29+
30+
<p><b>Example 1:</b></p>
31+
<pre>
32+
Input: head = [1,2,3,4]
33+
Output: [4,3,2,1]
34+
</pre>
35+
36+
<p><b>Example 2:</b></p>
37+
<pre>
38+
Input: head = [0,-4,-1,3,-5]
39+
Output: [-5,3,-1,-4,0]
40+
</pre>
41+
42+
<p><b>Example 3:</b></p>
43+
<pre>
44+
Input: head = [-2,0,6,4,4,-6]
45+
Output: [-6,4,4,6,0,-2]
46+
</pre>
47+
48+
Constraints:
49+
50+
- The length of the linked list is between [1, 1000].
51+
- The value of each node in the linked list is between [-1000, 1000].

problems/traffic-light-controlled-intersection/README.md

+59
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,63 @@ Next >
1111

1212
## [1279. Traffic Light Controlled Intersection (Easy)](https://leetcode.com/problems/traffic-light-controlled-intersection "")
1313

14+
There is an intersection of two roads. First road is road A where cars travel from North to South in direction 1 and from South to North in direction 2. Second road is road B where cars travel from West to East in direction 3 and from East to West in direction 4.
1415

16+
There is a traffic light located on each road before the intersection. A traffic light can either be green or red.
17+
18+
1. Green means cars can cross the intersection in both directions of the road.
19+
- Red means cars in both directions cannot cross the intersection and must wait until the light turns green.
20+
21+
The traffic lights cannot be green on both roads at the same time. That means when the light is green on road A, it is red on road B and when the light is green on road B, it is red on road A.
22+
23+
Initially, the traffic light is green on road A and red on road B. When the light is green on one road, all cars can cross the intersection in both directions until the light becomes green on the other road. No two cars traveling on different roads should cross at the same time.
24+
25+
Design a deadlock-free traffic light controlled system at this intersection.
26+
27+
Implement the function void carArrived(carId, roadId, direction, turnGreen, crossCar) where:
28+
29+
- carId is the id of the car that arrived.
30+
- roadId is the id of the road that the car travels on.
31+
- direction is the direction of the car.
32+
- turnGreen is a function you can call to turn the traffic light to green on the current road.
33+
- crossCar is a function you can call to let the current car cross the intersection.
34+
35+
Your answer is considered correct if it avoids cars deadlock in the intersection. Turning the light green on a road when it was already green is considered a wrong answer.
36+
37+
<p><b>Example 1:</b></p>
38+
<pre>
39+
Input: cars = [1,3,5,2,4], directions = [2,1,2,4,3], arrivalTimes = [10,20,30,40,50]
40+
Output: [
41+
"Car 1 Has Passed Road A In Direction 2", // Traffic light on road A is green, car 1 can cross the intersection.
42+
"Car 3 Has Passed Road A In Direction 1", // Car 3 crosses the intersection as the light is still green.
43+
"Car 5 Has Passed Road A In Direction 2", // Car 5 crosses the intersection as the light is still green.
44+
"Traffic Light On Road B Is Green", // Car 2 requests green light for road B.
45+
"Car 2 Has Passed Road B In Direction 4", // Car 2 crosses as the light is green on road B now.
46+
"Car 4 Has Passed Road B In Direction 3" // Car 4 crosses the intersection as the light is still green.
47+
]
48+
</pre>
49+
50+
<p><b>Example 2:</b></p>
51+
<pre>
52+
Input: cars = [1,2,3,4,5], directions = [2,4,3,3,1], arrivalTimes = [10,20,30,40,40]
53+
Output: [
54+
"Car 1 Has Passed Road A In Direction 2", // Traffic light on road A is green, car 1 can cross the intersection.
55+
"Traffic Light On Road B Is Green", // Car 2 requests green light for road B.
56+
"Car 2 Has Passed Road B In Direction 4", // Car 2 crosses as the light is green on road B now.
57+
"Car 3 Has Passed Road B In Direction 3", // Car 3 crosses as the light is green on road B now.
58+
"Traffic Light On Road A Is Green", // Car 5 requests green light for road A.
59+
"Car 5 Has Passed Road A In Direction 1", // Car 5 crosses as the light is green on road A now.
60+
"Traffic Light On Road B Is Green", // Car 4 requests green light for road B. Car 4 blocked until car 5 crosses and then traffic light is green on road B.
61+
"Car 4 Has Passed Road B In Direction 3" // Car 4 crosses as the light is green on road B now.
62+
]
63+
Explanation: This is a dead-lock free scenario. Note that the scenario when car 4 crosses before turning light into green on road A and allowing car 5 to pass is also correct and Accepted scenario.
64+
</pre>
65+
66+
Constraints:
67+
68+
- 1 <= cars.length <= 20
69+
- cars.length = directions.length
70+
- cars.length = arrivalTimes.length
71+
- All values of cars are unique
72+
- 1 <= directions[i] <= 4
73+
- arrivalTimes is non-decreasing

0 commit comments

Comments
 (0)