Skip to content

Commit 834252b

Browse files
committed
add
1 parent 165d1cd commit 834252b

8 files changed

+528
-4
lines changed

1.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
from requests.exceptions import RequestException
99
from bs4 import BeautifulSoup
1010

11-
import random
12-
1311
def get_proble_set(url):
1412
try:
1513
response = requests.get(url)
@@ -21,8 +19,8 @@ def get_proble_set(url):
2119

2220
def parse_proble_set(problemSet):
2321
# print(len(problemSet)) # 2218
24-
# for i in range(len(problemSet)):
25-
for i in range(930, len(problemSet)):
22+
for i in range(len(problemSet)):
23+
# for i in range(930, len(problemSet)):
2624
title = problemSet[i]["stat"]["question__title_slug"]
2725
if os.path.exists("[no content]{}.json".format(title)) or os.path.exists("{}.json".format(title)):
2826
print(i, "has been parsed.")
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"data": {
3+
"question": {
4+
"questionId": "1339",
5+
"questionFrontendId": "1212",
6+
"boundTopicId": null,
7+
"title": "Team Scores in Football Tournament",
8+
"titleSlug": "team-scores-in-football-tournament",
9+
"content": null,
10+
"translatedTitle": null,
11+
"translatedContent": null,
12+
"isPaidOnly": true,
13+
"difficulty": "Medium",
14+
"likes": 226,
15+
"dislikes": 19,
16+
"isLiked": null,
17+
"similarQuestions": "[]",
18+
"exampleTestcases": "{\"headers\": {\"Teams\": [\"team_id\", \"team_name\"], \"Matches\": [\"match_id\", \"host_team\", \"guest_team\", \"host_goals\", \"guest_goals\"]}, \"rows\": {\"Teams\": [[10, \"Leetcode FC\"], [20, \"NewYork FC\"], [30, \"Atlanta FC\"], [40, \"Chicago FC\"], [50, \"Toronto FC\"]], \"Matches\": [[1, 10, 20, 3, 0], [2, 30, 10, 2, 2], [3, 10, 50, 5, 1], [4, 20, 30, 1, 0], [5, 50, 30, 1, 0]]}}",
19+
"categoryTitle": "Database",
20+
"contributors": [],
21+
"topicTags": [
22+
{
23+
"name": "Database",
24+
"slug": "database",
25+
"translatedName": null,
26+
"__typename": "TopicTagNode"
27+
}
28+
],
29+
"companyTagStats": null,
30+
"codeSnippets": null,
31+
"stats": "{\"totalAccepted\": \"24.2K\", \"totalSubmission\": \"42.2K\", \"totalAcceptedRaw\": 24194, \"totalSubmissionRaw\": 42249, \"acRate\": \"57.3%\"}",
32+
"hints": [],
33+
"solution": null,
34+
"status": null,
35+
"sampleTestCase": "{\"headers\": {\"Teams\": [\"team_id\", \"team_name\"], \"Matches\": [\"match_id\", \"host_team\", \"guest_team\", \"host_goals\", \"guest_goals\"]}, \"rows\": {\"Teams\": [[10, \"Leetcode FC\"], [20, \"NewYork FC\"], [30, \"Atlanta FC\"], [40, \"Chicago FC\"], [50, \"Toronto FC\"]], \"Matches\": [[1, 10, 20, 3, 0], [2, 30, 10, 2, 2], [3, 10, 50, 5, 1], [4, 20, 30, 1, 0], [5, 50, 30, 1, 0]]}}",
36+
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Teams (team_id int, team_name varchar(30))\",\n \"Create table If Not Exists Matches (match_id int, host_team int, guest_team int, host_goals int, guest_goals int)\"\n ],\n \"mssql\": [\n \"Create table Teams (team_id int, team_name varchar(30))\",\n \"Create table Matches (match_id int, host_team int, guest_team int, host_goals int, guest_goals int)\"\n ],\n \"oraclesql\": [\n \"Create table Teams (team_id int, team_name varchar(30))\",\n \"Create table Matches (match_id int, host_team int, guest_team int, host_goals int, guest_goals int)\"\n ],\n \"database\": true\n}",
37+
"judgerAvailable": true,
38+
"judgeType": "large",
39+
"mysqlSchemas": [
40+
"Create table If Not Exists Teams (team_id int, team_name varchar(30))",
41+
"Create table If Not Exists Matches (match_id int, host_team int, guest_team int, host_goals int, guest_goals int)",
42+
"Truncate table Teams",
43+
"insert into Teams (team_id, team_name) values ('10', 'Leetcode FC')",
44+
"insert into Teams (team_id, team_name) values ('20', 'NewYork FC')",
45+
"insert into Teams (team_id, team_name) values ('30', 'Atlanta FC')",
46+
"insert into Teams (team_id, team_name) values ('40', 'Chicago FC')",
47+
"insert into Teams (team_id, team_name) values ('50', 'Toronto FC')",
48+
"Truncate table Matches",
49+
"insert into Matches (match_id, host_team, guest_team, host_goals, guest_goals) values ('1', '10', '20', '3', '0')",
50+
"insert into Matches (match_id, host_team, guest_team, host_goals, guest_goals) values ('2', '30', '10', '2', '2')",
51+
"insert into Matches (match_id, host_team, guest_team, host_goals, guest_goals) values ('3', '10', '50', '5', '1')",
52+
"insert into Matches (match_id, host_team, guest_team, host_goals, guest_goals) values ('4', '20', '30', '1', '0')",
53+
"insert into Matches (match_id, host_team, guest_team, host_goals, guest_goals) values ('5', '50', '30', '1', '0')"
54+
],
55+
"enableRunCode": true,
56+
"enableTestMode": false,
57+
"enableDebugger": false,
58+
"envInfo": "{\"mysql\": [\"MySQL\", \"<p><code>MySQL 8.0</code>.</p>\"], \"mssql\": [\"MS SQL Server\", \"<p><code>mssql server 2019</code>.</p>\"], \"oraclesql\": [\"Oracle\", \"<p><code>Oracle Sql 11.2</code>.</p>\"]}",
59+
"libraryUrl": null,
60+
"adminUrl": null,
61+
"challengeQuestion": null,
62+
"__typename": "QuestionNode"
63+
}
64+
}
65+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<p>There is an integer array <code>nums</code> sorted in ascending order (with <strong>distinct</strong> values).</p>
2+
3+
<p>Prior to being passed to your function, <code>nums</code> is <strong>possibly rotated</strong> at an unknown pivot index <code>k</code> (<code>1 &lt;= k &lt; nums.length</code>) such that the resulting array is <code>[nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]]</code> (<strong>0-indexed</strong>). For example, <code>[0,1,2,4,5,6,7]</code> might be rotated at pivot index <code>3</code> and become <code>[4,5,6,7,0,1,2]</code>.</p>
4+
5+
<p>Given the array <code>nums</code> <strong>after</strong> the possible rotation and an integer <code>target</code>, return <em>the index of </em><code>target</code><em> if it is in </em><code>nums</code><em>, or </em><code>-1</code><em> if it is not in </em><code>nums</code>.</p>
6+
7+
<p>You must write an algorithm with <code>O(log n)</code> runtime complexity.</p>
8+
9+
<p>&nbsp;</p>
10+
<p><strong>Example 1:</strong></p>
11+
<pre><strong>Input:</strong> nums = [4,5,6,7,0,1,2], target = 0
12+
<strong>Output:</strong> 4
13+
</pre><p><strong>Example 2:</strong></p>
14+
<pre><strong>Input:</strong> nums = [4,5,6,7,0,1,2], target = 3
15+
<strong>Output:</strong> -1
16+
</pre><p><strong>Example 3:</strong></p>
17+
<pre><strong>Input:</strong> nums = [1], target = 0
18+
<strong>Output:</strong> -1
19+
</pre>
20+
<p>&nbsp;</p>
21+
<p><strong>Constraints:</strong></p>
22+
23+
<ul>
24+
<li><code>1 &lt;= nums.length &lt;= 5000</code></li>
25+
<li><code>-10<sup>4</sup> &lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
26+
<li>All values of <code>nums</code> are <strong>unique</strong>.</li>
27+
<li><code>nums</code> is an ascending array that is possibly rotated.</li>
28+
<li><code>-10<sup>4</sup> &lt;= target &lt;= 10<sup>4</sup></code></li>
29+
</ul>

算法题/search-in-rotated-sorted-array.json

Lines changed: 172 additions & 0 deletions
Large diffs are not rendered by default.

算法题/second-highest-salary.html

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<p>Table: <code>Employee</code></p>
2+
3+
<pre>
4+
+-------------+------+
5+
| Column Name | Type |
6+
+-------------+------+
7+
| id | int |
8+
| salary | int |
9+
+-------------+------+
10+
id is the primary key column for this table.
11+
Each row of this table contains information about the salary of an employee.
12+
</pre>
13+
14+
<p>&nbsp;</p>
15+
16+
<p>Write an SQL query to report the second highest salary from the <code>Employee</code> table. If there is no second highest salary, the query should report <code>null</code>.</p>
17+
18+
<p>The query result format is in the following example.</p>
19+
20+
<p>&nbsp;</p>
21+
<p><strong>Example 1:</strong></p>
22+
23+
<pre>
24+
<strong>Input:</strong>
25+
Employee table:
26+
+----+--------+
27+
| id | salary |
28+
+----+--------+
29+
| 1 | 100 |
30+
| 2 | 200 |
31+
| 3 | 300 |
32+
+----+--------+
33+
<strong>Output:</strong>
34+
+---------------------+
35+
| SecondHighestSalary |
36+
+---------------------+
37+
| 200 |
38+
+---------------------+
39+
</pre>
40+
41+
<p><strong>Example 2:</strong></p>
42+
43+
<pre>
44+
<strong>Input:</strong>
45+
Employee table:
46+
+----+--------+
47+
| id | salary |
48+
+----+--------+
49+
| 1 | 100 |
50+
+----+--------+
51+
<strong>Output:</strong>
52+
+---------------------+
53+
| SecondHighestSalary |
54+
+---------------------+
55+
| null |
56+
+---------------------+
57+
</pre>

算法题/second-highest-salary.json

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{
2+
"data": {
3+
"question": {
4+
"questionId": "176",
5+
"questionFrontendId": "176",
6+
"boundTopicId": null,
7+
"title": "Second Highest Salary",
8+
"titleSlug": "second-highest-salary",
9+
"content": "<p>Table: <code>Employee</code></p>\n\n<pre>\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| id | int |\n| salary | int |\n+-------------+------+\nid is the primary key column for this table.\nEach row of this table contains information about the salary of an employee.\n</pre>\n\n<p>&nbsp;</p>\n\n<p>Write an SQL query to report the second highest salary from the <code>Employee</code> table. If there is no second highest salary, the query should report <code>null</code>.</p>\n\n<p>The query result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong>Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \nEmployee table:\n+----+--------+\n| id | salary |\n+----+--------+\n| 1 | 100 |\n| 2 | 200 |\n| 3 | 300 |\n+----+--------+\n<strong>Output:</strong> \n+---------------------+\n| SecondHighestSalary |\n+---------------------+\n| 200 |\n+---------------------+\n</pre>\n\n<p><strong>Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> \nEmployee table:\n+----+--------+\n| id | salary |\n+----+--------+\n| 1 | 100 |\n+----+--------+\n<strong>Output:</strong> \n+---------------------+\n| SecondHighestSalary |\n+---------------------+\n| null |\n+---------------------+\n</pre>\n",
10+
"translatedTitle": null,
11+
"translatedContent": null,
12+
"isPaidOnly": false,
13+
"difficulty": "Medium",
14+
"likes": 1716,
15+
"dislikes": 695,
16+
"isLiked": null,
17+
"similarQuestions": "[]",
18+
"exampleTestcases": "{\"headers\":{\"Employee\":[\"id\",\"salary\"]},\"rows\":{\"Employee\":[[1,100],[2,200],[3,300]]}}\n{\"headers\":{\"Employee\":[\"id\",\"salary\"]},\"rows\":{\"Employee\":[[1,100]]}}",
19+
"categoryTitle": "Database",
20+
"contributors": [],
21+
"topicTags": [
22+
{
23+
"name": "Database",
24+
"slug": "database",
25+
"translatedName": null,
26+
"__typename": "TopicTagNode"
27+
}
28+
],
29+
"companyTagStats": null,
30+
"codeSnippets": [
31+
{
32+
"lang": "MySQL",
33+
"langSlug": "mysql",
34+
"code": "# Write your MySQL query statement below\n",
35+
"__typename": "CodeSnippetNode"
36+
},
37+
{
38+
"lang": "MS SQL Server",
39+
"langSlug": "mssql",
40+
"code": "/* Write your T-SQL query statement below */\n",
41+
"__typename": "CodeSnippetNode"
42+
},
43+
{
44+
"lang": "Oracle",
45+
"langSlug": "oraclesql",
46+
"code": "/* Write your PL/SQL query statement below */\n",
47+
"__typename": "CodeSnippetNode"
48+
}
49+
],
50+
"stats": "{\"totalAccepted\": \"452.9K\", \"totalSubmission\": \"1.3M\", \"totalAcceptedRaw\": 452894, \"totalSubmissionRaw\": 1289634, \"acRate\": \"35.1%\"}",
51+
"hints": [],
52+
"solution": {
53+
"id": "217",
54+
"canSeeDetail": true,
55+
"paidOnly": false,
56+
"hasVideoSolution": false,
57+
"paidOnlyVideo": true,
58+
"__typename": "ArticleNode"
59+
},
60+
"status": null,
61+
"sampleTestCase": "{\"headers\":{\"Employee\":[\"id\",\"salary\"]},\"rows\":{\"Employee\":[[1,100],[2,200],[3,300]]}}",
62+
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Employee (id int, salary int)\"\n ],\n \"mssql\": [\n \"Create table Employee (id int, salary int)\"\n ],\n \"oraclesql\": [\n \"Create table Employee (id int, salary int)\"\n ],\n \"database\": true\n}",
63+
"judgerAvailable": true,
64+
"judgeType": "large",
65+
"mysqlSchemas": [
66+
"Create table If Not Exists Employee (id int, salary int)",
67+
"Truncate table Employee",
68+
"insert into Employee (id, salary) values ('1', '100')",
69+
"insert into Employee (id, salary) values ('2', '200')",
70+
"insert into Employee (id, salary) values ('3', '300')"
71+
],
72+
"enableRunCode": true,
73+
"enableTestMode": false,
74+
"enableDebugger": false,
75+
"envInfo": "{\"mysql\": [\"MySQL\", \"<p><code>MySQL 8.0</code>.</p>\"], \"mssql\": [\"MS SQL Server\", \"<p><code>mssql server 2019</code>.</p>\"], \"oraclesql\": [\"Oracle\", \"<p><code>Oracle Sql 11.2</code>.</p>\"]}",
76+
"libraryUrl": null,
77+
"adminUrl": null,
78+
"challengeQuestion": null,
79+
"__typename": "QuestionNode"
80+
}
81+
}
82+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<p>Five silent philosophers&nbsp;sit at a round table with bowls of spaghetti. Forks are placed between each pair of adjacent philosophers.</p>
2+
3+
<p>Each philosopher must alternately think and eat. However, a philosopher can only eat spaghetti when they have both left and right forks. Each fork can be held by only one philosopher and so a philosopher can use the fork only if it is not being used by another philosopher. After an individual philosopher finishes eating, they need to put down both forks so that the forks become available to others. A philosopher can take the fork on their right or the one on their left as they become available, but cannot start eating before getting both forks.</p>
4+
5+
<p>Eating is not limited by the remaining amounts of spaghetti or stomach space; an infinite supply and an infinite demand are assumed.</p>
6+
7+
<p>Design a discipline of behaviour (a concurrent algorithm) such that no philosopher will starve;&nbsp;<i>i.e.</i>, each can forever continue to alternate between eating and thinking, assuming that no philosopher can know when others may want to eat or think.</p>
8+
9+
<p style="text-align: center"><img alt="" src="https://assets.leetcode.com/uploads/2019/09/24/an_illustration_of_the_dining_philosophers_problem.png" style="width: 400px; height: 415px;" /></p>
10+
11+
<p style="text-align: center"><em>The problem statement and the image above are taken from <a href="https://en.wikipedia.org/wiki/Dining_philosophers_problem" target="_blank">wikipedia.org</a></em></p>
12+
13+
<p>&nbsp;</p>
14+
15+
<p>The philosophers&#39; ids are numbered from <strong>0</strong> to <strong>4</strong> in a <strong>clockwise</strong> order. Implement the function&nbsp;<code>void wantsToEat(philosopher, pickLeftFork, pickRightFork, eat, putLeftFork, putRightFork)</code> where:</p>
16+
17+
<ul>
18+
<li><code>philosopher</code>&nbsp;is the id of the philosopher who wants to eat.</li>
19+
<li><code>pickLeftFork</code>&nbsp;and&nbsp;<code>pickRightFork</code>&nbsp;are functions you can call to pick the corresponding forks of that philosopher.</li>
20+
<li><code>eat</code>&nbsp;is a function you can call to let the philosopher eat once he has picked&nbsp;both forks.</li>
21+
<li><code>putLeftFork</code>&nbsp;and&nbsp;<code>putRightFork</code>&nbsp;are functions you can call to put down the corresponding forks of that philosopher.</li>
22+
<li>The philosophers are assumed to be thinking as long as they are not asking to eat (the function is not being called with their number).</li>
23+
</ul>
24+
25+
<p>Five threads, each representing a philosopher, will&nbsp;simultaneously use one object of your class to simulate the process. The function may be called for the same philosopher more than once, even before the last call ends.</p>
26+
27+
<p>&nbsp;</p>
28+
<p><strong>Example 1:</strong></p>
29+
30+
<pre>
31+
<strong>Input:</strong> n = 1
32+
<strong>Output:</strong> [[4,2,1],[4,1,1],[0,1,1],[2,2,1],[2,1,1],[2,0,3],[2,1,2],[2,2,2],[4,0,3],[4,1,2],[0,2,1],[4,2,2],[3,2,1],[3,1,1],[0,0,3],[0,1,2],[0,2,2],[1,2,1],[1,1,1],[3,0,3],[3,1,2],[3,2,2],[1,0,3],[1,1,2],[1,2,2]]
33+
<strong>Explanation:</strong>
34+
n is the number of times each philosopher will call the function.
35+
The output array describes the calls you made to the functions controlling the forks and the eat function, its format is:
36+
output[i] = [a, b, c] (three integers)
37+
- a is the id of a philosopher.
38+
- b specifies the fork: {1 : left, 2 : right}.
39+
- c specifies the operation: {1 : pick, 2 : put, 3 : eat}.</pre>
40+
41+
<p>&nbsp;</p>
42+
<p><strong>Constraints:</strong></p>
43+
44+
<ul>
45+
<li><code>1 &lt;= n &lt;= 60</code></li>
46+
</ul>

0 commit comments

Comments
 (0)