mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
update
This commit is contained in:
parent
9732c4f3bc
commit
0b115f313a
@ -1,6 +1,6 @@
|
||||
# 力扣题库(完整版)
|
||||
|
||||
> 最后更新日期: **2023.05.03**
|
||||
> 最后更新日期: **2023.05.15**
|
||||
>
|
||||
> 使用脚本前请务必仔细完整阅读本 `README.md` 文件
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
161
leetcode-cn/originData/Nsibyl.json
Normal file
161
leetcode-cn/originData/Nsibyl.json
Normal file
File diff suppressed because one or more lines are too long
161
leetcode-cn/originData/W2ZX4X.json
Normal file
161
leetcode-cn/originData/W2ZX4X.json
Normal file
File diff suppressed because one or more lines are too long
55
leetcode-cn/originData/[no content]bikes-last-time-used.json
Normal file
55
leetcode-cn/originData/[no content]bikes-last-time-used.json
Normal file
@ -0,0 +1,55 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2841",
|
||||
"questionFrontendId": "2687",
|
||||
"categoryTitle": "Database",
|
||||
"boundTopicId": 2269584,
|
||||
"title": "Bikes Last Time Used ",
|
||||
"titleSlug": "bikes-last-time-used",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Easy",
|
||||
"likes": 0,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"contributors": [],
|
||||
"langToValidPlayground": null,
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"21\", \"totalSubmission\": \"21\", \"totalAcceptedRaw\": 21, \"totalSubmissionRaw\": 21, \"acRate\": \"100.0%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\":{\"Bikes\":[\"ride_id\",\"bike_number\",\"start_time\",\"end_time\"]},\"rows\":{\"Bikes\":[[1,\"W00576\",\"2012-03-25 11:30:00\",\"2012-03-25 12:40:00\"],[2,\"W00300\",\"2012-03-25 10:30:00\",\"2012-03-25 10:50:00\"],[3,\"W00455\",\"2012-03-26 14:30:00\",\"2012-03-26 17:40:00\"],[4,\"W00455\",\"2012-03-25 12:30:00\",\"2012-03-25 13:40:00\"],[5,\"W00576\",\"2012-03-25 08:10:00\",\"2012-03-25 09:10:00\"],[6,\"W00576\",\"2012-03-28 02:30:00\",\"2012-03-28 02:50:00\"]]}}",
|
||||
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Bikes (ride_id int,bike_number varchar(100), start_time datetime,end_time datetime)\"\n ],\n \"mssql\": [\n \"Create table Bikes (ride_id int,bike_number varchar(100), start_time datetime,end_time datetime)\"\n ],\n \"oraclesql\": [\n \"Create table Bikes (ride_id int,bike_number varchar(100), start_time date,end_time date)\",\n \"ALTER SESSION SET nls_date_format='YYYY-MM-DD HH24:MI:SS'\"\n ],\n \"database\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Create table If Not Exists Bikes (ride_id int,bike_number varchar(100), start_time datetime,end_time datetime)",
|
||||
"Truncate table Bikes",
|
||||
"insert into Bikes (ride_id, bike_number, start_time, end_time) values ('1', 'W00576', '2012-03-25 11:30:00', '2012-03-25 12:40:00')",
|
||||
"insert into Bikes (ride_id, bike_number, start_time, end_time) values ('2', 'W00300', '2012-03-25 10:30:00', '2012-03-25 10:50:00')",
|
||||
"insert into Bikes (ride_id, bike_number, start_time, end_time) values ('3', 'W00455', '2012-03-26 14:30:00', '2012-03-26 17:40:00')",
|
||||
"insert into Bikes (ride_id, bike_number, start_time, end_time) values ('4', 'W00455', '2012-03-25 12:30:00', '2012-03-25 13:40:00')",
|
||||
"insert into Bikes (ride_id, bike_number, start_time, end_time) values ('5', 'W00576', '2012-03-25 08:10:00', '2012-03-25 09:10:00')",
|
||||
"insert into Bikes (ride_id, bike_number, start_time, end_time) values ('6', 'W00576', '2012-03-28 02:30:00', '2012-03-28 02:50:00')"
|
||||
],
|
||||
"enableRunCode": true,
|
||||
"envInfo": "{\"mysql\":[\"MySQL\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"]}",
|
||||
"book": null,
|
||||
"isSubscribed": false,
|
||||
"isDailyQuestion": false,
|
||||
"dailyRecordStatus": null,
|
||||
"editorType": "CKEDITOR",
|
||||
"ugcQuestionId": null,
|
||||
"style": "LEETCODE",
|
||||
"exampleTestcases": "{\"headers\":{\"Bikes\":[\"ride_id\",\"bike_number\",\"start_time\",\"end_time\"]},\"rows\":{\"Bikes\":[[1,\"W00576\",\"2012-03-25 11:30:00\",\"2012-03-25 12:40:00\"],[2,\"W00300\",\"2012-03-25 10:30:00\",\"2012-03-25 10:50:00\"],[3,\"W00455\",\"2012-03-26 14:30:00\",\"2012-03-26 17:40:00\"],[4,\"W00455\",\"2012-03-25 12:30:00\",\"2012-03-25 13:40:00\"],[5,\"W00576\",\"2012-03-25 08:10:00\",\"2012-03-25 09:10:00\"],[6,\"W00576\",\"2012-03-28 02:30:00\",\"2012-03-28 02:50:00\"]]}}",
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2830",
|
||||
"questionFrontendId": "2669",
|
||||
"categoryTitle": "Database",
|
||||
"boundTopicId": 2259120,
|
||||
"title": "Count Artist Occurrences On Spotify Ranking List",
|
||||
"titleSlug": "count-artist-occurrences-on-spotify-ranking-list",
|
||||
"content": null,
|
||||
"translatedTitle": "统计 Spotify 排行榜上艺术家出现次数",
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Easy",
|
||||
"likes": 0,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"contributors": [],
|
||||
"langToValidPlayground": null,
|
||||
"topicTags": [
|
||||
{
|
||||
"name": "Database",
|
||||
"slug": "database",
|
||||
"translatedName": "数据库",
|
||||
"__typename": "TopicTagNode"
|
||||
}
|
||||
],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"71\", \"totalSubmission\": \"90\", \"totalAcceptedRaw\": 71, \"totalSubmissionRaw\": 90, \"acRate\": \"78.9%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\":{\"Spotify\":[\"id\",\"track_name\",\"artist\"]},\"rows\":{\"Spotify\":[[303651,\"Heart Won't Forget\",\"Ed Sheeran\"],[1046089,\"Shape of you\",\"Sia\"],[33445,\"I'm the one\",\"DJ Khalid\"],[811266,\"Young Dumb & Broke\",\"DJ Khalid\"],[505727,\"Happier\",\"Ed Sheeran\"]]}}",
|
||||
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Spotify (id int,track_name varchar(100),artist varchar(100))\"\n ],\n \"mssql\": [\n \"Create table Spotify (id int,track_name varchar(100),artist varchar(100))\"\n ],\n \"oraclesql\": [\n \"Create table Spotify (id int,track_name varchar(100),artist varchar(100))\"\n ],\n \"database\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Create table If Not Exists Spotify (id int,track_name varchar(100),artist varchar(100))",
|
||||
"Truncate table Spotify",
|
||||
"insert into Spotify (id, track_name, artist) values ('303651', 'Heart Won't Forget', 'Ed Sheeran')",
|
||||
"insert into Spotify (id, track_name, artist) values ('1046089', 'Shape of you', 'Sia')",
|
||||
"insert into Spotify (id, track_name, artist) values ('33445', 'I'm the one', 'DJ Khalid')",
|
||||
"insert into Spotify (id, track_name, artist) values ('811266', 'Young Dumb & Broke', 'DJ Khalid')",
|
||||
"insert into Spotify (id, track_name, artist) values ('505727', 'Happier', 'Ed Sheeran')"
|
||||
],
|
||||
"enableRunCode": true,
|
||||
"envInfo": "{\"mysql\":[\"MySQL\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"]}",
|
||||
"book": null,
|
||||
"isSubscribed": false,
|
||||
"isDailyQuestion": false,
|
||||
"dailyRecordStatus": null,
|
||||
"editorType": "CKEDITOR",
|
||||
"ugcQuestionId": null,
|
||||
"style": "LEETCODE",
|
||||
"exampleTestcases": "{\"headers\":{\"Spotify\":[\"id\",\"track_name\",\"artist\"]},\"rows\":{\"Spotify\":[[303651,\"Heart Won't Forget\",\"Ed Sheeran\"],[1046089,\"Shape of you\",\"Sia\"],[33445,\"I'm the one\",\"DJ Khalid\"],[811266,\"Young Dumb & Broke\",\"DJ Khalid\"],[505727,\"Happier\",\"Ed Sheeran\"]]}}",
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
55
leetcode-cn/originData/[no content]find-active-users.json
Normal file
55
leetcode-cn/originData/[no content]find-active-users.json
Normal file
@ -0,0 +1,55 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2842",
|
||||
"questionFrontendId": "2688",
|
||||
"categoryTitle": "Database",
|
||||
"boundTopicId": 2269585,
|
||||
"title": "Find Active Users",
|
||||
"titleSlug": "find-active-users",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Medium",
|
||||
"likes": 0,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"contributors": [],
|
||||
"langToValidPlayground": null,
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"14\", \"totalSubmission\": \"22\", \"totalAcceptedRaw\": 14, \"totalSubmissionRaw\": 22, \"acRate\": \"63.6%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\":{\"Users\":[\"user_id\",\"item\",\"created_at\",\"amount\"]},\"rows\":{\"Users\":[[5,\"Smart Crock Pot\",\"2021-09-18\",698882],[6,\"Smart Lock\",\"2021-09-14\",11487],[6,\"Smart Thermostat\",\"2021-09-10\",674762],[8,\"Smart Light Strip\",\"2021-09-29\",630773],[4,\"Smart Cat Feeder\",\"2021-09-02\",693545],[4,\"Smart Bed\",\"2021-09-13\",170249]]}}",
|
||||
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Users (user_id int, item varchar(100),created_at date,amount int)\"\n ],\n \"mssql\": [\n \"Create table Users (user_id int, item varchar(100),created_at date,amount int)\"\n ],\n \"oraclesql\": [\n \"Create table Users (user_id int, item varchar(100),created_at date,amount int)\",\n \"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"\n ],\n \"database\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Create table If Not Exists Users (user_id int, item varchar(100),created_at date,amount int)",
|
||||
"Truncate table Users",
|
||||
"insert into Users (user_id, item, created_at, amount) values ('5', 'Smart Crock Pot', '2021-09-18', '698882')",
|
||||
"insert into Users (user_id, item, created_at, amount) values ('6', 'Smart Lock', '2021-09-14', '11487')",
|
||||
"insert into Users (user_id, item, created_at, amount) values ('6', 'Smart Thermostat', '2021-09-10', '674762')",
|
||||
"insert into Users (user_id, item, created_at, amount) values ('8', 'Smart Light Strip', '2021-09-29', '630773')",
|
||||
"insert into Users (user_id, item, created_at, amount) values ('4', 'Smart Cat Feeder', '2021-09-02', '693545')",
|
||||
"insert into Users (user_id, item, created_at, amount) values ('4', 'Smart Bed', '2021-09-13', '170249')"
|
||||
],
|
||||
"enableRunCode": true,
|
||||
"envInfo": "{\"mysql\":[\"MySQL\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"]}",
|
||||
"book": null,
|
||||
"isSubscribed": false,
|
||||
"isDailyQuestion": false,
|
||||
"dailyRecordStatus": null,
|
||||
"editorType": "CKEDITOR",
|
||||
"ugcQuestionId": null,
|
||||
"style": "LEETCODE",
|
||||
"exampleTestcases": "{\"headers\":{\"Users\":[\"user_id\",\"item\",\"created_at\",\"amount\"]},\"rows\":{\"Users\":[[5,\"Smart Crock Pot\",\"2021-09-18\",698882],[6,\"Smart Lock\",\"2021-09-14\",11487],[6,\"Smart Thermostat\",\"2021-09-10\",674762],[8,\"Smart Light Strip\",\"2021-09-29\",630773],[4,\"Smart Cat Feeder\",\"2021-09-02\",693545],[4,\"Smart Bed\",\"2021-09-13\",170249]]}}",
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
66
leetcode-cn/originData/[no content]find-latest-salaries.json
Normal file
66
leetcode-cn/originData/[no content]find-latest-salaries.json
Normal file
@ -0,0 +1,66 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2829",
|
||||
"questionFrontendId": "2668",
|
||||
"categoryTitle": "Database",
|
||||
"boundTopicId": 2257550,
|
||||
"title": "Find Latest Salaries",
|
||||
"titleSlug": "find-latest-salaries",
|
||||
"content": null,
|
||||
"translatedTitle": "查询员工当前薪水",
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Easy",
|
||||
"likes": 0,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"contributors": [],
|
||||
"langToValidPlayground": null,
|
||||
"topicTags": [
|
||||
{
|
||||
"name": "Database",
|
||||
"slug": "database",
|
||||
"translatedName": "数据库",
|
||||
"__typename": "TopicTagNode"
|
||||
}
|
||||
],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"79\", \"totalSubmission\": \"109\", \"totalAcceptedRaw\": 79, \"totalSubmissionRaw\": 109, \"acRate\": \"72.5%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\":{\"Salary\":[\"emp_id\",\"firstname\",\"lastname\",\"salary\",\"department_id\"]},\"rows\":{\"Salary\":[[1,\"Todd\",\"Wilson\",110000,\"D1006\"],[1,\"Todd\",\"Wilson\",106119,\"D1006\"],[2,\"Justin\",\"Simon\",128922,\"D1005\"],[2,\"Justin\",\"Simon\",130000,\"D1005\"],[3,\"Kelly\",\"Rosario\",42689,\"D1002\"],[4,\"Patricia\",\"Powell\",162825,\"D1004\"],[4,\"Patricia\",\"Powell\",170000,\"D1004\"],[5,\"Sherry\",\"Golden\",44101,\"D1002\"],[6,\"Natasha\",\"Swanson\",79632,\"D1005\"],[6,\"Natasha\",\"Swanson\",90000,\"D1005\"]]}}",
|
||||
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Salary (emp_id int,firstname varchar(100),lastname varchar(100),salary int, department_id varchar(100))\"\n ],\n \"mssql\": [\n \"Create table Salary (emp_id int,firstname varchar(100),lastname varchar(100),salary int, department_id varchar(100))\"\n ],\n \"oraclesql\": [\n \"Create table Salary (emp_id int,firstname varchar(100),lastname varchar(100),salary int, department_id varchar(100))\"\n ],\n \"database\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Create table If Not Exists Salary (emp_id int,firstname varchar(100),lastname varchar(100),salary int, department_id varchar(100))",
|
||||
"Truncate table Salary",
|
||||
"insert into Salary (emp_id, firstname, lastname, salary, department_id) values ('1', 'Todd', 'Wilson', '110000', 'D1006')",
|
||||
"insert into Salary (emp_id, firstname, lastname, salary, department_id) values ('1', 'Todd', 'Wilson', '106119', 'D1006')",
|
||||
"insert into Salary (emp_id, firstname, lastname, salary, department_id) values ('2', 'Justin', 'Simon', '128922', 'D1005')",
|
||||
"insert into Salary (emp_id, firstname, lastname, salary, department_id) values ('2', 'Justin', 'Simon', '130000', 'D1005')",
|
||||
"insert into Salary (emp_id, firstname, lastname, salary, department_id) values ('3', 'Kelly', 'Rosario', '42689', 'D1002')",
|
||||
"insert into Salary (emp_id, firstname, lastname, salary, department_id) values ('4', 'Patricia', 'Powell', '162825', 'D1004')",
|
||||
"insert into Salary (emp_id, firstname, lastname, salary, department_id) values ('4', 'Patricia', 'Powell', '170000', 'D1004')",
|
||||
"insert into Salary (emp_id, firstname, lastname, salary, department_id) values ('5', 'Sherry', 'Golden', '44101', 'D1002')",
|
||||
"insert into Salary (emp_id, firstname, lastname, salary, department_id) values ('6', 'Natasha', 'Swanson', '79632', 'D1005')",
|
||||
"insert into Salary (emp_id, firstname, lastname, salary, department_id) values ('6', 'Natasha', 'Swanson', '90000', 'D1005')"
|
||||
],
|
||||
"enableRunCode": true,
|
||||
"envInfo": "{\"mysql\":[\"MySQL\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"]}",
|
||||
"book": null,
|
||||
"isSubscribed": false,
|
||||
"isDailyQuestion": false,
|
||||
"dailyRecordStatus": null,
|
||||
"editorType": "CKEDITOR",
|
||||
"ugcQuestionId": null,
|
||||
"style": "LEETCODE",
|
||||
"exampleTestcases": "{\"headers\":{\"Salary\":[\"emp_id\",\"firstname\",\"lastname\",\"salary\",\"department_id\"]},\"rows\":{\"Salary\":[[1,\"Todd\",\"Wilson\",110000,\"D1006\"],[1,\"Todd\",\"Wilson\",106119,\"D1006\"],[2,\"Justin\",\"Simon\",128922,\"D1005\"],[2,\"Justin\",\"Simon\",130000,\"D1005\"],[3,\"Kelly\",\"Rosario\",42689,\"D1002\"],[4,\"Patricia\",\"Powell\",162825,\"D1004\"],[4,\"Patricia\",\"Powell\",170000,\"D1004\"],[5,\"Sherry\",\"Golden\",44101,\"D1002\"],[6,\"Natasha\",\"Swanson\",79632,\"D1005\"],[6,\"Natasha\",\"Swanson\",90000,\"D1005\"]]}}",
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2840",
|
||||
"questionFrontendId": "2686",
|
||||
"categoryTitle": "Database",
|
||||
"boundTopicId": 2269586,
|
||||
"title": "Immediate Food Delivery III",
|
||||
"titleSlug": "immediate-food-delivery-iii",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Medium",
|
||||
"likes": 0,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"contributors": [],
|
||||
"langToValidPlayground": null,
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"18\", \"totalSubmission\": \"21\", \"totalAcceptedRaw\": 18, \"totalSubmissionRaw\": 21, \"acRate\": \"85.7%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\":{\"Delivery\":[\"delivery_id\",\"customer_id\",\"order_date\",\"customer_pref_delivery_date\"]},\"rows\":{\"Delivery\":[[1,1,\"2019-08-01\",\"2019-08-02\"],[2,2,\"2019-08-01\",\"2019-08-01\"],[3,1,\"2019-08-01\",\"2019-08-01\"],[4,3,\"2019-08-02\",\"2019-08-13\"],[5,3,\"2019-08-02\",\"2019-08-02\"],[6,2,\"2019-08-02\",\"2019-08-02\"],[7,4,\"2019-08-03\",\"2019-08-03\"],[8,1,\"2019-08-03\",\"2019-08-03\"],[9,5,\"2019-08-04\",\"2019-08-18\"],[10,2,\"2019-08-04\",\"2019-08-18\"]]}}",
|
||||
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Delivery (delivery_id int, customer_id int, order_date date, customer_pref_delivery_date date)\"\n ],\n \"mssql\": [\n \"Create table Delivery (delivery_id int, customer_id int, order_date date, customer_pref_delivery_date date)\"\n ],\n \"oraclesql\": [\n \"Create table Delivery (delivery_id int, customer_id int, order_date date, customer_pref_delivery_date date)\",\n \"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"\n ],\n \"database\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Create table If Not Exists Delivery (delivery_id int, customer_id int, order_date date, customer_pref_delivery_date date)",
|
||||
"Truncate table Delivery",
|
||||
"insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('1', '1', '2019-08-01', '2019-08-02')",
|
||||
"insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('2', '2', '2019-08-01', '2019-08-01')",
|
||||
"insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('3', '1', '2019-08-01', '2019-08-01')",
|
||||
"insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('4', '3', '2019-08-02', '2019-08-13')",
|
||||
"insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('5', '3', '2019-08-02', '2019-08-02')",
|
||||
"insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('6', '2', '2019-08-02', '2019-08-02')",
|
||||
"insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('7', '4', '2019-08-03', '2019-08-03')",
|
||||
"insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('8', '1', '2019-08-03', '2019-08-03')",
|
||||
"insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('9', '5', '2019-08-04', '2019-08-18')",
|
||||
"insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('10', '2', '2019-08-04', '2019-08-18')"
|
||||
],
|
||||
"enableRunCode": true,
|
||||
"envInfo": "{\"mysql\":[\"MySQL\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"]}",
|
||||
"book": null,
|
||||
"isSubscribed": false,
|
||||
"isDailyQuestion": false,
|
||||
"dailyRecordStatus": null,
|
||||
"editorType": "CKEDITOR",
|
||||
"ugcQuestionId": null,
|
||||
"style": "LEETCODE",
|
||||
"exampleTestcases": "{\"headers\":{\"Delivery\":[\"delivery_id\",\"customer_id\",\"order_date\",\"customer_pref_delivery_date\"]},\"rows\":{\"Delivery\":[[1,1,\"2019-08-01\",\"2019-08-02\"],[2,2,\"2019-08-01\",\"2019-08-01\"],[3,1,\"2019-08-01\",\"2019-08-01\"],[4,3,\"2019-08-02\",\"2019-08-13\"],[5,3,\"2019-08-02\",\"2019-08-02\"],[6,2,\"2019-08-02\",\"2019-08-02\"],[7,4,\"2019-08-03\",\"2019-08-03\"],[8,1,\"2019-08-03\",\"2019-08-03\"],[9,5,\"2019-08-04\",\"2019-08-18\"],[10,2,\"2019-08-04\",\"2019-08-18\"]]}}",
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
65
leetcode-cn/originData/[no content]the-knights-tour.json
Normal file
65
leetcode-cn/originData/[no content]the-knights-tour.json
Normal file
File diff suppressed because one or more lines are too long
59
leetcode-cn/originData/allow-one-function-call.json
Normal file
59
leetcode-cn/originData/allow-one-function-call.json
Normal file
@ -0,0 +1,59 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2796",
|
||||
"questionFrontendId": "2666",
|
||||
"categoryTitle": "JavaScript",
|
||||
"boundTopicId": 2262650,
|
||||
"title": "Allow One Function Call",
|
||||
"titleSlug": "allow-one-function-call",
|
||||
"content": "<p>Given a function <code>fn</code>, return a new function that is identical to the original function except that it ensures <code>fn</code> is called at most once.</p>\n\n<ul>\n\t<li>The first time the returned function is called, it should return the same result as <code>fn</code>.</li>\n\t<li>Every subsequent time it is called, it should return <code>undefined</code>.</li>\n</ul>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> fn = (a,b,c) => (a + b + c), calls = [[1,2,3],[2,3,6]]\n<strong>Output:</strong> [{"calls":1,"value":6}]\n<strong>Explanation:</strong>\nconst onceFn = once(fn);\nonceFn(1, 2, 3); // 6\nonceFn(2, 3, 6); // undefined, fn was not called\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> fn = (a,b,c) => (a * b * c), calls = [[5,7,4],[2,3,6],[4,6,8]]\n<strong>Output:</strong> [{"calls":1,"value":140}]\n<strong>Explanation:</strong>\nconst onceFn = once(fn);\nonceFn(5, 7, 4); // 140\nonceFn(2, 3, 6); // undefined, fn was not called\nonceFn(4, 6, 8); // undefined, fn was not called\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= calls.length <= 10</code></li>\n\t<li><code>1 <= calls[i].length <= 100</code></li>\n\t<li><code>2 <= JSON.stringify(calls).length <= 1000</code></li>\n</ul>\n",
|
||||
"translatedTitle": "只允许一次函数调用",
|
||||
"translatedContent": "<p>给定一个函数 <code>fn</code> ,它返回一个新的函数,返回的函数与原始函数完全相同,只不过它确保 <code>fn</code> 最多被调用一次。</p>\n\n<ul>\n\t<li>第一次调用返回的函数时,它应该返回与 <code>fn</code> 相同的结果。</li>\n\t<li>第一次后的每次调用,它应该返回 <code>undefined</code> 。</li>\n</ul>\n\n<p> </p>\n\n<p><b>示例 1:</b></p>\n\n<pre>\n<b>输入:</b>fn = (a,b,c) => (a + b + c), calls = [[1,2,3],[2,3,6]]\n<b>输出:</b>[{\"calls\":1,\"value\":6}]\n<strong>解释:</strong>\nconst onceFn = once(fn);\nonceFn(1, 2, 3); // 6\nonceFn(2, 3, 6); // undefined, fn 没有被调用\n</pre>\n\n<p><strong class=\"example\">示例 2:</strong></p>\n\n<pre>\n<b>输入:</b>fn = (a,b,c) => (a * b * c), calls = [[5,7,4],[2,3,6],[4,6,8]]\n<b>输出:</b>[{\"calls\":1,\"value\":140}]\n<strong>解释:</strong>\nconst onceFn = once(fn);\nonceFn(5, 7, 4); // 140\nonceFn(2, 3, 6); // undefined, fn 没有被调用\nonceFn(4, 6, 8); // undefined, fn 没有被调用\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= calls.length <= 10</code></li>\n\t<li><code>1 <= calls[i].length <= 100</code></li>\n\t<li><code>2 <= JSON.stringify(calls).length <= 1000</code></li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Easy",
|
||||
"likes": 0,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"contributors": [],
|
||||
"langToValidPlayground": "{\"cpp\": true, \"java\": true, \"python\": true, \"python3\": true, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"ruby\": false, \"bash\": false, \"swift\": false, \"golang\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"kotlin\": false, \"rust\": false, \"php\": false, \"typescript\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"dart\": false}",
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": [
|
||||
{
|
||||
"lang": "JavaScript",
|
||||
"langSlug": "javascript",
|
||||
"code": "/**\n * @param {Function} fn\n * @return {Function}\n */\nvar once = function(fn) {\n return function(...args){\n \n }\n};\n\n/**\n * let fn = (a,b,c) => (a + b + c)\n * let onceFn = once(fn)\n *\n * onceFn(1,2,3); // 6\n * onceFn(2,3,6); // returns undefined without calling fn\n */",
|
||||
"__typename": "CodeSnippetNode"
|
||||
},
|
||||
{
|
||||
"lang": "TypeScript",
|
||||
"langSlug": "typescript",
|
||||
"code": "function once<T extends (...args: any[]) => any>(fn: T): \n ((...args: Parameters<T>) => ReturnType<T> | undefined) {\n return function (...args) {\n\n };\n}\n\n/**\n * let fn = (a,b,c) => (a + b + c)\n * let onceFn = once(fn)\n *\n * onceFn(1,2,3); // 6\n * onceFn(2,3,6); // returns undefined without calling fn\n */",
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"326\", \"totalSubmission\": \"394\", \"totalAcceptedRaw\": 326, \"totalSubmissionRaw\": 394, \"acRate\": \"82.7%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "(a,b,c) => (a + b + c)\n[[1,2,3],[2,3,6]]",
|
||||
"metaData": "{\n \"name\": \"once\",\n \"params\": [\n {\n \"name\": \"fn\",\n \"type\": \"string\"\n },\n {\n \"type\": \"string\",\n \"name\": \"calls\"\n }\n ],\n \"return\": {\n \"type\": \"integer\"\n },\n \"languages\": [\n \"javascript\",\n \"typescript\"\n ],\n \"manual\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [],
|
||||
"enableRunCode": true,
|
||||
"envInfo": "{\"javascript\":[\"JavaScript\",\"<p>\\u7248\\u672c\\uff1a<code>Node.js 16.13.2<\\/code><\\/p>\\r\\n\\r\\n<p>\\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a <code>--harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f <a href=\\\"http:\\/\\/node.green\\/\\\" target=\\\"_blank\\\">\\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"],\"typescript\":[\"TypeScript\",\"<p>TypeScript 4.5.4<\\/p>\\r\\n\\r\\n<p>Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2020<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"]}",
|
||||
"book": null,
|
||||
"isSubscribed": false,
|
||||
"isDailyQuestion": false,
|
||||
"dailyRecordStatus": null,
|
||||
"editorType": "CKEDITOR",
|
||||
"ugcQuestionId": null,
|
||||
"style": "LEETCODE",
|
||||
"exampleTestcases": "(a,b,c) => (a + b + c)\n[[1,2,3],[2,3,6]]\n(a,b,c) => (a * b * c)\n[[5,7,4],[2,3,6],[4,6,8]]",
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
63
leetcode-cn/originData/array-of-objects-to-matrix.json
Normal file
63
leetcode-cn/originData/array-of-objects-to-matrix.json
Normal file
@ -0,0 +1,63 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2769",
|
||||
"questionFrontendId": "2675",
|
||||
"categoryTitle": "JavaScript",
|
||||
"boundTopicId": 2267107,
|
||||
"title": "Array of Objects to Matrix",
|
||||
"titleSlug": "array-of-objects-to-matrix",
|
||||
"content": "<p>Write a function that converts an array of objects <code>arr</code> into a matrix <code>m</code>.</p>\n\n<p><code>arr</code> is an array of objects or arrays. Each item in the array can be deeply nested with child arrays and child objects. It can also contain numbers, strings, booleans, and null values.</p>\n\n<p>The first row <code>m</code> should be the column names. If there is no nesting, the column names are the unique keys within the objects. If there is nesting, the column names are the respective paths in the object separated by <code>"."</code>.</p>\n\n<p>Each of the remaining rows corresponds to an object in <code>arr</code>. Each value in the matrix corresponds to a value in an object. If a given object doesn't contain a value for a given column, the cell should contain an empty string <code>""</code>.</p>\n\n<p>The colums in the matrix should be in <strong>lexographically ascending</strong> order.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \narr = [\n {"b": 1, "a": 2},\n {"b": 3, "a": 4}\n]\n<strong>Output:</strong> \n[\n ["a", "b"],\n [2, 1],\n [4, 3]\n]\n\n<strong>Explanation:</strong>\nThere are two unique column names in the two objects: "a" and "b".\n"a" corresponds with [2, 4].\n"b" coresponds with [1, 3].\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> \narr = [\n {"a": 1, "b": 2},\n {"c": 3, "d": 4},\n {}\n]\n<strong>Output:</strong> \n[\n ["a", "b", "c", "d"],\n [1, 2, "", ""],\n ["", "", 3, 4],\n ["", "", "", ""]\n]\n\n<strong>Explanation:</strong>\nThere are 4 unique column names: "a", "b", "c", "d".\nThe first object has values associated with "a" and "b".\nThe second object has values associated with "c" and "d".\nThe third object has no keys, so it is just a row of empty strings.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> \narr = [\n {"a": {"b": 1, "c": 2}},\n {"a": {"b": 3, "d": 4}}\n]\n<strong>Output:</strong> \n[\n ["a.b", "a.c", "a.d"],\n [1, 2, ""],\n [3, "", 4]\n]\n\n<strong>Explanation:</strong>\nIn this example, the objects are nested. The keys represent the full path to each value separated by periods.\nThere are three paths: "a.b", "a.c", "a.d".\n</pre>\n\n<p><strong class=\"example\">Example 4:</strong></p>\n\n<pre>\n<strong>Input:</strong> \narr = [\n [{"a": null}],\n [{"b": true}],\n [{"c": "x"}]\n]\n<strong>Output:</strong> \n[\n ["0.a", "0.b", "0.c"],\n [null, "", ""],\n ["", true, ""],\n ["", "", "x"]\n]\n\n<strong>Explanation:</strong>\nArrays are also considered objects with their keys being their indices.\nEach array has one element so the keys are "0.a", "0.b", and "0.c".\n</pre>\n\n<p><strong class=\"example\">Example 5:</strong></p>\n\n<pre>\n<strong>Input:</strong> \narr = [\n {},\n {},\n {},\n]\n<strong>Output:</strong> \n[\n [],\n [],\n [],\n []\n]\n\n<strong>Explanation:</strong>\nThere are no keys so every row is an empty array.</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= arr.length <= 1000</code></li>\n\t<li><code>unique keys <= 1000</code></li>\n</ul>\n",
|
||||
"translatedTitle": "将对象数组转换为矩阵",
|
||||
"translatedContent": "<p>编写一个函数,将对象数组 <code>arr</code> 转换为矩阵 <code>m</code> 。</p>\n\n<p><code>arr</code> 是一个由对象组成的数组或一个数组。数组中的每个项都可以包含深层嵌套的子数组和子对象。它还可以包含数字、字符串、布尔值和空值。</p>\n\n<p>矩阵 <code>m</code> 的第一行应该是列名。如果没有嵌套,列名是对象中的唯一键。如果存在嵌套,列名是对象中相应路径,以点号 <code>\".\"</code> 分隔。</p>\n\n<p>剩余的每一行对应 <code>arr</code> 中的一个对象。矩阵中的每个值对应对象中的一个值。如果给定对象在给定列中没有值,则应该包含空字符串 <code>\"\"</code> 。</p>\n\n<p>矩阵中的列应按 <strong>字典升序</strong> 排列。</p>\n\n<p> </p>\n\n<p><strong class=\"example\">示例 1:</strong></p>\n\n<pre>\n<b>输入:</b>\narr = [\n {\"b\": 1, \"a\": 2},\n {\"b\": 3, \"a\": 4}\n]\n<b>输出:</b>\n[\n [\"a\", \"b\"],\n [2, 1],\n [4, 3]\n]\n\n<strong>解释:</strong>\n两个对象中有两个唯一的列名:\"a\"和\"b\"。 \n\"a\"对应[2, 4]。 \n\"b\"对应[1, 3]。\n</pre>\n\n<p><strong class=\"example\">示例 2:</strong></p>\n\n<pre>\n<b>输入:</b>\narr = [\n {\"a\": 1, \"b\": 2},\n {\"c\": 3, \"d\": 4},\n {}\n]\n<b>输出:</b>\n[\n [\"a\", \"b\", \"c\", \"d\"],\n [1, 2, \"\", \"\"],\n [\"\", \"\", 3, 4],\n [\"\", \"\", \"\", \"\"]\n]\n\n<strong>解释:</strong>\n有四个唯一的列名:\"a\"、\"b\"、\"c\"、\"d\"。 \n 第一个对象具有与\"a\"和\"b\"关联的值。 \n第二个对象具有与\"c\"和\"d\"关联的值。 \n第三个对象没有键,因此只是一行空字符串。\n</pre>\n\n<p><strong class=\"example\">示例 3:</strong></p>\n\n<pre>\n<b>输入:</b>\narr = [\n {\"a\": {\"b\": 1, \"c\": 2}},\n {\"a\": {\"b\": 3, \"d\": 4}}\n]\n<b>输出:</b>\n[\n [\"a.b\", \"a.c\", \"a.d\"],\n [1, 2, \"\"],\n [3, \"\", 4]\n]\n\n<b>解释:</b>\n在这个例子中,对象是嵌套的。键表示每个值的完整路径,路径之间用句点分隔。 \n有三个路径:\"a.b\"、\"a.c\"、\"a.d\"。\n</pre>\n\n<p><strong class=\"example\">示例 4:</strong></p>\n\n<pre>\n<b>输入:</b>\narr = [\n [{\"a\": null}],\n [{\"b\": true}],\n [{\"c\": \"x\"}]\n]\n<strong>输出:</strong> \n[\n [\"0.a\", \"0.b\", \"0.c\"],\n [null, \"\", \"\"],\n [\"\", true, \"\"],\n [\"\", \"\", \"x\"]\n]\n\n<strong>解释:</strong>\n数组也被视为具有索引为键的对象。 \n每个数组只有一个元素,所以键是\"0.a\"、\"0.b\"和\"0.c\"。\n</pre>\n\n<p><strong class=\"example\">示例 5:</strong></p>\n\n<pre>\n<b>输入:</b>\narr = [\n {},\n {},\n {},\n]\n<b>输出:</b>\n[\n [],\n [],\n [],\n []\n]\n\n<strong>解释:</strong>\n没有键,所以每一行都是一个空数组。</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= arr.length <= 1000</code></li>\n\t<li><code>unique keys <= 1000</code></li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Medium",
|
||||
"likes": 0,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"contributors": [],
|
||||
"langToValidPlayground": "{\"cpp\": true, \"java\": true, \"python\": true, \"python3\": true, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"ruby\": false, \"bash\": false, \"swift\": false, \"golang\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"kotlin\": false, \"rust\": false, \"php\": false, \"typescript\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"dart\": false}",
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": [
|
||||
{
|
||||
"lang": "JavaScript",
|
||||
"langSlug": "javascript",
|
||||
"code": "/**\n * @param {Array} arr\n * @return {Matrix}\n */\nvar jsonToMatrix = function(arr) {\n \n};",
|
||||
"__typename": "CodeSnippetNode"
|
||||
},
|
||||
{
|
||||
"lang": "TypeScript",
|
||||
"langSlug": "typescript",
|
||||
"code": "function jsonToMatrix(arr: any[]): (string | number | boolean | null)[] {\n\n};",
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"54\", \"totalSubmission\": \"86\", \"totalAcceptedRaw\": 54, \"totalSubmissionRaw\": 86, \"acRate\": \"62.8%\"}",
|
||||
"hints": [
|
||||
"How could you split the problem up into sub-problems?",
|
||||
"1.) Write a function that converts a single object into a dictionary that maps the path name to values. You can solve this recursively by keeping track of current path list.",
|
||||
"2.) Write a function that converts a list of dictionaries into a matrix. Start by creating a list of all possible paths in any of the dictionaries. This will represent the columns."
|
||||
],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "[{\"b\":1,\"a\":2},{\"b\":3,\"a\":4}]",
|
||||
"metaData": "{\n \"name\": \"jsonToMatrix\",\n \"params\": [\n {\n \"name\": \"arr\",\n \"type\": \"string\"\n }\n ],\n \"return\": {\n \"type\": \"string\"\n },\n \"languages\": [\n \"typescript\",\n \"javascript\"\n ],\n \"manual\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [],
|
||||
"enableRunCode": true,
|
||||
"envInfo": "{\"javascript\":[\"JavaScript\",\"<p>\\u7248\\u672c\\uff1a<code>Node.js 16.13.2<\\/code><\\/p>\\r\\n\\r\\n<p>\\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a <code>--harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f <a href=\\\"http:\\/\\/node.green\\/\\\" target=\\\"_blank\\\">\\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"],\"typescript\":[\"TypeScript\",\"<p>TypeScript 4.5.4<\\/p>\\r\\n\\r\\n<p>Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2020<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"]}",
|
||||
"book": null,
|
||||
"isSubscribed": false,
|
||||
"isDailyQuestion": false,
|
||||
"dailyRecordStatus": null,
|
||||
"editorType": "CKEDITOR",
|
||||
"ugcQuestionId": null,
|
||||
"style": "LEETCODE",
|
||||
"exampleTestcases": "[{\"b\":1,\"a\":2},{\"b\":3,\"a\":4}]\n[{\"a\":1,\"b\":2},{\"c\":3,\"d\":4},{}]\n[{\"a\":{\"b\":1,\"c\":2}},{\"a\":{\"b\":3,\"d\":4}}]\n[[{\"a\":null}],[{\"b\":true}],[{\"c\":\"x\"}]]\n[{},{},{}]",
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
197
leetcode-cn/originData/binary-number-to-string-lcci.json
Normal file
197
leetcode-cn/originData/binary-number-to-string-lcci.json
Normal file
File diff suppressed because one or more lines are too long
59
leetcode-cn/originData/chunk-array.json
Normal file
59
leetcode-cn/originData/chunk-array.json
Normal file
@ -0,0 +1,59 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2798",
|
||||
"questionFrontendId": "2677",
|
||||
"categoryTitle": "JavaScript",
|
||||
"boundTopicId": 2267105,
|
||||
"title": "Chunk Array",
|
||||
"titleSlug": "chunk-array",
|
||||
"content": "<p>Given an array <code>arr</code> and a chunk size <code>size</code>, return a <strong>chunked</strong> array. A <strong>chunked</strong> array contains the original elements in <code>arr</code>, but consists of subarrays each of length <code>size</code>. The length of the last subarray may be less than <code>size</code> if <code>arr.length</code> is not evenly divisible by <code>size</code>.</p>\n\n<p>You may assume the array is the output of <code>JSON.parse</code>. In other words, it is valid JSON.</p>\n\n<p>Please solve it without using lodash's <code>_.chunk</code> function.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr = [1,2,3,4,5], size = 1\n<strong>Output:</strong> [[1],[2],[3],[4],[5]]\n<strong>Explanation:</strong> The arr has been split into subarrays each with 1 element.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr = [1,9,6,3,2], size = 3\n<strong>Output:</strong> [[1,9,6],[3,2]]\n<strong>Explanation:</strong> The arr has been split into subarrays with 3 elements. However, only two elements are left for the 2nd subarray.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr = [8,5,3,2,6], size = 6\n<strong>Output:</strong> [[8,5,3,2,6]]\n<strong>Explanation:</strong> Size is greater than arr.length thus all elements are in the first subarray.\n</pre>\n\n<p><strong class=\"example\">Example 4:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr = [], size = 1\n<strong>Output:</strong> []\n<strong>Explanation:</strong> There are no elements to be chunked so an empty array is returned.</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>arr is a valid JSON array</code></li>\n\t<li><code>2 <= JSON.stringify(arr).length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= size <= arr.length + 1</code></li>\n</ul>\n",
|
||||
"translatedTitle": "分块数组",
|
||||
"translatedContent": "<p>给定一个数组 <code>arr</code> 和一个块大小 <code>size</code> ,返回一个 <strong>分块</strong> 的数组。<strong>分块</strong> 的数组包含了 <code>arr</code> 中的原始元素,但是每个子数组的长度都是 <code>size</code> 。如果 <code>arr.length</code> 不能被 <code>size</code> 整除,那么最后一个子数组的长度可能小于 <code>size</code> 。</p>\n\n<p>你可以假设该数组是 <code>JSON.parse</code> 的输出结果。换句话说,它是有效的JSON。</p>\n\n<p>请你在不使用 lodash 的函数 <code>_.chunk</code> 的情况下解决这个问题。</p>\n\n<p> </p>\n\n<p><strong class=\"example\">示例 1:</strong></p>\n\n<pre>\n<b>输入:</b>arr = [1,2,3,4,5], size = 1\n<b>输出:</b>[[1],[2],[3],[4],[5]]\n<b>解释:</b>数组 <code>arr </code>被分割成了每个只有一个元素的子数组。\n</pre>\n\n<p><strong class=\"example\">示例 2:</strong></p>\n\n<pre>\n<b>输入:</b>arr = [1,9,6,3,2], size = 3\n<b>输出:</b>[[1,9,6],[3,2]]\n<b>解释:</b>数组 <code>arr </code>被分割成了每个有三个元素的子数组。然而,第二个子数组只有两个元素。\n</pre>\n\n<p><strong class=\"example\">示例 3:</strong></p>\n\n<pre>\n<b>输入:</b>arr = [8,5,3,2,6], size = 6\n<b>输出:</b>[[8,5,3,2,6]]\n<b>解释:</b><code>size </code>大于 <code>arr.length </code>,因此所有元素都在第一个子数组中。\n</pre>\n\n<p><strong class=\"example\">示例 4:</strong></p>\n\n<pre>\n<b>输入:</b>arr = [], size = 1\n<b>输出:</b>[]\n<b>解释:</b>没有元素需要分块,因此返回一个空数组。</pre>\n\n<p> </p>\n\n<p><b>提示:</b></p>\n\n<ul>\n\t<li><code>arr is a valid JSON array</code></li>\n\t<li><code>2 <= JSON.stringify(arr).length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= size <= arr.length + 1</code></li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Easy",
|
||||
"likes": 0,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"contributors": [],
|
||||
"langToValidPlayground": "{\"cpp\": true, \"java\": true, \"python\": true, \"python3\": true, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"ruby\": false, \"bash\": false, \"swift\": false, \"golang\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"kotlin\": false, \"rust\": false, \"php\": false, \"typescript\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"dart\": false}",
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": [
|
||||
{
|
||||
"lang": "JavaScript",
|
||||
"langSlug": "javascript",
|
||||
"code": "/**\n * @param {Array} arr\n * @param {number} size\n * @return {Array[]}\n */\nvar chunk = function(arr, size) {\n \n};",
|
||||
"__typename": "CodeSnippetNode"
|
||||
},
|
||||
{
|
||||
"lang": "TypeScript",
|
||||
"langSlug": "typescript",
|
||||
"code": "function chunk(arr: any[], size: number): any[][] {\n\n};",
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"153\", \"totalSubmission\": \"206\", \"totalAcceptedRaw\": 153, \"totalSubmissionRaw\": 206, \"acRate\": \"74.3%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "[1,2,3,4,5]\n1",
|
||||
"metaData": "{\n \"name\": \"chunkify\",\n \"params\": [\n {\n \"name\": \"arr\",\n \"type\": \"string\"\n },\n {\n \"type\": \"integer\",\n \"name\": \"size\"\n }\n ],\n \"return\": {\n \"type\": \"integer\"\n },\n \"languages\": [\n \"javascript\",\n \"typescript\"\n ],\n \"manual\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [],
|
||||
"enableRunCode": true,
|
||||
"envInfo": "{\"javascript\":[\"JavaScript\",\"<p>\\u7248\\u672c\\uff1a<code>Node.js 16.13.2<\\/code><\\/p>\\r\\n\\r\\n<p>\\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a <code>--harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f <a href=\\\"http:\\/\\/node.green\\/\\\" target=\\\"_blank\\\">\\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"],\"typescript\":[\"TypeScript\",\"<p>TypeScript 4.5.4<\\/p>\\r\\n\\r\\n<p>Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2020<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"]}",
|
||||
"book": null,
|
||||
"isSubscribed": false,
|
||||
"isDailyQuestion": false,
|
||||
"dailyRecordStatus": null,
|
||||
"editorType": "CKEDITOR",
|
||||
"ugcQuestionId": null,
|
||||
"style": "LEETCODE",
|
||||
"exampleTestcases": "[1,2,3,4,5]\n1\n[1,9,6,3,2]\n3\n[8,5,3,2,6]\n6\n[]\n1",
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
161
leetcode-cn/originData/cnHoX6.json
Normal file
161
leetcode-cn/originData/cnHoX6.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
62
leetcode-cn/originData/counter-ii.json
Normal file
62
leetcode-cn/originData/counter-ii.json
Normal file
@ -0,0 +1,62 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2789",
|
||||
"questionFrontendId": "2665",
|
||||
"categoryTitle": "JavaScript",
|
||||
"boundTopicId": 2258605,
|
||||
"title": "Counter II",
|
||||
"titleSlug": "counter-ii",
|
||||
"content": "<p>Write a function <code>createCounter</code>. It should accept an initial integer <code>init</code>. It should return an object with three functions.</p>\n\n<p>The three functions are:</p>\n\n<ul>\n\t<li><code>increment()</code> increases the current value by 1 and then returns it.</li>\n\t<li><code>decrement()</code> reduces the current value by 1 and then returns it.</li>\n\t<li><code>reset()</code> sets the current value to <code>init</code> and then returns it.</li>\n</ul>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> init = 5, calls = ["increment","reset","decrement"]\n<strong>Output:</strong> [6,5,4]\n<strong>Explanation:</strong>\nconst counter = createCounter(5);\ncounter.increment(); // 6\ncounter.reset(); // 5\ncounter.decrement(); // 4\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> init = 0, calls = ["increment","increment","decrement","reset","reset"]\n<strong>Output:</strong> [1,2,1,0,0]\n<strong>Explanation:</strong>\nconst counter = createCounter(0);\ncounter.increment(); // 1\ncounter.increment(); // 2\ncounter.decrement(); // 1\ncounter.reset(); // 0\ncounter.reset(); // 0\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>-1000 <= init <= 1000</code></li>\n\t<li><code>total calls not to exceed 1000</code></li>\n</ul>\n",
|
||||
"translatedTitle": "计数器 II",
|
||||
"translatedContent": "<p>请你写一个函数 <code>createCounter</code>. 这个函数接收一个初始的整数值 <code>init</code> 并返回一个包含三个函数的对象。</p>\n\n<p>这三个函数是:</p>\n\n<ul>\n\t<li><code>increment()</code> 将当前值加 1 并返回。</li>\n\t<li><code>decrement()</code> 将当前值减 1 并返回。</li>\n\t<li><code>reset()</code> 将当前值设置为 <code>init</code> 并返回。</li>\n</ul>\n\n<p> </p>\n\n<p><strong class=\"example\">示例 1:</strong></p>\n\n<pre>\n<b>输入:</b>init = 5, calls = [\"increment\",\"reset\",\"decrement\"]\n<b>输出:</b>[6,5,4]\n<strong>解释:</strong>\nconst counter = createCounter(5);\ncounter.increment(); // 6\ncounter.reset(); // 5\ncounter.decrement(); // 4\n</pre>\n\n<p><strong class=\"example\">示例 2:</strong></p>\n\n<pre>\n<b>输入:</b>init = 0, calls = [\"increment\",\"increment\",\"decrement\",\"reset\",\"reset\"]\n<b>输出:</b>[1,2,1,0,0]\n<strong>解释:</strong>\nconst counter = createCounter(0);\ncounter.increment(); // 1\ncounter.increment(); // 2\ncounter.decrement(); // 1\ncounter.reset(); // 0\ncounter.reset(); // 0\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>-1000 <= init <= 1000</code></li>\n\t<li><code>总调用次数不会超过 1000</code></li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Easy",
|
||||
"likes": 0,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"contributors": [],
|
||||
"langToValidPlayground": "{\"cpp\": false, \"java\": true, \"python\": true, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"ruby\": false, \"bash\": false, \"swift\": false, \"golang\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"kotlin\": false, \"rust\": false, \"php\": false, \"typescript\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"dart\": false}",
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": [
|
||||
{
|
||||
"lang": "JavaScript",
|
||||
"langSlug": "javascript",
|
||||
"code": "/**\n * @param {integer} init\n * @return { increment: Function, decrement: Function, reset: Function }\n */\nvar createCounter = function(init) {\n \n};\n\n/**\n * const counter = createCounter(5)\n * counter.increment(); // 6\n * counter.reset(); // 5\n * counter.decrement(); // 4\n */",
|
||||
"__typename": "CodeSnippetNode"
|
||||
},
|
||||
{
|
||||
"lang": "TypeScript",
|
||||
"langSlug": "typescript",
|
||||
"code": "type ReturnObj = {\n increment: () => number,\n decrement: () => number,\n reset: () => number,\n}\n\nfunction createCounter(init: number): ReturnObj {\n\n};\n\n/**\n * const counter = createCounter(5)\n * counter.increment(); // 6\n * counter.reset(); // 5\n * counter.decrement(); // 4\n */",
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"402\", \"totalSubmission\": \"512\", \"totalAcceptedRaw\": 402, \"totalSubmissionRaw\": 512, \"acRate\": \"78.5%\"}",
|
||||
"hints": [
|
||||
"You can return an object with methods.",
|
||||
"Initialize a variable for currentCount. Inside these methods, add the appropriate logic which mutates currentCount."
|
||||
],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "5\n[\"increment\",\"reset\",\"decrement\"]",
|
||||
"metaData": "{\n \"name\": \"createCounter\",\n \"params\": [\n {\n \"name\": \"init\",\n \"type\": \"integer\"\n },\n {\n \"type\": \"string[]\",\n \"name\": \"calls\"\n }\n ],\n \"return\": {\n \"type\": \"integer\"\n },\n \"languages\": [\n \"javascript\",\n \"typescript\"\n ],\n \"manual\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [],
|
||||
"enableRunCode": true,
|
||||
"envInfo": "{\"javascript\":[\"JavaScript\",\"<p>\\u7248\\u672c\\uff1a<code>Node.js 16.13.2<\\/code><\\/p>\\r\\n\\r\\n<p>\\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a <code>--harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f <a href=\\\"http:\\/\\/node.green\\/\\\" target=\\\"_blank\\\">\\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"],\"typescript\":[\"TypeScript\",\"<p>TypeScript 4.5.4<\\/p>\\r\\n\\r\\n<p>Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2020<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"]}",
|
||||
"book": null,
|
||||
"isSubscribed": false,
|
||||
"isDailyQuestion": false,
|
||||
"dailyRecordStatus": null,
|
||||
"editorType": "CKEDITOR",
|
||||
"ugcQuestionId": null,
|
||||
"style": "LEETCODE",
|
||||
"exampleTestcases": "5\n[\"increment\",\"reset\",\"decrement\"]\n0\n[\"increment\",\"increment\",\"decrement\",\"reset\",\"reset\"]",
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
59
leetcode-cn/originData/create-hello-world-function.json
Normal file
59
leetcode-cn/originData/create-hello-world-function.json
Normal file
@ -0,0 +1,59 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2809",
|
||||
"questionFrontendId": "2667",
|
||||
"categoryTitle": "JavaScript",
|
||||
"boundTopicId": 2255550,
|
||||
"title": "Create Hello World Function",
|
||||
"titleSlug": "create-hello-world-function",
|
||||
"content": "Write a function <code>createHelloWorld</code>. It should return a new function that always returns <code>"Hello World"</code>.\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> args = []\n<strong>Output:</strong> "Hello World"\n<strong>Explanation:</strong>\nconst f = createHelloWorld();\nf(); // "Hello World"\n\nThe function returned by createHelloWorld should always return "Hello World".\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> args = [{},null,42]\n<strong>Output:</strong> "Hello World"\n<strong>Explanation:</strong>\nconst f = createHelloWorld();\nf({}, null, 42); // "Hello World"\n\nAny arguments could be passed to the function but it should still always return "Hello World".\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>0 <= args.length <= 10</code></li>\n</ul>\n",
|
||||
"translatedTitle": "创建 Hello World 函数",
|
||||
"translatedContent": "请你编写一个名为 <code>createHelloWorld</code> 的函数。它应该返回一个新的函数,该函数总是返回 <code>\"Hello World\"</code> 。\n<p> </p>\n\n<p><strong class=\"example\">示例 1:</strong></p>\n\n<pre>\n<b>输入:</b>args = []\n<b>输出:</b>\"Hello World\"\n<strong>解释:</strong>\nconst f = createHelloWorld();\nf(); // \"Hello World\"\n\ncreateHelloWorld 返回的函数应始终返回 \"Hello World\"。\n</pre>\n\n<p><strong class=\"example\">示例 2:</strong></p>\n\n<pre>\n<b>输入:</b>args = [{},null,42]\n<b>输出:</b>\"Hello World\"\n<strong>解释:</strong>\nconst f = createHelloWorld();\nf({}, null, 42); // \"Hello World\"\n\n可以传递任何参数给函数,但它应始终返回 \"Hello World\"。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>0 <= args.length <= 10</code></li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Easy",
|
||||
"likes": 1,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"contributors": [],
|
||||
"langToValidPlayground": "{\"cpp\": true, \"java\": true, \"python\": true, \"python3\": true, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"ruby\": false, \"bash\": false, \"swift\": false, \"golang\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"kotlin\": false, \"rust\": false, \"php\": false, \"typescript\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"dart\": false}",
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": [
|
||||
{
|
||||
"lang": "JavaScript",
|
||||
"langSlug": "javascript",
|
||||
"code": "/**\n * @return {Function}\n */\nvar createHelloWorld = function() {\n return function(...args) {\n \n }\n};\n\n/**\n * const f = createHelloWorld();\n * f(); // \"Hello World\"\n */",
|
||||
"__typename": "CodeSnippetNode"
|
||||
},
|
||||
{
|
||||
"lang": "TypeScript",
|
||||
"langSlug": "typescript",
|
||||
"code": "function createHelloWorld() {\n\treturn function(...args): string {\n \n };\n};\n\n/**\n * const f = createHelloWorld();\n * f(); // \"Hello World\"\n */",
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"520\", \"totalSubmission\": \"584\", \"totalAcceptedRaw\": 520, \"totalSubmissionRaw\": 584, \"acRate\": \"89.0%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "[]",
|
||||
"metaData": "{\n \"name\": \"createHelloWorld\",\n \"params\": [\n {\n \"name\": \"args\",\n \"type\": \"string\"\n }\n ],\n \"return\": {\n \"type\": \"string\"\n },\n \"languages\": [\n \"javascript\",\n \"typescript\"\n ],\n \"manual\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [],
|
||||
"enableRunCode": true,
|
||||
"envInfo": "{\"javascript\":[\"JavaScript\",\"<p>\\u7248\\u672c\\uff1a<code>Node.js 16.13.2<\\/code><\\/p>\\r\\n\\r\\n<p>\\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a <code>--harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f <a href=\\\"http:\\/\\/node.green\\/\\\" target=\\\"_blank\\\">\\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"],\"typescript\":[\"TypeScript\",\"<p>TypeScript 4.5.4<\\/p>\\r\\n\\r\\n<p>Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2020<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"]}",
|
||||
"book": null,
|
||||
"isSubscribed": false,
|
||||
"isDailyQuestion": false,
|
||||
"dailyRecordStatus": null,
|
||||
"editorType": "CKEDITOR",
|
||||
"ugcQuestionId": null,
|
||||
"style": "LEETCODE",
|
||||
"exampleTestcases": "[]\n[{},null,42]",
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
177
leetcode-cn/originData/find-the-distinct-difference-array.json
Normal file
177
leetcode-cn/originData/find-the-distinct-difference-array.json
Normal file
File diff suppressed because one or more lines are too long
163
leetcode-cn/originData/find-the-losers-of-the-circular-game.json
Normal file
163
leetcode-cn/originData/find-the-losers-of-the-circular-game.json
Normal file
File diff suppressed because one or more lines are too long
178
leetcode-cn/originData/frequency-tracker.json
Normal file
178
leetcode-cn/originData/frequency-tracker.json
Normal file
File diff suppressed because one or more lines are too long
168
leetcode-cn/originData/kjpLFZ.json
Normal file
168
leetcode-cn/originData/kjpLFZ.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
164
leetcode-cn/originData/maximum-number-of-moves-in-a-grid.json
Normal file
164
leetcode-cn/originData/maximum-number-of-moves-in-a-grid.json
Normal file
File diff suppressed because one or more lines are too long
164
leetcode-cn/originData/maximum-or.json
Normal file
164
leetcode-cn/originData/maximum-or.json
Normal file
File diff suppressed because one or more lines are too long
164
leetcode-cn/originData/neighboring-bitwise-xor.json
Normal file
164
leetcode-cn/originData/neighboring-bitwise-xor.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
164
leetcode-cn/originData/number-of-senior-citizens.json
Normal file
164
leetcode-cn/originData/number-of-senior-citizens.json
Normal file
File diff suppressed because one or more lines are too long
166
leetcode-cn/originData/power-of-heroes.json
Normal file
166
leetcode-cn/originData/power-of-heroes.json
Normal file
File diff suppressed because one or more lines are too long
161
leetcode-cn/originData/qoQAMX.json
Normal file
161
leetcode-cn/originData/qoQAMX.json
Normal file
File diff suppressed because one or more lines are too long
161
leetcode-cn/originData/ryfUiz.json
Normal file
161
leetcode-cn/originData/ryfUiz.json
Normal file
File diff suppressed because one or more lines are too long
164
leetcode-cn/originData/sum-in-a-matrix.json
Normal file
164
leetcode-cn/originData/sum-in-a-matrix.json
Normal file
File diff suppressed because one or more lines are too long
63
leetcode-cn/originData/throttle.json
Normal file
63
leetcode-cn/originData/throttle.json
Normal file
@ -0,0 +1,63 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2771",
|
||||
"questionFrontendId": "2676",
|
||||
"categoryTitle": "JavaScript",
|
||||
"boundTopicId": 2267103,
|
||||
"title": "Throttle",
|
||||
"titleSlug": "throttle",
|
||||
"content": "<p>Given a function <code>fn</code> and a time in milliseconds <code>t</code>, return a <strong>throttled</strong> version of that function.</p>\n\n<p>A <strong>throttled</strong> function is first called without delay and then, for a time interval of <code>t</code> milliseconds, can't be executed but should store the latest function arguments provided to call <code>fn</code> with them after the end of the delay.</p>\n\n<p>For instance, <code>t = 50ms</code>, and the function was called at <code>30ms</code>, <code>40ms</code>, and <code>60ms</code>. The first function call would block calling functions for the following <code>t</code> milliseconds. The second function call would save arguments, and the third call arguments should overwrite currently stored arguments from the second call because the second and third calls are called before <code>80ms</code>. Once the delay has passed, the throttled function should be called with the latest arguments provided during the delay period, and it should also create another delay period of <code>80ms + t</code>.</p>\n\n<p><img alt=\"Throttle Diagram\" src=\"https://assets.leetcode.com/uploads/2023/04/08/screen-shot-2023-04-08-at-120313-pm.png\" style=\"width: 1156px; height: 372px;\" />The above diagram shows how throttle will transform events. Each rectangle represents 100ms and the throttle time is 400ms. Each color represents a different set of inputs.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> t = 100, calls = [{"t":20,"inputs":[1]}]\n<strong>Output:</strong> [{"t":20,"inputs":[1]}]\n<strong>Explanation:</strong> The 1st call is always called without delay\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> t = 50, calls = [{"t":50,"inputs":[1]},{"t":75,"inputs":[2]}]\n<strong>Output:</strong> [{"t":50,"inputs":[1]},{"t":100,"inputs":[2]}]\n<strong>Explanation:</strong> \nThe 1st is called a function with arguments (1) without delay.\nThe 2nd is called at 75ms, within the delay period because 50ms + 50ms = 100ms, so the next call can be reached at 100ms. Therefore, we save arguments from the 2nd call to use them at the callback of the 1st call.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> t = 70, calls = [{"t":50,"inputs":[1]},{"t":75,"inputs":[2]},{"t":90,"inputs":[8]},{"t": 140, "inputs":[5,7]},{"t": 300, "inputs": [9,4]}]\n<strong>Output:</strong> [{"t":50,"inputs":[1]},{"t":120,"inputs":[8]},{"t":190,"inputs":[5,7]},{"t":300,"inputs":[9,4]}]\n<strong>Explanation:</strong> \nThe 1st is called a function with arguments (1) without delay.\nThe 2nd is called at 75ms within the delay period because 50ms + 70ms = 120ms, so it should only save arguments. \nThe 3rd is also called within the delay period, and because we need just the latest function arguments, we overwrite previous ones. After the delay period, we do a callback at 120ms with saved arguments. That callback makes another delay period of 120ms + 70ms = 190ms so that the next function can be called at 190ms.\nThe 4th is called at 140ms in the delay period, so it should be called as a callback at 190ms. That will create another delay period of 190ms + 70ms = 260ms.\nThe 5th is called at 300ms, but it is after 260ms, so it should be called immediately and should create another delay period of 300ms + 70ms = 370ms.</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>0 <= t <= 1000</code></li>\n\t<li><code>1 <= calls.length <= 10</code></li>\n\t<li><code>0 <= calls[i].t <= 1000</code></li>\n\t<li><code>0 <= calls[i].inputs[i], calls[i].inputs.length <= 10</code></li>\n</ul>\n",
|
||||
"translatedTitle": "节流",
|
||||
"translatedContent": "<p>现给定一个函数 <code>fn</code> 和一个以毫秒为单位的时间 <code>t</code> ,请你返回该函数的 <strong>节流</strong> 版本。</p>\n\n<p><strong>节流</strong> 函数首先立即被调用,然后在 <code>t</code> 毫秒的时间间隔内不能再次执行,但应该存储最新的函数参数,以便在延迟结束后使用这些参数调用 <code>fn</code> 。</p>\n\n<p>例如,<code>t = 50ms</code> ,并且函数在 <code>30ms</code> 、 <code>40ms</code> 和 <code>60ms</code> 时被调用。第一次函数调用会在接下来的 <code>t</code> 毫秒内阻止调用函数。第二次函数调用会保存参数,而第三次调用的参数应该覆盖当前保存的第二次调用的参数,因为第二次和第三次调用发生在 <code>80ms</code> 之前。一旦延迟时间过去,节流函数应该使用延迟期间提供的最新参数进行调用,并且还应创建另一个延迟期间,时长为 <code>80ms + t</code> 。</p>\n\n<p><img alt=\"Throttle Diagram\" src=\"https://assets.leetcode.com/uploads/2023/04/08/screen-shot-2023-04-08-at-120313-pm.png\" style=\"width: 1156px; height: 372px;\" />上面的图示展示了节流如何转换事件。每个矩形代表100毫秒,节流时间为400毫秒。每种颜色代表不同的输入集合。</p>\n\n<p> </p>\n\n<p><strong class=\"example\">示例 1:</strong></p>\n\n<pre>\n<b>输入:</b>t = 100, calls = [{\"t\":20,\"inputs\":[1]}]\n<b>输出:</b>[{\"t\":20,\"inputs\":[1]}]\n<b>解释:</b>第一次调用总是立即执行,没有延迟。\n</pre>\n\n<p><strong class=\"example\">示例 2:</strong></p>\n\n<pre>\n<b>输入:</b>t = 50, calls = [{\"t\":50,\"inputs\":[1]},{\"t\":75,\"inputs\":[2]}]\n<b>输出:</b>[{\"t\":50,\"inputs\":[1]},{\"t\":100,\"inputs\":[2]}]\n<b>解释:</b>\n第一次调用立即执行带有参数 (1) 的函数。 \n第二次调用发生在 75毫秒 时,在延迟期间内,因为 50毫秒 + 50毫秒 = 100毫秒,所以下一次调用可以在 100毫秒 时执行。因此,我们保存第二次调用的参数,以便在第一次调用的回调函数中使用。\n</pre>\n\n<p><strong class=\"example\">示例 3:</strong></p>\n\n<pre>\n<b>输入:</b>t = 70, calls = [{\"t\":50,\"inputs\":[1]},{\"t\":75,\"inputs\":[2]},{\"t\":90,\"inputs\":[8]},{\"t\": 140, \"inputs\":[5,7]},{\"t\": 300, \"inputs\": [9,4]}]\n<b>输出:</b>[{\"t\":50,\"inputs\":[1]},{\"t\":120,\"inputs\":[8]},{\"t\":190,\"inputs\":[5,7]},{\"t\":300,\"inputs\":[9,4]}]\n<b>解释:</b>\n第一次调用立即执行带有参数 (1) 的函数。 \n第二次调用发生在 75毫秒 时,在延迟期间内,因为 50毫秒 + 70毫秒 = 120毫秒,所以它只应保存参数。 \n第三次调用也在延迟期间内,因为我们只需要最新的函数参数,所以覆盖之前的参数。延迟期过后,在 120毫秒时进行回调,并使用保存的参数进行调用。该回调会创建另一个延迟期间,时长为 120毫秒 + 70毫秒 = 190毫秒,以便下一个函数可以在 190毫秒时调用。 \n第四次调用发生在 140毫秒,在延迟期间内,因此应在190毫秒时作为回调进行调用。这将创建另一个延迟期间,时长为 190毫秒 + 70毫秒 = 260毫秒。 \n第五次调用发生在 300毫秒,但它是在 260毫秒 之后,所以应立即调用,并创建另一个延迟期间,时长为 300毫秒 + 70毫秒 = 370毫秒。</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>0 <= t <= 1000</code></li>\n\t<li><code>1 <= calls.length <= 10</code></li>\n\t<li><code>0 <= calls[i].t <= 1000</code></li>\n\t<li><code>0 <= calls[i].inputs[i], calls[i].inputs.length <= 10</code></li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Medium",
|
||||
"likes": 0,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"contributors": [],
|
||||
"langToValidPlayground": "{\"cpp\": true, \"java\": true, \"python\": true, \"python3\": true, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"ruby\": false, \"bash\": false, \"swift\": false, \"golang\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"kotlin\": false, \"rust\": false, \"php\": false, \"typescript\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"dart\": false}",
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": [
|
||||
{
|
||||
"lang": "JavaScript",
|
||||
"langSlug": "javascript",
|
||||
"code": "/**\n * @param {Function} fn\n * @param {number} t\n * @return {Function}\n */\nvar throttle = function(fn, t) {\n return function(...args) {\n\n }\n};\n\n/**\n * const throttled = throttle(console.log, 100);\n * throttled(\"log\"); // logged immediately.\n * throttled(\"log\"); // logged at t=100ms.\n */",
|
||||
"__typename": "CodeSnippetNode"
|
||||
},
|
||||
{
|
||||
"lang": "TypeScript",
|
||||
"langSlug": "typescript",
|
||||
"code": "type F = (...args: any[]) => void\n\nfunction throttle(fn: F, t: number): F {\n return function (...args) {\n\n }\n};\n\n/**\n * const throttled = throttle(console.log, 100);\n * throttled(\"log\"); // logged immediately.\n * throttled(\"log\"); // logged at t=100ms.\n */",
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"86\", \"totalSubmission\": \"182\", \"totalAcceptedRaw\": 86, \"totalSubmissionRaw\": 182, \"acRate\": \"47.3%\"}",
|
||||
"hints": [
|
||||
"Store a variable for currArguments.",
|
||||
"If no timeout is in progress, immediately execute the function and create a timeout. If a timeout is in progress, set the currArguments to the new arguments.",
|
||||
"When the timeout is done: if currArguments is null, do nothing. Otherwise, execute the function with currArguments and create another timeout."
|
||||
],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "100\n[{\"t\":20,\"inputs\":[1]}]",
|
||||
"metaData": "{\n \"name\": \"throttle\",\n \"params\": [\n {\n \"name\": \"fn\",\n \"type\": \"string\"\n },\n {\n \"type\": \"integer\",\n \"name\": \"t\"\n }\n ],\n \"return\": {\n \"type\": \"integer\"\n },\n \"languages\": [\n \"javascript\",\n \"typescript\"\n ],\n \"manual\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [],
|
||||
"enableRunCode": true,
|
||||
"envInfo": "{\"javascript\":[\"JavaScript\",\"<p>\\u7248\\u672c\\uff1a<code>Node.js 16.13.2<\\/code><\\/p>\\r\\n\\r\\n<p>\\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a <code>--harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f <a href=\\\"http:\\/\\/node.green\\/\\\" target=\\\"_blank\\\">\\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"],\"typescript\":[\"TypeScript\",\"<p>TypeScript 4.5.4<\\/p>\\r\\n\\r\\n<p>Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2020<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"]}",
|
||||
"book": null,
|
||||
"isSubscribed": false,
|
||||
"isDailyQuestion": false,
|
||||
"dailyRecordStatus": null,
|
||||
"editorType": "CKEDITOR",
|
||||
"ugcQuestionId": null,
|
||||
"style": "LEETCODE",
|
||||
"exampleTestcases": "100\n[{\"t\":20,\"inputs\":[1]}]\n50\n[{\"t\":50,\"inputs\":[1]},{\"t\":75,\"inputs\":[2]}]\n70\n[{\"t\":50,\"inputs\":[1]},{\"t\":75,\"inputs\":[2]},{\"t\":90,\"inputs\":[8]},{\"t\": 140, \"inputs\":[5,7]},{\"t\": 300, \"inputs\": [9,4]}]",
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
58
leetcode-cn/problem (Chinese)/万灵之树 [cnHoX6].md
Normal file
58
leetcode-cn/problem (Chinese)/万灵之树 [cnHoX6].md
Normal file
@ -0,0 +1,58 @@
|
||||
探险家小扣终于来到了万灵之树前,挑战最后的谜题。
|
||||
已知小扣拥有足够数量的链接节点和 `n` 颗幻境宝石,`gem[i]` 表示第 `i` 颗宝石的数值。现在小扣需要使用这些链接节点和宝石组合成一颗二叉树,其组装规则为:
|
||||
- 链接节点将作为二叉树中的非叶子节点,且每个链接节点必须拥有 `2` 个子节点;
|
||||
- 幻境宝石将作为二叉树中的叶子节点,所有的幻境宝石都必须被使用。
|
||||
|
||||
能量首先进入根节点,而后将按如下规则进行移动和记录:
|
||||
- 若能量首次到达该节点时:
|
||||
- 记录数字 `1`;
|
||||
- 若该节点为叶节点,将额外记录该叶节点的数值;
|
||||
- 若存在未到达的子节点,则选取未到达的一个子节点(优先选取左子节点)进入;
|
||||
- 若无子节点或所有子节点均到达过,此时记录 `9`,并回到当前节点的父节点(若存在)。
|
||||
|
||||
如果最终记下的数依序连接成一个整数 `num`,满足 $num \mod~p=target$,则视为解开谜题。
|
||||
请问有多少种二叉树的组装方案,可以使得最终记录下的数字可以解开谜题
|
||||
|
||||
**注意:**
|
||||
- 两棵结构不同的二叉树,作为不同的组装方案
|
||||
- 两棵结构相同的二叉树且存在某个相同位置处的宝石编号不同,也作为不同的组装方案
|
||||
- 可能存在数值相同的两颗宝石
|
||||
|
||||
**示例 1:**
|
||||
> 输入:`gem = [2,3]`
|
||||
> `p = 100000007`
|
||||
> `target = 11391299`
|
||||
>
|
||||
> 输出:`1`
|
||||
>
|
||||
> 解释:
|
||||
> 包含 `2` 个叶节点的结构只有一种。
|
||||
> 假设 B、C 节点的值分别为 3、2,对应 target 为 11391299,如下图所示。
|
||||
> 11391299 % 100000007 = 11391299,满足条件;
|
||||
> 假设 B、C 节点的值分别为 2、3,对应 target 为 11291399;
|
||||
> 11291399 % 100000007 = 11291399,不满足条件;
|
||||
> 因此只存在 1 种方案,返回 1
|
||||
![万灵 (1).gif](https://pic.leetcode.cn/1682397079-evMssw-%E4%B8%87%E7%81%B5%20\(1\).gif){:height=300px}
|
||||
|
||||
|
||||
**示例 2:**
|
||||
> 输入:`gem = [3,21,3]`
|
||||
> `p = 7`
|
||||
> `target = 5`
|
||||
>
|
||||
> 输出:`4`
|
||||
>
|
||||
> 解释:
|
||||
包含 `3` 个叶节点树结构有两种,列举如下:
|
||||
满足条件的组合有四种情况:
|
||||
> 当结构为下图(1)时:叶子节点的值为 [3,3,21] 或 [3,3,21],得到的整数为 `11139139912199`。
|
||||
> 当结构为下图(2)时:叶子节点的值为 [21,3,3] 或 [21,3,3],得到的整数为 `11219113913999`。
|
||||
![image.png](https://pic.leetcode.cn/1682322894-vfqJIV-image.png){:width=500px}
|
||||
|
||||
|
||||
**提示:**
|
||||
- `1 <= gem.length <= 9`
|
||||
- `0 <= gem[i] <= 10^9`
|
||||
- `1 <= p <= 10^9`,保证 $p$ 为素数。
|
||||
- `0 <= target < p`
|
||||
- 存在 2 组 `gem.length == 9` 的用例
|
54
leetcode-cn/problem (Chinese)/与非的谜题 [ryfUiz].md
Normal file
54
leetcode-cn/problem (Chinese)/与非的谜题 [ryfUiz].md
Normal file
@ -0,0 +1,54 @@
|
||||
在永恒之森中,封存着有关万灵之树线索的卷轴,只要探险队通过最后的考验,便可以获取前往万灵之树的线索。
|
||||
|
||||
探险队需要从一段不断变化的谜题数组中找到最终的密码,初始的谜题为长度为 `n` 的数组 `arr`(下标从 0 开始),数组中的数字代表了 `k` 位二进制数。
|
||||
破解谜题的过程中,需要使用 `与非(NAND)` 运算方式,`operations[i] = [type,x,y]` 表示第 `i` 次进行的谜题操作信息:
|
||||
- 若 `type = 0`,表示修改操作,将谜题数组中下标 `x` 的数字变化为 `y`;
|
||||
- 若 `type = 1`,表示运算操作,将数字 `y` 进行 `x*n` 次「与非」操作,第 `i` 次与非操作为 `y = y NAND arr[i%n]`;
|
||||
> 运算操作结果即:`y NAND arr[0%n] NAND arr[1%n] NAND arr[2%n] ... NAND arr[(x*n-1)%n]`
|
||||
|
||||
最后,将所有运算操作的结果按顺序逐一进行 `异或(XOR)`运算,从而得到最终解开封印的密码。请返回最终解开封印的密码。
|
||||
|
||||
**注意:**
|
||||
- 「与非」(NAND)的操作为:先进行 `与` 操作,后进行 `非` 操作。
|
||||
> 例如:两个三位二进制数`2`和`3`,其与非结果为 `NOT ((010) AND (011)) = (101) = 5`
|
||||
|
||||
**示例 1:**
|
||||
> 输入:
|
||||
> `k = 3`
|
||||
> `arr = [1,2]`
|
||||
> `operations = [[1,2,3],[0,0,3],[1,2,2]]`
|
||||
>
|
||||
> 输出: `2`
|
||||
>
|
||||
> 解释:
|
||||
> 初始的谜题数组为 [1,2],二进制位数为 3,
|
||||
> 第 0 次进行运算操作,将数字 3(011) 进行 2\*2 次「与非」运算,
|
||||
> 运算操作结果为 `3 NAND 1 NAND 2 NAND 1 NAND 2 = 5`
|
||||
> 第 1 次进行修改操作,谜题数组的第 `0` 个数字变化为 `3`,谜题变成 `[3,2]`
|
||||
> 第 2 次进行运算操作,将数字 2(010) 进行 2\*2 次「与非」运算,
|
||||
> 运算操作结果为 `2 NAND 3 NAND 2 NAND 3 NAND 2 = 7`
|
||||
> 所有运算操作结果进行「异或」运算为 `5 XOR 7 = 2`
|
||||
> 因此得到的最终密码为 `2`。
|
||||
|
||||
**示例 2:**
|
||||
> 输入:
|
||||
> `k = 4`
|
||||
> `arr = [4,6,4,7,10,9,11]`
|
||||
> `operations = [[1,5,7],[1,7,14],[0,6,7],[1,6,5]]`
|
||||
> 输出: `9`
|
||||
> 解释:
|
||||
> 初始的谜题数组为 [4,6,4,7,10,9,11],
|
||||
> 第 0 次进行运算操作,运算操作结果为 5;
|
||||
> 第 1 次进行运算操作,运算操作结果为 5;
|
||||
> 第 2 次进行修改操作,修改后谜题数组为 [4, 6, 4, 7, 10, 9, 7];
|
||||
> 第 3 次进行运算操作,运算操作结果为 9;
|
||||
> 所有运算操作结果进行「异或」运算为 `5 XOR 5 XOR 9 = 9`;
|
||||
> 因此得到的最终密码为 `9`。
|
||||
|
||||
**提示:**
|
||||
- `1 <= arr.length, operations.length <= 10^4`
|
||||
- `1 <= k <= 30`
|
||||
- `0 <= arr[i] < 2^k`
|
||||
- 若 `type = 0`,`0 <= x < arr.length` 且 `0 <= y < 2^k`
|
||||
- 若 `type = 1`,`1 <= x < 10^9` 且 `0 <= y < 2^k`
|
||||
- 保证存在 `type = 1` 的操作
|
@ -0,0 +1,25 @@
|
||||
<p>二进制数转字符串。给定一个介于0和1之间的实数(如0.72),类型为double,打印它的二进制表达式。如果该数字无法精确地用32位以内的二进制表示,则打印“ERROR”。</p>
|
||||
|
||||
<p><strong>示例1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong> 输入</strong>:0.625
|
||||
<strong> 输出</strong>:"0.101"
|
||||
</pre>
|
||||
|
||||
<p><strong>示例2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong> 输入</strong>:0.1
|
||||
<strong> 输出</strong>:"ERROR"
|
||||
<strong> 提示</strong>:0.1无法被二进制准确表示
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>32位包括输出中的 <code>"0."</code> 这两位。</li>
|
||||
<li>题目保证输入用例的小数位数最多只有 <code>6</code> 位</li>
|
||||
</ul>
|
@ -0,0 +1,51 @@
|
||||
<p>给你一个整数 <code>n</code> 表示一棵 <b>满二叉树</b> 里面节点的数目,节点编号从 <code>1</code> 到 <code>n</code> 。根节点编号为 <code>1</code> ,树中每个非叶子节点 <code>i</code> 都有两个孩子,分别是左孩子 <code>2 * i</code> 和右孩子 <code>2 * i + 1</code> 。</p>
|
||||
|
||||
<p>树中每个节点都有一个值,用下标从<b> 0</b> 开始、长度为 <code>n</code> 的整数数组 <code>cost</code> 表示,其中 <code>cost[i]</code> 是第 <code>i + 1</code> 个节点的值。每次操作,你可以将树中 <strong>任意</strong> 节点的值 <strong>增加</strong> <code>1</code> 。你可以执行操作 <strong>任意</strong> 次。</p>
|
||||
|
||||
<p>你的目标是让根到每一个 <strong>叶子结点</strong> 的路径值相等。请你返回 <strong>最少</strong> 需要执行增加操作多少次。</p>
|
||||
|
||||
<p><b>注意:</b></p>
|
||||
|
||||
<ul>
|
||||
<li><strong>满二叉树</strong> 指的是一棵树,它满足树中除了叶子节点外每个节点都恰好有 2 个节点,且所有叶子节点距离根节点距离相同。</li>
|
||||
<li><strong>路径值</strong> 指的是路径上所有节点的值之和。</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2023/04/04/binaryytreeedrawio-4.png" /></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>n = 7, cost = [1,5,2,2,3,3,1]
|
||||
<b>输出:</b>6
|
||||
<b>解释:</b>我们执行以下的增加操作:
|
||||
- 将节点 4 的值增加一次。
|
||||
- 将节点 3 的值增加三次。
|
||||
- 将节点 7 的值增加两次。
|
||||
从根到叶子的每一条路径值都为 9 。
|
||||
总共增加次数为 1 + 3 + 2 = 6 。
|
||||
这是最小的答案。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2023/04/04/binaryytreee2drawio.png" style="width: 205px; height: 151px;" /></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>n = 3, cost = [5,3,3]
|
||||
<b>输出:</b>0
|
||||
<b>解释:</b>两条路径已经有相等的路径值,所以不需要执行任何增加操作。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>3 <= n <= 10<sup>5</sup></code></li>
|
||||
<li><code>n + 1</code> 是 <code>2</code> 的幂</li>
|
||||
<li><code>cost.length == n</code></li>
|
||||
<li><code>1 <= cost[i] <= 10<sup>4</sup></code></li>
|
||||
</ul>
|
48
leetcode-cn/problem (Chinese)/分块数组 [chunk-array].html
Normal file
48
leetcode-cn/problem (Chinese)/分块数组 [chunk-array].html
Normal file
@ -0,0 +1,48 @@
|
||||
<p>给定一个数组 <code>arr</code> 和一个块大小 <code>size</code> ,返回一个 <strong>分块</strong> 的数组。<strong>分块</strong> 的数组包含了 <code>arr</code> 中的原始元素,但是每个子数组的长度都是 <code>size</code> 。如果 <code>arr.length</code> 不能被 <code>size</code> 整除,那么最后一个子数组的长度可能小于 <code>size</code> 。</p>
|
||||
|
||||
<p>你可以假设该数组是 <code>JSON.parse</code> 的输出结果。换句话说,它是有效的JSON。</p>
|
||||
|
||||
<p>请你在不使用 lodash 的函数 <code>_.chunk</code> 的情况下解决这个问题。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>arr = [1,2,3,4,5], size = 1
|
||||
<b>输出:</b>[[1],[2],[3],[4],[5]]
|
||||
<b>解释:</b>数组 <code>arr </code>被分割成了每个只有一个元素的子数组。
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>arr = [1,9,6,3,2], size = 3
|
||||
<b>输出:</b>[[1,9,6],[3,2]]
|
||||
<b>解释:</b>数组 <code>arr </code>被分割成了每个有三个元素的子数组。然而,第二个子数组只有两个元素。
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">示例 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>arr = [8,5,3,2,6], size = 6
|
||||
<b>输出:</b>[[8,5,3,2,6]]
|
||||
<b>解释:</b><code>size </code>大于 <code>arr.length </code>,因此所有元素都在第一个子数组中。
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">示例 4:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>arr = [], size = 1
|
||||
<b>输出:</b>[]
|
||||
<b>解释:</b>没有元素需要分块,因此返回一个空数组。</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><b>提示:</b></p>
|
||||
|
||||
<ul>
|
||||
<li><code>arr is a valid JSON array</code></li>
|
||||
<li><code>2 <= JSON.stringify(arr).length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= size <= arr.length + 1</code></li>
|
||||
</ul>
|
@ -0,0 +1,34 @@
|
||||
请你编写一个名为 <code>createHelloWorld</code> 的函数。它应该返回一个新的函数,该函数总是返回 <code>"Hello World"</code> 。
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>args = []
|
||||
<b>输出:</b>"Hello World"
|
||||
<strong>解释:</strong>
|
||||
const f = createHelloWorld();
|
||||
f(); // "Hello World"
|
||||
|
||||
createHelloWorld 返回的函数应始终返回 "Hello World"。
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>args = [{},null,42]
|
||||
<b>输出:</b>"Hello World"
|
||||
<strong>解释:</strong>
|
||||
const f = createHelloWorld();
|
||||
f({}, null, 42); // "Hello World"
|
||||
|
||||
可以传递任何参数给函数,但它应始终返回 "Hello World"。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= args.length <= 10</code></li>
|
||||
</ul>
|
@ -0,0 +1,41 @@
|
||||
<p>给定一个函数 <code>fn</code> ,它返回一个新的函数,返回的函数与原始函数完全相同,只不过它确保 <code>fn</code> 最多被调用一次。</p>
|
||||
|
||||
<ul>
|
||||
<li>第一次调用返回的函数时,它应该返回与 <code>fn</code> 相同的结果。</li>
|
||||
<li>第一次后的每次调用,它应该返回 <code>undefined</code> 。</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><b>示例 1:</b></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>fn = (a,b,c) => (a + b + c), calls = [[1,2,3],[2,3,6]]
|
||||
<b>输出:</b>[{"calls":1,"value":6}]
|
||||
<strong>解释:</strong>
|
||||
const onceFn = once(fn);
|
||||
onceFn(1, 2, 3); // 6
|
||||
onceFn(2, 3, 6); // undefined, fn 没有被调用
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>fn = (a,b,c) => (a * b * c), calls = [[5,7,4],[2,3,6],[4,6,8]]
|
||||
<b>输出:</b>[{"calls":1,"value":140}]
|
||||
<strong>解释:</strong>
|
||||
const onceFn = once(fn);
|
||||
onceFn(5, 7, 4); // 140
|
||||
onceFn(2, 3, 6); // undefined, fn 没有被调用
|
||||
onceFn(4, 6, 8); // undefined, fn 没有被调用
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= calls.length <= 10</code></li>
|
||||
<li><code>1 <= calls[i].length <= 100</code></li>
|
||||
<li><code>2 <= JSON.stringify(calls).length <= 1000</code></li>
|
||||
</ul>
|
32
leetcode-cn/problem (Chinese)/城墙防线 [Nsibyl].md
Normal file
32
leetcode-cn/problem (Chinese)/城墙防线 [Nsibyl].md
Normal file
@ -0,0 +1,32 @@
|
||||
在探险营地间,小扣意外发现了一片城墙遗迹,在探索期间,却不巧遇到迁徙中的兽群向他迎面冲来。情急之下小扣吹响了他的苍蓝笛,随着笛声响起,遗迹中的城墙逐渐发生了横向膨胀。
|
||||
已知 `rampart[i] = [x,y]` 表示第 `i` 段城墙的初始所在区间。当城墙发生膨胀时,将遵循以下规则:
|
||||
- 所有的城墙会同时膨胀相等的长度;
|
||||
- 每个城墙可以向左、向右或向两个方向膨胀。
|
||||
|
||||
小扣为了确保自身的安全,需要在所有城墙均无重叠的情况下,让城墙尽可能的膨胀。请返回城墙可以膨胀的 **最大值** 。
|
||||
|
||||
**注意:**
|
||||
- 初始情况下,所有城墙均不重叠,且 `rampart` 中的元素升序排列;
|
||||
- 两侧的城墙可以向外无限膨胀。
|
||||
|
||||
**示例 1:**
|
||||
>输入:`rampart = [[0,3],[4,5],[7,9]]`
|
||||
>
|
||||
>输出:`3`
|
||||
>
|
||||
>解释:如下图所示:
|
||||
>`rampart[0]` 向左侧膨胀 3 个单位;
|
||||
>`rampart[2]` 向右侧膨胀 3 个单位;
|
||||
>`rampart[1]` 向左侧膨胀 1 个单位,向右膨胀 2 个单位。
|
||||
>不存在膨胀更多的方案,返回 3。
|
||||
![image.png](https://pic.leetcode.cn/1681717918-tWywrp-image.png){:width=750px}
|
||||
|
||||
**示例 2:**
|
||||
>输入:`rampart = [[1,2],[5,8],[11,15],[18,25]]`
|
||||
>
|
||||
>输出:`4`
|
||||
|
||||
**提示:**
|
||||
- `3 <= rampart.length <= 10^4`
|
||||
- `rampart[i].length == 2`
|
||||
- `0 <= rampart[i][0] < rampart[i][1] <= rampart[i+1][0] <= 10^8`
|
@ -0,0 +1,127 @@
|
||||
<p>编写一个函数,将对象数组 <code>arr</code> 转换为矩阵 <code>m</code> 。</p>
|
||||
|
||||
<p><code>arr</code> 是一个由对象组成的数组或一个数组。数组中的每个项都可以包含深层嵌套的子数组和子对象。它还可以包含数字、字符串、布尔值和空值。</p>
|
||||
|
||||
<p>矩阵 <code>m</code> 的第一行应该是列名。如果没有嵌套,列名是对象中的唯一键。如果存在嵌套,列名是对象中相应路径,以点号 <code>"."</code> 分隔。</p>
|
||||
|
||||
<p>剩余的每一行对应 <code>arr</code> 中的一个对象。矩阵中的每个值对应对象中的一个值。如果给定对象在给定列中没有值,则应该包含空字符串 <code>""</code> 。</p>
|
||||
|
||||
<p>矩阵中的列应按 <strong>字典升序</strong> 排列。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>
|
||||
arr = [
|
||||
{"b": 1, "a": 2},
|
||||
{"b": 3, "a": 4}
|
||||
]
|
||||
<b>输出:</b>
|
||||
[
|
||||
["a", "b"],
|
||||
[2, 1],
|
||||
[4, 3]
|
||||
]
|
||||
|
||||
<strong>解释:</strong>
|
||||
两个对象中有两个唯一的列名:"a"和"b"。
|
||||
"a"对应[2, 4]。
|
||||
"b"对应[1, 3]。
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>
|
||||
arr = [
|
||||
{"a": 1, "b": 2},
|
||||
{"c": 3, "d": 4},
|
||||
{}
|
||||
]
|
||||
<b>输出:</b>
|
||||
[
|
||||
["a", "b", "c", "d"],
|
||||
[1, 2, "", ""],
|
||||
["", "", 3, 4],
|
||||
["", "", "", ""]
|
||||
]
|
||||
|
||||
<strong>解释:</strong>
|
||||
有四个唯一的列名:"a"、"b"、"c"、"d"。
|
||||
第一个对象具有与"a"和"b"关联的值。
|
||||
第二个对象具有与"c"和"d"关联的值。
|
||||
第三个对象没有键,因此只是一行空字符串。
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">示例 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>
|
||||
arr = [
|
||||
{"a": {"b": 1, "c": 2}},
|
||||
{"a": {"b": 3, "d": 4}}
|
||||
]
|
||||
<b>输出:</b>
|
||||
[
|
||||
["a.b", "a.c", "a.d"],
|
||||
[1, 2, ""],
|
||||
[3, "", 4]
|
||||
]
|
||||
|
||||
<b>解释:</b>
|
||||
在这个例子中,对象是嵌套的。键表示每个值的完整路径,路径之间用句点分隔。
|
||||
有三个路径:"a.b"、"a.c"、"a.d"。
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">示例 4:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>
|
||||
arr = [
|
||||
[{"a": null}],
|
||||
[{"b": true}],
|
||||
[{"c": "x"}]
|
||||
]
|
||||
<strong>输出:</strong>
|
||||
[
|
||||
["0.a", "0.b", "0.c"],
|
||||
[null, "", ""],
|
||||
["", true, ""],
|
||||
["", "", "x"]
|
||||
]
|
||||
|
||||
<strong>解释:</strong>
|
||||
数组也被视为具有索引为键的对象。
|
||||
每个数组只有一个元素,所以键是"0.a"、"0.b"和"0.c"。
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">示例 5:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>
|
||||
arr = [
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
]
|
||||
<b>输出:</b>
|
||||
[
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
[]
|
||||
]
|
||||
|
||||
<strong>解释:</strong>
|
||||
没有键,所以每一行都是一个空数组。</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= arr.length <= 1000</code></li>
|
||||
<li><code>unique keys <= 1000</code></li>
|
||||
</ul>
|
@ -0,0 +1,44 @@
|
||||
<p>给你一个下标从 <strong>0</strong> 开始的数组 <code>nums</code> ,数组长度为 <code>n</code> 。</p>
|
||||
|
||||
<p><code>nums</code> 的 <strong>不同元素数目差</strong> 数组可以用一个长度为 <code>n</code> 的数组 <code>diff</code> 表示,其中 <code>diff[i]</code> 等于前缀 <code>nums[0, ..., i]</code> 中不同元素的数目 <strong>减去</strong> 后缀 <code>nums[i + 1, ..., n - 1]</code> 中不同元素的数目。</p>
|
||||
|
||||
<p>返回<em> </em><code>nums</code> 的 <strong>不同元素数目差</strong> 数组。</p>
|
||||
|
||||
<p>注意 <code>nums[i, ..., j]</code> 表示 <code>nums</code> 的一个从下标 <code>i</code> 开始到下标 <code>j</code> 结束的子数组(包含下标 <code>i</code> 和 <code>j</code> 对应元素)。特别需要说明的是,如果 <code>i > j</code> ,则 <code>nums[i, ..., j]</code> 表示一个空子数组。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>nums = [1,2,3,4,5]
|
||||
<strong>输出:</strong>[-3,-1,1,3,5]
|
||||
<strong>解释:
|
||||
</strong>对于 i = 0,前缀中有 1 个不同的元素,而在后缀中有 4 个不同的元素。因此,diff[0] = 1 - 4 = -3 。
|
||||
对于 i = 1,前缀中有 2 个不同的元素,而在后缀中有 3 个不同的元素。因此,diff[1] = 2 - 3 = -1 。
|
||||
对于 i = 2,前缀中有 3 个不同的元素,而在后缀中有 2 个不同的元素。因此,diff[2] = 3 - 2 = 1 。
|
||||
对于 i = 3,前缀中有 4 个不同的元素,而在后缀中有 1 个不同的元素。因此,diff[3] = 4 - 1 = 3 。
|
||||
对于 i = 4,前缀中有 5 个不同的元素,而在后缀中有 0 个不同的元素。因此,diff[4] = 5 - 0 = 5 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>nums = [3,2,3,4,2]
|
||||
<strong>输出:</strong>[-2,-1,0,2,3]
|
||||
<strong>解释:</strong>
|
||||
对于 i = 0,前缀中有 1 个不同的元素,而在后缀中有 3 个不同的元素。因此,diff[0] = 1 - 3 = -2 。
|
||||
对于 i = 1,前缀中有 2 个不同的元素,而在后缀中有 3 个不同的元素。因此,diff[1] = 2 - 3 = -1 。
|
||||
对于 i = 2,前缀中有 2 个不同的元素,而在后缀中有 2 个不同的元素。因此,diff[2] = 2 - 2 = 0 。
|
||||
对于 i = 3,前缀中有 3 个不同的元素,而在后缀中有 1 个不同的元素。因此,diff[3] = 3 - 1 = 2 。
|
||||
对于 i = 4,前缀中有 3 个不同的元素,而在后缀中有 0 个不同的元素。因此,diff[4] = 3 - 0 = 3 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n == nums.length <= 50</code></li>
|
||||
<li><code>1 <= nums[i] <= 50</code></li>
|
||||
</ul>
|
@ -0,0 +1,50 @@
|
||||
<p><code>n</code> 个朋友在玩游戏。这些朋友坐成一个圈,按 <strong>顺时针方向</strong> 从 <code>1</code> 到 <code>n</code> 编号。从第 <code>i</code> 个朋友的位置开始顺时针移动 <code>1</code> 步会到达第 <code>(i + 1)</code> 个朋友的位置(<code>1 <= i < n</code>),而从第 <code>n</code> 个朋友的位置开始顺时针移动 <code>1</code> 步会回到第 <code>1</code> 个朋友的位置。</p>
|
||||
|
||||
<p>游戏规则如下:</p>
|
||||
|
||||
<p>第 <code>1</code> 个朋友接球。</p>
|
||||
|
||||
<ul>
|
||||
<li>接着,第 <code>1</code> 个朋友将球传给距离他顺时针方向 <code>k</code> 步的朋友。</li>
|
||||
<li>然后,接球的朋友应该把球传给距离他顺时针方向 <code>2 * k</code> 步的朋友。</li>
|
||||
<li>接着,接球的朋友应该把球传给距离他顺时针方向 <code>3 * k</code> 步的朋友,以此类推。</li>
|
||||
</ul>
|
||||
|
||||
<p>换句话说,在第 <code>i</code> 轮中持有球的那位朋友需要将球传递给距离他顺时针方向 <code>i * k</code> 步的朋友。</p>
|
||||
|
||||
<p>当某个朋友第 2 次接到球时,游戏结束。</p>
|
||||
|
||||
<p>在整场游戏中没有接到过球的朋友是 <strong>输家</strong> 。</p>
|
||||
|
||||
<p>给你参与游戏的朋友数量 <code>n</code> 和一个整数 <code>k</code> ,请按升序排列返回包含所有输家编号的数组 <code>answer</code> 作为答案。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>n = 5, k = 2
|
||||
<strong>输出:</strong>[4,5]
|
||||
<strong>解释:</strong>以下为游戏进行情况:
|
||||
1)第 1 个朋友接球,第 <code>1</code> 个朋友将球传给距离他顺时针方向 2 步的玩家 —— 第 3 个朋友。
|
||||
2)第 3 个朋友将球传给距离他顺时针方向 4 步的玩家 —— 第 2 个朋友。
|
||||
3)第 2 个朋友将球传给距离他顺时针方向 6 步的玩家 —— 第 3 个朋友。
|
||||
4)第 3 个朋友接到两次球,游戏结束。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>n = 4, k = 4
|
||||
<strong>输出:</strong>[2,3,4]
|
||||
<strong>解释:</strong>以下为游戏进行情况:
|
||||
1)第 1 个朋友接球,第 <code>1</code> 个朋友将球传给距离他顺时针方向 4 步的玩家 —— 第 1 个朋友。
|
||||
2)第 1 个朋友接到两次球,游戏结束。</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= k <= n <= 50</code></li>
|
||||
</ul>
|
29
leetcode-cn/problem (Chinese)/提取咒文 [kjpLFZ].md
Normal file
29
leetcode-cn/problem (Chinese)/提取咒文 [kjpLFZ].md
Normal file
@ -0,0 +1,29 @@
|
||||
随着兽群逐渐远去,一座大升降机缓缓的从地下升到了远征队面前。借由这台升降机,他们将能够到达地底的永恒至森。
|
||||
在升降机的操作台上,是一个由魔法符号组成的矩阵,为了便于辨识,我们用小写字母来表示。 `matrix[i][j]` 表示矩阵第 `i` 行 `j` 列的字母。该矩阵上有一个提取装置,可以对所在位置的字母提取。
|
||||
提取装置初始位于矩阵的左上角 `[0,0]`,可以通过每次操作移动到上、下、左、右相邻的 1 格位置中。提取装置每次移动或每次提取均记为一次操作。
|
||||
|
||||
远征队需要按照顺序,从矩阵中逐一取出字母以组成 `mantra`,才能够成功的启动升降机。请返回他们 **最少** 需要消耗的操作次数。如果无法完成提取,返回 `-1`。
|
||||
|
||||
**注意:**
|
||||
- 提取装置可对同一位置的字母重复提取,每次提取一个
|
||||
- 提取字母时,需按词语顺序依次提取
|
||||
|
||||
**示例 1:**
|
||||
>输入:`matrix = ["sd","ep"], mantra = "speed"`
|
||||
>
|
||||
>输出:`10`
|
||||
>
|
||||
>解释:如下图所示
|
||||
![矩阵 (2).gif](https://pic.leetcode-cn.com/1646288670-OTlvAl-%E7%9F%A9%E9%98%B5%20\(2\).gif)
|
||||
|
||||
**示例 2:**
|
||||
>输入:`matrix = ["abc","daf","geg"], mantra = "sad"`
|
||||
>
|
||||
>输出:`-1`
|
||||
>
|
||||
>解释:矩阵中不存在 `s` ,无法提取词语
|
||||
|
||||
**提示:**
|
||||
- `0 < matrix.length, matrix[i].length <= 100`
|
||||
- `0 < mantra.length <= 100`
|
||||
- `matrix 和 mantra` 仅由小写字母组成
|
33
leetcode-cn/problem (Chinese)/最大或值 [maximum-or].html
Normal file
33
leetcode-cn/problem (Chinese)/最大或值 [maximum-or].html
Normal file
@ -0,0 +1,33 @@
|
||||
<p>给你一个下标从 <strong>0</strong> 开始长度为 <code>n</code> 的整数数组 <code>nums</code> 和一个整数 <code>k</code> 。每一次操作中,你可以选择一个数并将它乘 <code>2</code> 。</p>
|
||||
|
||||
<p>你最多可以进行 <code>k</code> 次操作,请你返回<em> </em><code>nums[0] | nums[1] | ... | nums[n - 1]</code> 的最大值。</p>
|
||||
|
||||
<p><code>a | b</code> 表示两个整数 <code>a</code> 和 <code>b</code> 的 <strong>按位或</strong> 运算。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>nums = [12,9], k = 1
|
||||
<b>输出:</b>30
|
||||
<b>解释:</b>如果我们对下标为 1 的元素进行操作,新的数组为 [12,18] 。此时得到最优答案为 12 和 18 的按位或运算的结果,也就是 30 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>nums = [8,1,2], k = 2
|
||||
<b>输出:</b>35
|
||||
<b>解释:</b>如果我们对下标 0 处的元素进行操作,得到新数组 [32,1,2] 。此时得到最优答案为 32|1|2 = 35 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>
|
||||
<li><code>1 <= k <= 15</code></li>
|
||||
</ul>
|
@ -0,0 +1,45 @@
|
||||
<p>给你一个下标从 <strong>0</strong> 开始、长度为 <code>n</code> 的数组 <code>nums</code> 。一开始,所有元素都是 <strong>未染色</strong> (值为 <code>0</code> )的。</p>
|
||||
|
||||
<p>给你一个二维整数数组 <code>queries</code> ,其中 <code>queries[i] = [index<sub>i</sub>, color<sub>i</sub>]</code> 。</p>
|
||||
|
||||
<p>对于每个操作,你需要将数组 <code>nums</code> 中下标为 <code>index<sub>i</sub></code> 的格子染色为 <code>color<sub>i</sub></code> 。</p>
|
||||
|
||||
<p>请你返回一个长度与 <code>queries</code> 相等的数组<em> </em><code>answer</code><em> </em>,其中<em> </em><code>answer[i]</code>是前 <code>i</code> 个操作 <strong>之后</strong> ,相邻元素颜色相同的数目。</p>
|
||||
|
||||
<p>更正式的,<code>answer[i]</code> 是执行完前 <code>i</code> 个操作后,<code>0 <= j < n - 1</code> 的下标 <code>j</code> 中,满足 <code>nums[j] == nums[j + 1]</code> 且 <code>nums[j] != 0</code> 的数目。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>n = 4, queries = [[0,2],[1,2],[3,1],[1,1],[2,1]]
|
||||
<b>输出:</b>[0,1,1,0,2]
|
||||
<b>解释:</b>一开始数组 nums = [0,0,0,0] ,0 表示数组中还没染色的元素。
|
||||
- 第 1 个操作后,nums = [2,0,0,0] 。相邻元素颜色相同的数目为 0 。
|
||||
- 第 2 个操作后,nums = [2,2,0,0] 。相邻元素颜色相同的数目为 1 。
|
||||
- 第 3 个操作后,nums = [2,2,0,1] 。相邻元素颜色相同的数目为 1 。
|
||||
- 第 4 个操作后,nums = [2,1,0,1] 。相邻元素颜色相同的数目为 0 。
|
||||
- 第 5 个操作后,nums = [2,1,1,1] 。相邻元素颜色相同的数目为 2 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>n = 1, queries = [[0,100000]]
|
||||
<b>输出:</b>[0]
|
||||
<b>解释:</b>一开始数组 nums = [0] ,0 表示数组中还没染色的元素。
|
||||
- 第 1 个操作后,nums = [100000] 。相邻元素颜色相同的数目为 0 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= queries.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>queries[i].length == 2</code></li>
|
||||
<li><code>0 <= index<sub>i</sub> <= n - 1</code></li>
|
||||
<li><code>1 <= color<sub>i</sub> <= 10<sup>5</sup></code></li>
|
||||
</ul>
|
34
leetcode-cn/problem (Chinese)/生物进化录 [qoQAMX].md
Normal file
34
leetcode-cn/problem (Chinese)/生物进化录 [qoQAMX].md
Normal file
@ -0,0 +1,34 @@
|
||||
在永恒之森中,存在着一本生物进化录,以 **一个树形结构** 记载了所有生物的演化过程。经过观察并整理了各节点间的关系,`parents[i]` 表示编号 `i` 节点的父节点编号(根节点的父节点为 `-1`)。
|
||||
|
||||
为了探索和记录其中的演化规律,队伍中的炼金术师提出了一种方法,可以以字符串的形式将其复刻下来,规则如下:
|
||||
- 初始只有一个根节点,表示演化的起点,依次记录 `01` 字符串中的字符,
|
||||
- 如果记录 `0`,则在当前节点下添加一个子节点,并将指针指向新添加的子节点;
|
||||
- 如果记录 `1`,则将指针回退到当前节点的父节点处。
|
||||
|
||||
现在需要应用上述的记录方法,复刻下它的演化过程。请返回能够复刻演化过程的字符串中, **字典序最小** 的 `01` 字符串。
|
||||
|
||||
**注意:**
|
||||
- 节点指针最终可以停在任何节点上,不一定要回到根节点。
|
||||
|
||||
**示例 1:**
|
||||
> 输入:`parents = [-1,0,0,2]`
|
||||
>
|
||||
> 输出:`"00110"`
|
||||
>
|
||||
>解释:树结构如下图所示,共存在 2 种记录方案:
|
||||
>第 1 种方案为:0(记录编号 1 的节点) -> 1(回退至节点 0) -> 0(记录编号 2 的节点) -> 0((记录编号 3 的节点))
|
||||
>第 2 种方案为:0(记录编号 2 的节点) -> 0(记录编号 3 的节点) -> 1(回退至节点 2) -> 1(回退至节点 0) -> 0(记录编号 1 的节点)
|
||||
>返回字典序更小的 `"00110"`
|
||||
![image.png](https://pic.leetcode.cn/1682319485-cRVudI-image.png){:width=120px}![进化 (3).gif](https://pic.leetcode.cn/1682412701-waHdnm-%E8%BF%9B%E5%8C%96%20\(3\).gif){:width=320px}
|
||||
|
||||
|
||||
|
||||
**示例 2:**
|
||||
> 输入:`parents = [-1,0,0,1,2,2]`
|
||||
>
|
||||
> 输出:`"00101100"`
|
||||
|
||||
**提示:**
|
||||
|
||||
- `1 <= parents.length <= 10^4`
|
||||
- `-1 <= parents[i] < i` (即父节点编号小于子节点)
|
@ -0,0 +1,54 @@
|
||||
<p>下标从 <strong>0</strong> 开始、长度为 <code>n</code> 的数组 <code>derived</code> 是由同样长度为 <code>n</code> 的原始 <strong>二进制数组</strong> <code>original</code> 通过计算相邻值的 <strong>按位异或(⊕)</strong>派生而来。</p>
|
||||
|
||||
<p>特别地,对于范围 <code>[0, n - 1]</code> 内的每个下标 <code>i</code> :</p>
|
||||
|
||||
<ul>
|
||||
<li>如果 <code>i = n - 1</code> ,那么 <code>derived[i] = original[i] ⊕ original[0]</code></li>
|
||||
<li>否则 <code>derived[i] = original[i] ⊕ original[i + 1]</code></li>
|
||||
</ul>
|
||||
|
||||
<p>给你一个数组 <code>derived</code> ,请判断是否存在一个能够派生得到 <code>derived</code> 的 <strong>有效原始二进制数组</strong> <code>original</code> 。</p>
|
||||
|
||||
<p>如果存在满足要求的原始二进制数组,返回 <em><strong>true</strong> </em>;否则,返回<em> <strong>false</strong> </em>。</p>
|
||||
|
||||
<ul>
|
||||
<li>二进制数组是仅由 <strong>0</strong> 和 <strong>1</strong> 组成的数组。</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>derived = [1,1,0]
|
||||
<strong>输出:</strong>true
|
||||
<strong>解释:</strong>能够派生得到 [1,1,0] 的有效原始二进制数组是 [0,1,0] :
|
||||
derived[0] = original[0] ⊕ original[1] = 0 ⊕ 1 = 1
|
||||
derived[1] = original[1] ⊕ original[2] = 1 ⊕ 0 = 1
|
||||
derived[2] = original[2] ⊕ original[0] = 0 ⊕ 0 = 0
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>derived = [1,1]
|
||||
<strong>输出:</strong>true
|
||||
<strong>解释:</strong>能够派生得到 [1,1] 的有效原始二进制数组是 [0,1] :
|
||||
derived[0] = original[0] ⊕ original[1] = 1
|
||||
derived[1] = original[1] ⊕ original[0] = 1
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>derived = [1,0]
|
||||
<strong>输出:</strong>false
|
||||
<strong>解释:</strong>不存在能够派生得到 [1,0] 的有效原始二进制数组。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>n == derived.length</code></li>
|
||||
<li><code>1 <= n <= 10<sup>5</sup></code></li>
|
||||
<li><code>derived</code> 中的值不是 <strong>0</strong> 就是 <strong>1</strong> 。</li>
|
||||
</ul>
|
35
leetcode-cn/problem (Chinese)/矩阵中的和 [sum-in-a-matrix].html
Normal file
35
leetcode-cn/problem (Chinese)/矩阵中的和 [sum-in-a-matrix].html
Normal file
@ -0,0 +1,35 @@
|
||||
<p>给你一个下标从 <strong>0</strong> 开始的二维整数数组 <code>nums</code> 。一开始你的分数为 <code>0</code> 。你需要执行以下操作直到矩阵变为空:</p>
|
||||
|
||||
<ol>
|
||||
<li>矩阵中每一行选取最大的一个数,并删除它。如果一行中有多个最大的数,选择任意一个并删除。</li>
|
||||
<li>在步骤 1 删除的所有数字中找到最大的一个数字,将它添加到你的 <strong>分数</strong> 中。</li>
|
||||
</ol>
|
||||
|
||||
<p>请你返回最后的 <strong>分数</strong> 。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>nums = [[7,2,1],[6,4,2],[6,5,3],[3,2,1]]
|
||||
<b>输出:</b>15
|
||||
<b>解释:</b>第一步操作中,我们删除 7 ,6 ,6 和 3 ,将分数增加 7 。下一步操作中,删除 2 ,4 ,5 和 2 ,将分数增加 5 。最后删除 1 ,2 ,3 和 1 ,将分数增加 3 。所以总得分为 7 + 5 + 3 = 15 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>nums = [[1]]
|
||||
<b>输出:</b>1
|
||||
<b>解释:</b>我们删除 1 并将分数增加 1 ,所以返回 1 。</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 300</code></li>
|
||||
<li><code>1 <= nums[i].length <= 500</code></li>
|
||||
<li><code>0 <= nums[i][j] <= 10<sup>3</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,41 @@
|
||||
<p>给你一个下标从 <strong>0</strong> 开始、大小为 <code>m x n</code> 的矩阵 <code>grid</code> ,矩阵由若干 <strong>正</strong> 整数组成。</p>
|
||||
|
||||
<p>你可以从矩阵第一列中的 <strong>任一</strong> 单元格出发,按以下方式遍历 <code>grid</code> :</p>
|
||||
|
||||
<ul>
|
||||
<li>从单元格 <code>(row, col)</code> 可以移动到 <code>(row - 1, col + 1)</code>、<code>(row, col + 1)</code> 和 <code>(row + 1, col + 1)</code> 三个单元格中任一满足值 <strong>严格</strong> 大于当前单元格的单元格。</li>
|
||||
</ul>
|
||||
|
||||
<p>返回你在矩阵中能够 <strong>移动</strong> 的 <strong>最大</strong> 次数。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2023/04/11/yetgriddrawio-10.png" style="width: 201px; height: 201px;">
|
||||
<pre><strong>输入:</strong>grid = [[2,4,3,5],[5,4,9,3],[3,4,2,11],[10,9,13,15]]
|
||||
<strong>输出:</strong>3
|
||||
<strong>解释:</strong>可以从单元格 (0, 0) 开始并且按下面的路径移动:
|
||||
- (0, 0) -> (0, 1).
|
||||
- (0, 1) -> (1, 2).
|
||||
- (1, 2) -> (2, 3).
|
||||
可以证明这是能够移动的最大次数。</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><img alt="" src="https://assets.leetcode.com/uploads/2023/04/12/yetgrid4drawio.png">
|
||||
<strong>输入:</strong>grid = [[3,2,4],[2,1,9],[1,1,7]]
|
||||
<strong>输出:</strong>0
|
||||
<strong>解释:</strong>从第一列的任一单元格开始都无法移动。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>m == grid.length</code></li>
|
||||
<li><code>n == grid[i].length</code></li>
|
||||
<li><code>2 <= m, n <= 1000</code></li>
|
||||
<li><code>4 <= m * n <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= grid[i][j] <= 10<sup>6</sup></code></li>
|
||||
</ul>
|
26
leetcode-cn/problem (Chinese)/符文储备 [W2ZX4X].md
Normal file
26
leetcode-cn/problem (Chinese)/符文储备 [W2ZX4X].md
Normal file
@ -0,0 +1,26 @@
|
||||
远征队在出发前需要携带一些「符文」,作为后续的冒险储备。`runes[i]` 表示第 `i` 枚符文的魔力值。
|
||||
|
||||
他们将从中选取若干符文进行携带,并对这些符文进行重新排列,以确保任意相邻的两块符文之间的魔力值相差不超过 `1`。
|
||||
|
||||
请返回他们能够携带的符文 **最大数量**。
|
||||
|
||||
**示例 1:**
|
||||
>输入:`runes = [1,3,5,4,1,7]`
|
||||
>
|
||||
>输出:`3`
|
||||
>
|
||||
>解释:最佳的选择方案为[3,5,4]
|
||||
>将其排列为 [3,4,5] 后,任意相邻的两块符文魔力值均不超过 `1`,携带数量为 `3`
|
||||
>其他满足条件的方案为 [1,1] 和 [7],数量均小于 3。
|
||||
>因此返回可携带的最大数量 `3`。
|
||||
|
||||
**示例 2:**
|
||||
>输入:`runes = [1,1,3,3,2,4]`
|
||||
>
|
||||
>输出:`6`
|
||||
>
|
||||
>解释:排列为 [1,1,2,3,3,4],可携带所有的符文
|
||||
|
||||
**提示:**
|
||||
- `1 <= runes.length <= 10^4`
|
||||
- `0 <= runes[i] <= 10^4`
|
@ -0,0 +1,44 @@
|
||||
<p>给你一个整数 <code>n</code> 。现有一个包含 <code>n</code> 个顶点的 <strong>无向</strong> 图,顶点按从 <code>0</code> 到 <code>n - 1</code> 编号。给你一个二维整数数组 <code>edges</code> 其中 <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> 表示顶点 <code>a<sub>i</sub></code> 和 <code>b<sub>i</sub></code> 之间存在一条 <strong>无向</strong> 边。</p>
|
||||
|
||||
<p>返回图中 <strong>完全连通分量</strong> 的数量。</p>
|
||||
|
||||
<p>如果在子图中任意两个顶点之间都存在路径,并且子图中没有任何一个顶点与子图外部的顶点共享边,则称其为 <strong>连通分量</strong> 。</p>
|
||||
|
||||
<p>如果连通分量中每对节点之间都存在一条边,则称其为 <strong>完全连通分量</strong> 。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2023/04/11/screenshot-from-2023-04-11-23-31-23.png" style="width: 671px; height: 270px;" /></strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>n = 6, edges = [[0,1],[0,2],[1,2],[3,4]]
|
||||
<strong>输出:</strong>3
|
||||
<strong>解释:</strong>如上图所示,可以看到此图所有分量都是完全连通分量。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2023/04/11/screenshot-from-2023-04-11-23-32-00.png" style="width: 671px; height: 270px;" /></strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>n = 6, edges = [[0,1],[0,2],[1,2],[3,4],[3,5]]
|
||||
<strong>输出:</strong>1
|
||||
<strong>解释:</strong>包含节点 0、1 和 2 的分量是完全连通分量,因为每对节点之间都存在一条边。
|
||||
包含节点 3 、4 和 5 的分量不是完全连通分量,因为节点 4 和 5 之间不存在边。
|
||||
因此,在图中完全连接分量的数量是 1 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n <= 50</code></li>
|
||||
<li><code>0 <= edges.length <= n * (n - 1) / 2</code></li>
|
||||
<li><code>edges[i].length == 2</code></li>
|
||||
<li><code>0 <= a<sub>i</sub>, b<sub>i</sub> <= n - 1</code></li>
|
||||
<li><code>a<sub>i</sub> != b<sub>i</sub></code></li>
|
||||
<li>不存在重复的边</li>
|
||||
</ul>
|
@ -0,0 +1,40 @@
|
||||
<p>给你一个下标从 <strong>0</strong> 开始的字符串 <code>details</code> 。<code>details</code> 中每个元素都是一位乘客的信息,信息用长度为 <code>15</code> 的字符串表示,表示方式如下:</p>
|
||||
|
||||
<ul>
|
||||
<li>前十个字符是乘客的手机号码。</li>
|
||||
<li>接下来的一个字符是乘客的性别。</li>
|
||||
<li>接下来两个字符是乘客的年龄。</li>
|
||||
<li>最后两个字符是乘客的座位号。</li>
|
||||
</ul>
|
||||
|
||||
<p>请你返回乘客中年龄 <strong>严格大于 60 岁</strong> 的人数。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>details = ["7868190130M7522","5303914400F9211","9273338290F4010"]
|
||||
<b>输出:</b>2
|
||||
<b>解释:</b>下标为 0 ,1 和 2 的乘客年龄分别为 75 ,92 和 40 。所以有 2 人年龄大于 60 岁。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>details = ["1313579440F2036","2921522980M5644"]
|
||||
<b>输出:</b>0
|
||||
<b>解释:</b>没有乘客的年龄大于 60 岁。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= details.length <= 100</code></li>
|
||||
<li><code>details[i].length == 15</code></li>
|
||||
<li><code>details[i]</code> 中的数字只包含 <code>'0'</code> 到 <code>'9'</code> 。</li>
|
||||
<li><code>details[i][10]</code> 是 <code>'M'</code> ,<code>'F'</code> 或者 <code>'O'</code> 之一。</li>
|
||||
<li>所有乘客的手机号码和座位号互不相同。</li>
|
||||
</ul>
|
50
leetcode-cn/problem (Chinese)/节流 [throttle].html
Normal file
50
leetcode-cn/problem (Chinese)/节流 [throttle].html
Normal file
@ -0,0 +1,50 @@
|
||||
<p>现给定一个函数 <code>fn</code> 和一个以毫秒为单位的时间 <code>t</code> ,请你返回该函数的 <strong>节流</strong> 版本。</p>
|
||||
|
||||
<p><strong>节流</strong> 函数首先立即被调用,然后在 <code>t</code> 毫秒的时间间隔内不能再次执行,但应该存储最新的函数参数,以便在延迟结束后使用这些参数调用 <code>fn</code> 。</p>
|
||||
|
||||
<p>例如,<code>t = 50ms</code> ,并且函数在 <code>30ms</code> 、 <code>40ms</code> 和 <code>60ms</code> 时被调用。第一次函数调用会在接下来的 <code>t</code> 毫秒内阻止调用函数。第二次函数调用会保存参数,而第三次调用的参数应该覆盖当前保存的第二次调用的参数,因为第二次和第三次调用发生在 <code>80ms</code> 之前。一旦延迟时间过去,节流函数应该使用延迟期间提供的最新参数进行调用,并且还应创建另一个延迟期间,时长为 <code>80ms + t</code> 。</p>
|
||||
|
||||
<p><img alt="Throttle Diagram" src="https://assets.leetcode.com/uploads/2023/04/08/screen-shot-2023-04-08-at-120313-pm.png" style="width: 1156px; height: 372px;" />上面的图示展示了节流如何转换事件。每个矩形代表100毫秒,节流时间为400毫秒。每种颜色代表不同的输入集合。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>t = 100, calls = [{"t":20,"inputs":[1]}]
|
||||
<b>输出:</b>[{"t":20,"inputs":[1]}]
|
||||
<b>解释:</b>第一次调用总是立即执行,没有延迟。
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>t = 50, calls = [{"t":50,"inputs":[1]},{"t":75,"inputs":[2]}]
|
||||
<b>输出:</b>[{"t":50,"inputs":[1]},{"t":100,"inputs":[2]}]
|
||||
<b>解释:</b>
|
||||
第一次调用立即执行带有参数 (1) 的函数。
|
||||
第二次调用发生在 75毫秒 时,在延迟期间内,因为 50毫秒 + 50毫秒 = 100毫秒,所以下一次调用可以在 100毫秒 时执行。因此,我们保存第二次调用的参数,以便在第一次调用的回调函数中使用。
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">示例 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>t = 70, calls = [{"t":50,"inputs":[1]},{"t":75,"inputs":[2]},{"t":90,"inputs":[8]},{"t": 140, "inputs":[5,7]},{"t": 300, "inputs": [9,4]}]
|
||||
<b>输出:</b>[{"t":50,"inputs":[1]},{"t":120,"inputs":[8]},{"t":190,"inputs":[5,7]},{"t":300,"inputs":[9,4]}]
|
||||
<b>解释:</b>
|
||||
第一次调用立即执行带有参数 (1) 的函数。
|
||||
第二次调用发生在 75毫秒 时,在延迟期间内,因为 50毫秒 + 70毫秒 = 120毫秒,所以它只应保存参数。
|
||||
第三次调用也在延迟期间内,因为我们只需要最新的函数参数,所以覆盖之前的参数。延迟期过后,在 120毫秒时进行回调,并使用保存的参数进行调用。该回调会创建另一个延迟期间,时长为 120毫秒 + 70毫秒 = 190毫秒,以便下一个函数可以在 190毫秒时调用。
|
||||
第四次调用发生在 140毫秒,在延迟期间内,因此应在190毫秒时作为回调进行调用。这将创建另一个延迟期间,时长为 190毫秒 + 70毫秒 = 260毫秒。
|
||||
第五次调用发生在 300毫秒,但它是在 260毫秒 之后,所以应立即调用,并创建另一个延迟期间,时长为 300毫秒 + 70毫秒 = 370毫秒。</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= t <= 1000</code></li>
|
||||
<li><code>1 <= calls.length <= 10</code></li>
|
||||
<li><code>0 <= calls[i].t <= 1000</code></li>
|
||||
<li><code>0 <= calls[i].inputs[i], calls[i].inputs.length <= 10</code></li>
|
||||
</ul>
|
42
leetcode-cn/problem (Chinese)/英雄的力量 [power-of-heroes].html
Normal file
42
leetcode-cn/problem (Chinese)/英雄的力量 [power-of-heroes].html
Normal file
@ -0,0 +1,42 @@
|
||||
<p>给你一个下标从 <strong>0</strong> 开始的整数数组 <code>nums</code> ,它表示英雄的能力值。如果我们选出一部分英雄,这组英雄的 <strong>力量</strong> 定义为:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>i<sub>0</sub></code> ,<code>i<sub>1</sub></code> ,<span style="">... </span><code><span style="">i<sub>k</sub></span></code><span style=""> </span>表示这组英雄在数组中的下标。那么这组英雄的力量为 <code><font face="monospace">max(nums[</font>i<sub>0</sub><font face="monospace">],nums[</font>i<sub>1</sub><font face="monospace">] ... nums[</font><span style="font-size:10.8333px">i<sub>k</sub></span><font face="monospace">])<sup>2</sup> * min(nums[</font>i<sub>0</sub><font face="monospace">],nums[</font>i<sub>1</sub><font face="monospace">] ... nums[</font><span style="font-size:10.8333px">i<sub>k</sub></span><font face="monospace">])</font></code> 。</li>
|
||||
</ul>
|
||||
|
||||
<p>请你返回所有可能的 <strong>非空</strong> 英雄组的 <strong>力量</strong> 之和。由于答案可能非常大,请你将结果对 <code>10<sup>9 </sup>+ 7</code> <strong>取余。</strong></p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>nums = [2,1,4]
|
||||
<b>输出:</b>141
|
||||
<b>解释:</b>
|
||||
第 1 组:[2] 的力量为 2<sup>2</sup> * 2 = 8 。
|
||||
第 2 组:[1] 的力量为 1<sup>2</sup> * 1 = 1 。
|
||||
第 3 组:[4] 的力量为 4<sup>2</sup> * 4 = 64 。
|
||||
第 4 组:[2,1] 的力量为 2<sup>2</sup> * 1 = 4 。
|
||||
第 5 组:[2,4] 的力量为 4<sup>2</sup> * 2 = 32 。
|
||||
第 6 组:[1,4] 的力量为 4<sup>2</sup> * 1 = 16 。
|
||||
第 7 组:[2,1,4] 的力量为 4<sup>2</sup> * 1 = 16 。
|
||||
所有英雄组的力量之和为 8 + 1 + 64 + 4 + 32 + 16 + 16 = 141 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>nums = [1,1,1]
|
||||
<b>输出:</b>7
|
||||
<b>解释:</b>总共有 7 个英雄组,每一组的力量都是 1 。所以所有英雄组的力量之和为 7 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
46
leetcode-cn/problem (Chinese)/计数器 II [counter-ii].html
Normal file
46
leetcode-cn/problem (Chinese)/计数器 II [counter-ii].html
Normal file
@ -0,0 +1,46 @@
|
||||
<p>请你写一个函数 <code>createCounter</code>. 这个函数接收一个初始的整数值 <code>init</code> 并返回一个包含三个函数的对象。</p>
|
||||
|
||||
<p>这三个函数是:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>increment()</code> 将当前值加 1 并返回。</li>
|
||||
<li><code>decrement()</code> 将当前值减 1 并返回。</li>
|
||||
<li><code>reset()</code> 将当前值设置为 <code>init</code> 并返回。</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>init = 5, calls = ["increment","reset","decrement"]
|
||||
<b>输出:</b>[6,5,4]
|
||||
<strong>解释:</strong>
|
||||
const counter = createCounter(5);
|
||||
counter.increment(); // 6
|
||||
counter.reset(); // 5
|
||||
counter.decrement(); // 4
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>init = 0, calls = ["increment","increment","decrement","reset","reset"]
|
||||
<b>输出:</b>[1,2,1,0,0]
|
||||
<strong>解释:</strong>
|
||||
const counter = createCounter(0);
|
||||
counter.increment(); // 1
|
||||
counter.increment(); // 2
|
||||
counter.decrement(); // 1
|
||||
counter.reset(); // 0
|
||||
counter.reset(); // 0
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>-1000 <= init <= 1000</code></li>
|
||||
<li><code>总调用次数不会超过 1000</code></li>
|
||||
</ul>
|
70
leetcode-cn/problem (Chinese)/频率跟踪器 [frequency-tracker].html
Normal file
70
leetcode-cn/problem (Chinese)/频率跟踪器 [frequency-tracker].html
Normal file
@ -0,0 +1,70 @@
|
||||
<p>请你设计并实现一个能够对其中的值进行跟踪的数据结构,并支持对频率相关查询进行应答。</p>
|
||||
|
||||
<p>实现 <code>FrequencyTracker</code> 类:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>FrequencyTracker()</code>:使用一个空数组初始化 <code>FrequencyTracker</code> 对象。</li>
|
||||
<li><code>void add(int number)</code>:添加一个 <code>number</code> 到数据结构中。</li>
|
||||
<li><code>void deleteOne(int number)</code>:从数据结构中删除一个 <code>number</code> 。数据结构 <strong>可能不包含</strong> <code>number</code> ,在这种情况下不删除任何内容。</li>
|
||||
<li><code>bool hasFrequency(int frequency)</code>: 如果数据结构中存在出现 <code>frequency</code> 次的数字,则返回 <code>true</code>,否则返回 <code>false</code>。</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入</strong>
|
||||
["FrequencyTracker", "add", "add", "hasFrequency"]
|
||||
[[], [3], [3], [2]]
|
||||
<strong>输出</strong>
|
||||
[null, null, null, true]
|
||||
|
||||
<strong>解释</strong>
|
||||
FrequencyTracker frequencyTracker = new FrequencyTracker();
|
||||
frequencyTracker.add(3); // 数据结构现在包含 [3]
|
||||
frequencyTracker.add(3); // 数据结构现在包含 [3, 3]
|
||||
frequencyTracker.hasFrequency(2); // 返回 true ,因为 3 出现 2 次
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入</strong>
|
||||
["FrequencyTracker", "add", "deleteOne", "hasFrequency"]
|
||||
[[], [1], [1], [1]]
|
||||
<strong>输出</strong>
|
||||
[null, null, null, false]
|
||||
|
||||
<strong>解释</strong>
|
||||
FrequencyTracker frequencyTracker = new FrequencyTracker();
|
||||
frequencyTracker.add(1); // 数据结构现在包含 [1]
|
||||
frequencyTracker.deleteOne(1); // 数据结构现在为空 []
|
||||
frequencyTracker.hasFrequency(1); // 返回 false ,因为数据结构为空
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入</strong>
|
||||
["FrequencyTracker", "hasFrequency", "add", "hasFrequency"]
|
||||
[[], [2], [3], [1]]
|
||||
<strong>输出</strong>
|
||||
[null, false, null, true]
|
||||
|
||||
<strong>解释</strong>
|
||||
FrequencyTracker frequencyTracker = new FrequencyTracker();
|
||||
frequencyTracker.hasFrequency(2); // 返回 false ,因为数据结构为空
|
||||
frequencyTracker.add(3); // 数据结构现在包含 [3]
|
||||
frequencyTracker.hasFrequency(1); // 返回 true ,因为 3 出现 1 次
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= number <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= frequency <= 10<sup>5</sup></code></li>
|
||||
<li>最多调用 <code>add</code>、<code>deleteOne</code> 和 <code>hasFrequency</code> <strong>共计</strong> <code>2 * 10<sup>5</sup></code> 次</li>
|
||||
</ul>
|
@ -0,0 +1,23 @@
|
||||
<p>Given a real number between 0 and 1 (e.g., 0.72) that is passed in as a double, print the binary representation. If the number cannot be represented accurately in binary with at most 32 characters, print "ERROR".</p>
|
||||
|
||||
<p><strong>Example1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong> Input</strong>: 0.625
|
||||
<strong> Output</strong>: "0.101"
|
||||
</pre>
|
||||
|
||||
<p><strong>Example2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong> Input</strong>: 0.1
|
||||
<strong> Output</strong>: "ERROR"
|
||||
<strong> Note</strong>: 0.1 cannot be represented accurately in binary.
|
||||
</pre>
|
||||
|
||||
<p><strong>Note: </strong></p>
|
||||
|
||||
<ul>
|
||||
<li>This two charaters "0." should be counted into 32 characters.</li>
|
||||
<li>The number of decimal places for <code>num</code> is at most 6 digits</li>
|
||||
</ul>
|
@ -0,0 +1,45 @@
|
||||
<p>You are given an integer <code>n</code> representing the number of nodes in a <strong>perfect binary tree</strong> consisting of nodes numbered from <code>1</code> to <code>n</code>. The root of the tree is node <code>1</code> and each node <code>i</code> in the tree has two children where the left child is the node <code>2 * i</code> and the right child is <code>2 * i + 1</code>.</p>
|
||||
|
||||
<p>Each node in the tree also has a <strong>cost</strong> represented by a given <strong>0-indexed</strong> integer array <code>cost</code> of size <code>n</code> where <code>cost[i]</code> is the cost of node <code>i + 1</code>. You are allowed to <strong>increment</strong> the cost of <strong>any</strong> node by <code>1</code> <strong>any</strong> number of times.</p>
|
||||
|
||||
<p>Return <em>the <strong>minimum</strong> number of increments you need to make the cost of paths from the root to each <strong>leaf</strong> node equal</em>.</p>
|
||||
|
||||
<p><strong>Note</strong>:</p>
|
||||
|
||||
<ul>
|
||||
<li>A <strong>perfect binary tree </strong>is a tree where each node, except the leaf nodes, has exactly 2 children.</li>
|
||||
<li>The <strong>cost of a path</strong> is the sum of costs of nodes in the path.</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2023/04/04/binaryytreeedrawio-4.png" />
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 7, cost = [1,5,2,2,3,3,1]
|
||||
<strong>Output:</strong> 6
|
||||
<strong>Explanation:</strong> We can do the following increments:
|
||||
- Increase the cost of node 4 one time.
|
||||
- Increase the cost of node 3 three times.
|
||||
- Increase the cost of node 7 two times.
|
||||
Each path from the root to a leaf will have a total cost of 9.
|
||||
The total increments we did is 1 + 3 + 2 = 6.
|
||||
It can be shown that this is the minimum answer we can achieve.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2023/04/04/binaryytreee2drawio.png" style="width: 205px; height: 151px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 3, cost = [5,3,3]
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong> The two paths already have equal total costs, so no increments are needed.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>3 <= n <= 10<sup>5</sup></code></li>
|
||||
<li><code>n + 1</code> is a power of <code>2</code></li>
|
||||
<li><code>cost.length == n</code></li>
|
||||
<li><code>1 <= cost[i] <= 10<sup>4</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,46 @@
|
||||
<p>Given an array <code>arr</code> and a chunk size <code>size</code>, return a <strong>chunked</strong> array. A <strong>chunked</strong> array contains the original elements in <code>arr</code>, but consists of subarrays each of length <code>size</code>. The length of the last subarray may be less than <code>size</code> if <code>arr.length</code> is not evenly divisible by <code>size</code>.</p>
|
||||
|
||||
<p>You may assume the array is the output of <code>JSON.parse</code>. In other words, it is valid JSON.</p>
|
||||
|
||||
<p>Please solve it without using lodash's <code>_.chunk</code> function.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> arr = [1,2,3,4,5], size = 1
|
||||
<strong>Output:</strong> [[1],[2],[3],[4],[5]]
|
||||
<strong>Explanation:</strong> The arr has been split into subarrays each with 1 element.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> arr = [1,9,6,3,2], size = 3
|
||||
<strong>Output:</strong> [[1,9,6],[3,2]]
|
||||
<strong>Explanation:</strong> The arr has been split into subarrays with 3 elements. However, only two elements are left for the 2nd subarray.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> arr = [8,5,3,2,6], size = 6
|
||||
<strong>Output:</strong> [[8,5,3,2,6]]
|
||||
<strong>Explanation:</strong> Size is greater than arr.length thus all elements are in the first subarray.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 4:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> arr = [], size = 1
|
||||
<strong>Output:</strong> []
|
||||
<strong>Explanation:</strong> There are no elements to be chunked so an empty array is returned.</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>arr is a valid JSON array</code></li>
|
||||
<li><code>2 <= JSON.stringify(arr).length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= size <= arr.length + 1</code></li>
|
||||
</ul>
|
@ -0,0 +1,32 @@
|
||||
Write a function <code>createHelloWorld</code>. It should return a new function that always returns <code>"Hello World"</code>.
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> args = []
|
||||
<strong>Output:</strong> "Hello World"
|
||||
<strong>Explanation:</strong>
|
||||
const f = createHelloWorld();
|
||||
f(); // "Hello World"
|
||||
|
||||
The function returned by createHelloWorld should always return "Hello World".
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> args = [{},null,42]
|
||||
<strong>Output:</strong> "Hello World"
|
||||
<strong>Explanation:</strong>
|
||||
const f = createHelloWorld();
|
||||
f({}, null, 42); // "Hello World"
|
||||
|
||||
Any arguments could be passed to the function but it should still always return "Hello World".
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= args.length <= 10</code></li>
|
||||
</ul>
|
@ -0,0 +1,39 @@
|
||||
<p>Given a function <code>fn</code>, return a new function that is identical to the original function except that it ensures <code>fn</code> is called at most once.</p>
|
||||
|
||||
<ul>
|
||||
<li>The first time the returned function is called, it should return the same result as <code>fn</code>.</li>
|
||||
<li>Every subsequent time it is called, it should return <code>undefined</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> fn = (a,b,c) => (a + b + c), calls = [[1,2,3],[2,3,6]]
|
||||
<strong>Output:</strong> [{"calls":1,"value":6}]
|
||||
<strong>Explanation:</strong>
|
||||
const onceFn = once(fn);
|
||||
onceFn(1, 2, 3); // 6
|
||||
onceFn(2, 3, 6); // undefined, fn was not called
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> fn = (a,b,c) => (a * b * c), calls = [[5,7,4],[2,3,6],[4,6,8]]
|
||||
<strong>Output:</strong> [{"calls":1,"value":140}]
|
||||
<strong>Explanation:</strong>
|
||||
const onceFn = once(fn);
|
||||
onceFn(5, 7, 4); // 140
|
||||
onceFn(2, 3, 6); // undefined, fn was not called
|
||||
onceFn(4, 6, 8); // undefined, fn was not called
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= calls.length <= 10</code></li>
|
||||
<li><code>1 <= calls[i].length <= 100</code></li>
|
||||
<li><code>2 <= JSON.stringify(calls).length <= 1000</code></li>
|
||||
</ul>
|
@ -0,0 +1,125 @@
|
||||
<p>Write a function that converts an array of objects <code>arr</code> into a matrix <code>m</code>.</p>
|
||||
|
||||
<p><code>arr</code> is an array of objects or arrays. Each item in the array can be deeply nested with child arrays and child objects. It can also contain numbers, strings, booleans, and null values.</p>
|
||||
|
||||
<p>The first row <code>m</code> should be the column names. If there is no nesting, the column names are the unique keys within the objects. If there is nesting, the column names are the respective paths in the object separated by <code>"."</code>.</p>
|
||||
|
||||
<p>Each of the remaining rows corresponds to an object in <code>arr</code>. Each value in the matrix corresponds to a value in an object. If a given object doesn't contain a value for a given column, the cell should contain an empty string <code>""</code>.</p>
|
||||
|
||||
<p>The colums in the matrix should be in <strong>lexographically ascending</strong> order.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong>
|
||||
arr = [
|
||||
{"b": 1, "a": 2},
|
||||
{"b": 3, "a": 4}
|
||||
]
|
||||
<strong>Output:</strong>
|
||||
[
|
||||
["a", "b"],
|
||||
[2, 1],
|
||||
[4, 3]
|
||||
]
|
||||
|
||||
<strong>Explanation:</strong>
|
||||
There are two unique column names in the two objects: "a" and "b".
|
||||
"a" corresponds with [2, 4].
|
||||
"b" coresponds with [1, 3].
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong>
|
||||
arr = [
|
||||
{"a": 1, "b": 2},
|
||||
{"c": 3, "d": 4},
|
||||
{}
|
||||
]
|
||||
<strong>Output:</strong>
|
||||
[
|
||||
["a", "b", "c", "d"],
|
||||
[1, 2, "", ""],
|
||||
["", "", 3, 4],
|
||||
["", "", "", ""]
|
||||
]
|
||||
|
||||
<strong>Explanation:</strong>
|
||||
There are 4 unique column names: "a", "b", "c", "d".
|
||||
The first object has values associated with "a" and "b".
|
||||
The second object has values associated with "c" and "d".
|
||||
The third object has no keys, so it is just a row of empty strings.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong>
|
||||
arr = [
|
||||
{"a": {"b": 1, "c": 2}},
|
||||
{"a": {"b": 3, "d": 4}}
|
||||
]
|
||||
<strong>Output:</strong>
|
||||
[
|
||||
["a.b", "a.c", "a.d"],
|
||||
[1, 2, ""],
|
||||
[3, "", 4]
|
||||
]
|
||||
|
||||
<strong>Explanation:</strong>
|
||||
In this example, the objects are nested. The keys represent the full path to each value separated by periods.
|
||||
There are three paths: "a.b", "a.c", "a.d".
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 4:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong>
|
||||
arr = [
|
||||
[{"a": null}],
|
||||
[{"b": true}],
|
||||
[{"c": "x"}]
|
||||
]
|
||||
<strong>Output:</strong>
|
||||
[
|
||||
["0.a", "0.b", "0.c"],
|
||||
[null, "", ""],
|
||||
["", true, ""],
|
||||
["", "", "x"]
|
||||
]
|
||||
|
||||
<strong>Explanation:</strong>
|
||||
Arrays are also considered objects with their keys being their indices.
|
||||
Each array has one element so the keys are "0.a", "0.b", and "0.c".
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 5:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong>
|
||||
arr = [
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
]
|
||||
<strong>Output:</strong>
|
||||
[
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
[]
|
||||
]
|
||||
|
||||
<strong>Explanation:</strong>
|
||||
There are no keys so every row is an empty array.</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= arr.length <= 1000</code></li>
|
||||
<li><code>unique keys <= 1000</code></li>
|
||||
</ul>
|
@ -0,0 +1,40 @@
|
||||
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of length <code>n</code>.</p>
|
||||
|
||||
<p>The <strong>distinct difference</strong> array of <code>nums</code> is an array <code>diff</code> of length <code>n</code> such that <code>diff[i]</code> is equal to the number of distinct elements in the suffix <code>nums[i + 1, ..., n - 1]</code> <strong>subtracted from</strong> the number of distinct elements in the prefix <code>nums[0, ..., i]</code>.</p>
|
||||
|
||||
<p>Return <em>the <strong>distinct difference</strong> array of </em><code>nums</code>.</p>
|
||||
|
||||
<p>Note that <code>nums[i, ..., j]</code> denotes the subarray of <code>nums</code> starting at index <code>i</code> and ending at index <code>j</code> inclusive. Particularly, if <code>i > j</code> then <code>nums[i, ..., j]</code> denotes an empty subarray.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,2,3,4,5]
|
||||
<strong>Output:</strong> [-3,-1,1,3,5]
|
||||
<strong>Explanation:</strong> For index i = 0, there is 1 element in the prefix and 4 distinct elements in the suffix. Thus, diff[0] = 1 - 4 = -3.
|
||||
For index i = 1, there are 2 distinct elements in the prefix and 3 distinct elements in the suffix. Thus, diff[1] = 2 - 3 = -1.
|
||||
For index i = 2, there are 3 distinct elements in the prefix and 2 distinct elements in the suffix. Thus, diff[2] = 3 - 2 = 1.
|
||||
For index i = 3, there are 4 distinct elements in the prefix and 1 distinct element in the suffix. Thus, diff[3] = 4 - 1 = 3.
|
||||
For index i = 4, there are 5 distinct elements in the prefix and no elements in the suffix. Thus, diff[4] = 5 - 0 = 5.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [3,2,3,4,2]
|
||||
<strong>Output:</strong> [-2,-1,0,2,3]
|
||||
<strong>Explanation:</strong> For index i = 0, there is 1 element in the prefix and 3 distinct elements in the suffix. Thus, diff[0] = 1 - 3 = -2.
|
||||
For index i = 1, there are 2 distinct elements in the prefix and 3 distinct elements in the suffix. Thus, diff[1] = 2 - 3 = -1.
|
||||
For index i = 2, there are 2 distinct elements in the prefix and 2 distinct elements in the suffix. Thus, diff[2] = 2 - 2 = 0.
|
||||
For index i = 3, there are 3 distinct elements in the prefix and 1 distinct element in the suffix. Thus, diff[3] = 3 - 1 = 2.
|
||||
For index i = 4, there are 3 distinct elements in the prefix and no elements in the suffix. Thus, diff[4] = 3 - 0 = 3.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n == nums.length <= 50</code></li>
|
||||
<li><code>1 <= nums[i] <= 50</code></li>
|
||||
</ul>
|
@ -0,0 +1,49 @@
|
||||
<p>There are <code>n</code> friends that are playing a game. The friends are sitting in a circle and are numbered from <code>1</code> to <code>n</code> in <strong>clockwise order</strong>. More formally, moving clockwise from the <code>i<sup>th</sup></code> friend brings you to the <code>(i+1)<sup>th</sup></code> friend for <code>1 <= i < n</code>, and moving clockwise from the <code>n<sup>th</sup></code> friend brings you to the <code>1<sup>st</sup></code> friend.</p>
|
||||
|
||||
<p>The rules of the game are as follows:</p>
|
||||
|
||||
<p><code>1<sup>st</sup></code> friend receives the ball.</p>
|
||||
|
||||
<ul>
|
||||
<li>After that, <code>1<sup>st</sup></code> friend passes it to the friend who is <code>k</code> steps away from them in the <strong>clockwise</strong> direction.</li>
|
||||
<li>After that, the friend who receives the ball should pass it to the friend who is <code>2 * k</code> steps away from them in the <strong>clockwise</strong> direction.</li>
|
||||
<li>After that, the friend who receives the ball should pass it to the friend who is <code>3 * k</code> steps away from them in the <strong>clockwise</strong> direction, and so on and so forth.</li>
|
||||
</ul>
|
||||
|
||||
<p>In other words, on the <code>i<sup>th</sup></code> turn, the friend holding the ball should pass it to the friend who is <code>i * k</code> steps away from them in the <strong>clockwise</strong> direction.</p>
|
||||
|
||||
<p>The game is finished when some friend receives the ball for the second time.</p>
|
||||
|
||||
<p>The <strong>losers</strong> of the game are friends who did not receive the ball in the entire game.</p>
|
||||
|
||||
<p>Given the number of friends, <code>n</code>, and an integer <code>k</code>, return <em>the array answer, which contains the losers of the game in the <strong>ascending</strong> order</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 5, k = 2
|
||||
<strong>Output:</strong> [4,5]
|
||||
<strong>Explanation:</strong> The game goes as follows:
|
||||
1) Start at 1<sup>st</sup> friend and pass the ball to the friend who is 2 steps away from them - 3<sup>rd</sup> friend.
|
||||
2) 3<sup>rd</sup> friend passes the ball to the friend who is 4 steps away from them - 2<sup>nd</sup> friend.
|
||||
3) 2<sup>nd</sup> friend passes the ball to the friend who is 6 steps away from them - 3<sup>rd</sup> friend.
|
||||
4) The game ends as 3<sup>rd</sup> friend receives the ball for the second time.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 4, k = 4
|
||||
<strong>Output:</strong> [2,3,4]
|
||||
<strong>Explanation:</strong> The game goes as follows:
|
||||
1) Start at the 1<sup>st</sup> friend and pass the ball to the friend who is 4 steps away from them - 1<sup>st</sup> friend.
|
||||
2) The game ends as 1<sup>st</sup> friend receives the ball for the second time.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= k <= n <= 50</code></li>
|
||||
</ul>
|
@ -0,0 +1,31 @@
|
||||
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code> and an integer <code>k</code>. In an operation, you can choose an element and multiply it by <code>2</code>.</p>
|
||||
|
||||
<p>Return <em>the maximum possible value of </em><code>nums[0] | nums[1] | ... | nums[n - 1]</code> <em>that can be obtained after applying the operation on nums at most </em><code>k</code><em> times</em>.</p>
|
||||
|
||||
<p>Note that <code>a | b</code> denotes the <strong>bitwise or</strong> between two integers <code>a</code> and <code>b</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [12,9], k = 1
|
||||
<strong>Output:</strong> 30
|
||||
<strong>Explanation:</strong> If we apply the operation to index 1, our new array nums will be equal to [12,18]. Thus, we return the bitwise or of 12 and 18, which is 30.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [8,1,2], k = 2
|
||||
<strong>Output:</strong> 35
|
||||
<strong>Explanation:</strong> If we apply the operation twice on index 0, we yield a new array of [32,1,2]. Thus, we return 32|1|2 = 35.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>
|
||||
<li><code>1 <= k <= 15</code></li>
|
||||
</ul>
|
@ -0,0 +1,43 @@
|
||||
<p>There is a <strong>0-indexed</strong> array <code>nums</code> of length <code>n</code>. Initially, all elements are <strong>uncolored </strong>(has a value of <code>0</code>).</p>
|
||||
|
||||
<p>You are given a 2D integer array <code>queries</code> where <code>queries[i] = [index<sub>i</sub>, color<sub>i</sub>]</code>.</p>
|
||||
|
||||
<p>For each query, you color the index <code>index<sub>i</sub></code> with the color <code>color<sub>i</sub></code> in the array <code>nums</code>.</p>
|
||||
|
||||
<p>Return <em>an array </em><code>answer</code><em> of the same length as </em><code>queries</code><em> where </em><code>answer[i]</code><em> is the number of adjacent elements with the same color <strong>after</strong> the </em><code>i<sup>th</sup></code><em> query</em>.</p>
|
||||
|
||||
<p>More formally, <code>answer[i]</code> is the number of indices <code>j</code>, such that <code>0 <= j < n - 1</code> and <code>nums[j] == nums[j + 1]</code> and <code>nums[j] != 0</code> after the <code>i<sup>th</sup></code> query.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 4, queries = [[0,2],[1,2],[3,1],[1,1],[2,1]]
|
||||
<strong>Output:</strong> [0,1,1,0,2]
|
||||
<strong>Explanation:</strong> Initially array nums = [0,0,0,0], where 0 denotes uncolored elements of the array.
|
||||
- After the 1<sup>st</sup> query nums = [2,0,0,0]. The count of adjacent elements with the same color is 0.
|
||||
- After the 2<sup>nd</sup> query nums = [2,2,0,0]. The count of adjacent elements with the same color is 1.
|
||||
- After the 3<sup>rd</sup> query nums = [2,2,0,1]. The count of adjacent elements with the same color is 1.
|
||||
- After the 4<sup>th</sup> query nums = [2,1,0,1]. The count of adjacent elements with the same color is 0.
|
||||
- After the 5<sup>th</sup> query nums = [2,1,1,1]. The count of adjacent elements with the same color is 2.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 1, queries = [[0,100000]]
|
||||
<strong>Output:</strong> [0]
|
||||
<strong>Explanation:</strong> Initially array nums = [0], where 0 denotes uncolored elements of the array.
|
||||
- After the 1<sup>st</sup> query nums = [100000]. The count of adjacent elements with the same color is 0.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= queries.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>queries[i].length == 2</code></li>
|
||||
<li><code>0 <= index<sub>i</sub> <= n - 1</code></li>
|
||||
<li><code>1 <= color<sub>i</sub> <= 10<sup>5</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,55 @@
|
||||
<p>A <strong>0-indexed</strong> array <code>derived</code> with length <code>n</code> is derived by computing the <strong>bitwise XOR</strong> (⊕) of adjacent values in a <strong>binary array</strong> <code>original</code> of length <code>n</code>.</p>
|
||||
|
||||
<p>Specifically, for each index <code>i</code> in the range <code>[0, n - 1]</code>:</p>
|
||||
|
||||
<ul>
|
||||
<li>If <code>i = n - 1</code>, then <code>derived[i] = original[i] ⊕ original[0]</code>.</li>
|
||||
<li>Otherwise, <code>derived[i] = original[i] ⊕ original[i + 1]</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Given an array <code>derived</code>, your task is to determine whether there exists a <strong>valid binary array</strong> <code>original</code> that could have formed <code>derived</code>.</p>
|
||||
|
||||
<p>Return <em><strong>true</strong> if such an array exists or <strong>false</strong> otherwise.</em></p>
|
||||
|
||||
<ul>
|
||||
<li>A binary array is an array containing only <strong>0's</strong> and <strong>1's</strong></li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> derived = [1,1,0]
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong> A valid original array that gives derived is [0,1,0].
|
||||
derived[0] = original[0] ⊕ original[1] = 0 ⊕ 1 = 1
|
||||
derived[1] = original[1] ⊕ original[2] = 1 ⊕ 0 = 1
|
||||
derived[2] = original[2] ⊕ original[0] = 0 ⊕ 0 = 0
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> derived = [1,1]
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong> A valid original array that gives derived is [0,1].
|
||||
derived[0] = original[0] ⊕ original[1] = 1
|
||||
derived[1] = original[1] ⊕ original[0] = 1
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> derived = [1,0]
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation:</strong> There is no valid original array that gives derived.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>n == derived.length</code></li>
|
||||
<li><code>1 <= n <= 10<sup>5</sup></code></li>
|
||||
<li>The values in <code>derived</code> are either <strong>0's</strong> or <strong>1's</strong></li>
|
||||
</ul>
|
@ -0,0 +1,32 @@
|
||||
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>nums</code>. Initially, your score is <code>0</code>. Perform the following operations until the matrix becomes empty:</p>
|
||||
|
||||
<ol>
|
||||
<li>From each row in the matrix, select the largest number and remove it. In the case of a tie, it does not matter which number is chosen.</li>
|
||||
<li>Identify the highest number amongst all those removed in step 1. Add that number to your <strong>score</strong>.</li>
|
||||
</ol>
|
||||
|
||||
<p>Return <em>the final <strong>score</strong>.</em></p>
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [[7,2,1],[6,4,2],[6,5,3],[3,2,1]]
|
||||
<strong>Output:</strong> 15
|
||||
<strong>Explanation:</strong> In the first operation, we remove 7, 6, 6, and 3. We then add 7 to our score. Next, we remove 2, 4, 5, and 2. We add 5 to our score. Lastly, we remove 1, 2, 3, and 1. We add 3 to our score. Thus, our final score is 7 + 5 + 3 = 15.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [[1]]
|
||||
<strong>Output:</strong> 1
|
||||
<strong>Explanation:</strong> We remove 1 and add it to the answer. We return 1.</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 300</code></li>
|
||||
<li><code>1 <= nums[i].length <= 500</code></li>
|
||||
<li><code>0 <= nums[i][j] <= 10<sup>3</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,41 @@
|
||||
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> matrix <code>grid</code> consisting of <strong>positive</strong> integers.</p>
|
||||
|
||||
<p>You can start at <strong>any</strong> cell in the first column of the matrix, and traverse the grid in the following way:</p>
|
||||
|
||||
<ul>
|
||||
<li>From a cell <code>(row, col)</code>, you can move to any of the cells: <code>(row - 1, col + 1)</code>, <code>(row, col + 1)</code> and <code>(row + 1, col + 1)</code> such that the value of the cell you move to, should be <strong>strictly</strong> bigger than the value of the current cell.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the <strong>maximum</strong> number of <strong>moves</strong> that you can perform.</em></p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2023/04/11/yetgriddrawio-10.png" style="width: 201px; height: 201px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> grid = [[2,4,3,5],[5,4,9,3],[3,4,2,11],[10,9,13,15]]
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> We can start at the cell (0, 0) and make the following moves:
|
||||
- (0, 0) -> (0, 1).
|
||||
- (0, 1) -> (1, 2).
|
||||
- (1, 2) -> (2, 3).
|
||||
It can be shown that it is the maximum number of moves that can be made.</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2023/04/12/yetgrid4drawio.png" />
|
||||
<strong>Input:</strong> grid = [[3,2,4],[2,1,9],[1,1,7]]
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong> Starting from any cell in the first column we cannot perform any moves.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>m == grid.length</code></li>
|
||||
<li><code>n == grid[i].length</code></li>
|
||||
<li><code>2 <= m, n <= 1000</code></li>
|
||||
<li><code>4 <= m * n <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= grid[i][j] <= 10<sup>6</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,40 @@
|
||||
<p>You are given an integer <code>n</code>. There is an <strong>undirected</strong> graph with <code>n</code> vertices, numbered from <code>0</code> to <code>n - 1</code>. You are given a 2D integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists an <strong>undirected</strong> edge connecting vertices <code>a<sub>i</sub></code> and <code>b<sub>i</sub></code>.</p>
|
||||
|
||||
<p>Return <em>the number of <strong>complete connected components</strong> of the graph</em>.</p>
|
||||
|
||||
<p>A <strong>connected component</strong> is a subgraph of a graph in which there exists a path between any two vertices, and no vertex of the subgraph shares an edge with a vertex outside of the subgraph.</p>
|
||||
|
||||
<p>A connected component is said to be <b>complete</b> if there exists an edge between every pair of its vertices.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<p><strong class="example"><img alt="" src="https://assets.leetcode.com/uploads/2023/04/11/screenshot-from-2023-04-11-23-31-23.png" style="width: 671px; height: 270px;" /></strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 6, edges = [[0,1],[0,2],[1,2],[3,4]]
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> From the picture above, one can see that all of the components of this graph are complete.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<p><strong class="example"><img alt="" src="https://assets.leetcode.com/uploads/2023/04/11/screenshot-from-2023-04-11-23-32-00.png" style="width: 671px; height: 270px;" /></strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 6, edges = [[0,1],[0,2],[1,2],[3,4],[3,5]]
|
||||
<strong>Output:</strong> 1
|
||||
<strong>Explanation:</strong> The component containing vertices 0, 1, and 2 is complete since there is an edge between every pair of two vertices. On the other hand, the component containing vertices 3, 4, and 5 is not complete since there is no edge between vertices 4 and 5. Thus, the number of complete components in this graph is 1.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n <= 50</code></li>
|
||||
<li><code>0 <= edges.length <= n * (n - 1) / 2</code></li>
|
||||
<li><code>edges[i].length == 2</code></li>
|
||||
<li><code>0 <= a<sub>i</sub>, b<sub>i</sub> <= n - 1</code></li>
|
||||
<li><code>a<sub>i</sub> != b<sub>i</sub></code></li>
|
||||
<li>There are no repeated edges.</li>
|
||||
</ul>
|
@ -0,0 +1,38 @@
|
||||
<p>You are given a <strong>0-indexed</strong> array of strings <code>details</code>. Each element of <code>details</code> provides information about a given passenger compressed into a string of length <code>15</code>. The system is such that:</p>
|
||||
|
||||
<ul>
|
||||
<li>The first ten characters consist of the phone number of passengers.</li>
|
||||
<li>The next character denotes the gender of the person.</li>
|
||||
<li>The following two characters are used to indicate the age of the person.</li>
|
||||
<li>The last two characters determine the seat allotted to that person.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the number of passengers who are <strong>strictly </strong><strong>more than 60 years old</strong>.</em></p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> details = ["7868190130M7522","5303914400F9211","9273338290F4010"]
|
||||
<strong>Output:</strong> 2
|
||||
<strong>Explanation:</strong> The passengers at indices 0, 1, and 2 have ages 75, 92, and 40. Thus, there are 2 people who are over 60 years old.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> details = ["1313579440F2036","2921522980M5644"]
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong> None of the passengers are older than 60.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= details.length <= 100</code></li>
|
||||
<li><code>details[i].length == 15</code></li>
|
||||
<li><code>details[i] consists of digits from '0' to '9'.</code></li>
|
||||
<li><code>details[i][10] is either 'M' or 'F' or 'O'.</code></li>
|
||||
<li>The phone numbers and seat numbers of the passengers are distinct.</li>
|
||||
</ul>
|
48
leetcode-cn/problem (English)/节流(English) [throttle].html
Normal file
48
leetcode-cn/problem (English)/节流(English) [throttle].html
Normal file
@ -0,0 +1,48 @@
|
||||
<p>Given a function <code>fn</code> and a time in milliseconds <code>t</code>, return a <strong>throttled</strong> version of that function.</p>
|
||||
|
||||
<p>A <strong>throttled</strong> function is first called without delay and then, for a time interval of <code>t</code> milliseconds, can't be executed but should store the latest function arguments provided to call <code>fn</code> with them after the end of the delay.</p>
|
||||
|
||||
<p>For instance, <code>t = 50ms</code>, and the function was called at <code>30ms</code>, <code>40ms</code>, and <code>60ms</code>. The first function call would block calling functions for the following <code>t</code> milliseconds. The second function call would save arguments, and the third call arguments should overwrite currently stored arguments from the second call because the second and third calls are called before <code>80ms</code>. Once the delay has passed, the throttled function should be called with the latest arguments provided during the delay period, and it should also create another delay period of <code>80ms + t</code>.</p>
|
||||
|
||||
<p><img alt="Throttle Diagram" src="https://assets.leetcode.com/uploads/2023/04/08/screen-shot-2023-04-08-at-120313-pm.png" style="width: 1156px; height: 372px;" />The above diagram shows how throttle will transform events. Each rectangle represents 100ms and the throttle time is 400ms. Each color represents a different set of inputs.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> t = 100, calls = [{"t":20,"inputs":[1]}]
|
||||
<strong>Output:</strong> [{"t":20,"inputs":[1]}]
|
||||
<strong>Explanation:</strong> The 1st call is always called without delay
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> t = 50, calls = [{"t":50,"inputs":[1]},{"t":75,"inputs":[2]}]
|
||||
<strong>Output:</strong> [{"t":50,"inputs":[1]},{"t":100,"inputs":[2]}]
|
||||
<strong>Explanation:</strong>
|
||||
The 1st is called a function with arguments (1) without delay.
|
||||
The 2nd is called at 75ms, within the delay period because 50ms + 50ms = 100ms, so the next call can be reached at 100ms. Therefore, we save arguments from the 2nd call to use them at the callback of the 1st call.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> t = 70, calls = [{"t":50,"inputs":[1]},{"t":75,"inputs":[2]},{"t":90,"inputs":[8]},{"t": 140, "inputs":[5,7]},{"t": 300, "inputs": [9,4]}]
|
||||
<strong>Output:</strong> [{"t":50,"inputs":[1]},{"t":120,"inputs":[8]},{"t":190,"inputs":[5,7]},{"t":300,"inputs":[9,4]}]
|
||||
<strong>Explanation:</strong>
|
||||
The 1st is called a function with arguments (1) without delay.
|
||||
The 2nd is called at 75ms within the delay period because 50ms + 70ms = 120ms, so it should only save arguments.
|
||||
The 3rd is also called within the delay period, and because we need just the latest function arguments, we overwrite previous ones. After the delay period, we do a callback at 120ms with saved arguments. That callback makes another delay period of 120ms + 70ms = 190ms so that the next function can be called at 190ms.
|
||||
The 4th is called at 140ms in the delay period, so it should be called as a callback at 190ms. That will create another delay period of 190ms + 70ms = 260ms.
|
||||
The 5th is called at 300ms, but it is after 260ms, so it should be called immediately and should create another delay period of 300ms + 70ms = 370ms.</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= t <= 1000</code></li>
|
||||
<li><code>1 <= calls.length <= 10</code></li>
|
||||
<li><code>0 <= calls[i].t <= 1000</code></li>
|
||||
<li><code>0 <= calls[i].inputs[i], calls[i].inputs.length <= 10</code></li>
|
||||
</ul>
|
@ -0,0 +1,41 @@
|
||||
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> representing the strength of some heroes. The<b> power</b> of a group of heroes is defined as follows:</p>
|
||||
|
||||
<ul>
|
||||
<li>Let <code>i<sub>0</sub></code>, <code>i<sub>1</sub></code>, ... ,<code>i<sub>k</sub></code> be the indices of the heroes in a group. Then, the power of this group is <code>max(nums[i<sub>0</sub>], nums[i<sub>1</sub>], ... ,nums[i<sub>k</sub>])<sup>2</sup> * min(nums[i<sub>0</sub>], nums[i<sub>1</sub>], ... ,nums[i<sub>k</sub>])</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the sum of the <strong>power</strong> of all <strong>non-empty</strong> groups of heroes possible.</em> Since the sum could be very large, return it <strong>modulo</strong> <code>10<sup>9 </sup>+ 7</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [2,1,4]
|
||||
<strong>Output:</strong> 141
|
||||
<strong>Explanation:</strong>
|
||||
1<sup>st</sup> group: [2] has power = 2<sup>2</sup> * 2 = 8.
|
||||
2<sup>nd</sup> group: [1] has power = 1<sup>2</sup> * 1 = 1.
|
||||
3<sup>rd</sup> group: [4] has power = 4<sup>2</sup> * 4 = 64.
|
||||
4<sup>th</sup> group: [2,1] has power = 2<sup>2</sup> * 1 = 4.
|
||||
5<sup>th</sup> group: [2,4] has power = 4<sup>2</sup> * 2 = 32.
|
||||
6<sup>th</sup> group: [1,4] has power = 4<sup>2</sup> * 1 = 16.
|
||||
7<sup>th</sup> group: [2,1,4] has power = 4<sup>2</sup> * 1 = 16.
|
||||
The sum of powers of all groups is 8 + 1 + 64 + 4 + 32 + 16 + 16 = 141.
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,1,1]
|
||||
<strong>Output:</strong> 7
|
||||
<strong>Explanation:</strong> A total of 7 groups are possible, and the power of each group will be 1. Therefore, the sum of the powers of all groups is 7.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,44 @@
|
||||
<p>Write a function <code>createCounter</code>. It should accept an initial integer <code>init</code>. It should return an object with three functions.</p>
|
||||
|
||||
<p>The three functions are:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>increment()</code> increases the current value by 1 and then returns it.</li>
|
||||
<li><code>decrement()</code> reduces the current value by 1 and then returns it.</li>
|
||||
<li><code>reset()</code> sets the current value to <code>init</code> and then returns it.</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> init = 5, calls = ["increment","reset","decrement"]
|
||||
<strong>Output:</strong> [6,5,4]
|
||||
<strong>Explanation:</strong>
|
||||
const counter = createCounter(5);
|
||||
counter.increment(); // 6
|
||||
counter.reset(); // 5
|
||||
counter.decrement(); // 4
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> init = 0, calls = ["increment","increment","decrement","reset","reset"]
|
||||
<strong>Output:</strong> [1,2,1,0,0]
|
||||
<strong>Explanation:</strong>
|
||||
const counter = createCounter(0);
|
||||
counter.increment(); // 1
|
||||
counter.increment(); // 2
|
||||
counter.decrement(); // 1
|
||||
counter.reset(); // 0
|
||||
counter.reset(); // 0
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>-1000 <= init <= 1000</code></li>
|
||||
<li><code>total calls not to exceed 1000</code></li>
|
||||
</ul>
|
@ -0,0 +1,71 @@
|
||||
<p>Design a data structure that keeps track of the values in it and answers some queries regarding their frequencies.</p>
|
||||
|
||||
<p>Implement the <code>FrequencyTracker</code> class.</p>
|
||||
|
||||
<ul>
|
||||
<li><code>FrequencyTracker()</code>: Initializes the <code>FrequencyTracker</code> object with an empty array initially.</li>
|
||||
<li><code>void add(int number)</code>: Adds <code>number</code> to the data structure.</li>
|
||||
<li><code>void deleteOne(int number)</code>: Deletes <strong>one</strong> occurence of <code>number</code> from the data structure. The data structure <strong>may not contain</strong> <code>number</code>, and in this case nothing is deleted.</li>
|
||||
<li><code>bool hasFrequency(int frequency)</code>: Returns <code>true</code> if there is a number in the data structure that occurs <code>frequency</code> number of times, otherwise, it returns <code>false</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input</strong>
|
||||
["FrequencyTracker", "add", "add", "hasFrequency"]
|
||||
[[], [3], [3], [2]]
|
||||
<strong>Output</strong>
|
||||
[null, null, null, true]
|
||||
|
||||
<strong>Explanation</strong>
|
||||
FrequencyTracker frequencyTracker = new FrequencyTracker();
|
||||
frequencyTracker.add(3); // The data structure now contains [3]
|
||||
frequencyTracker.add(3); // The data structure now contains [3, 3]
|
||||
frequencyTracker.hasFrequency(2); // Returns true, because 3 occurs twice
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input</strong>
|
||||
["FrequencyTracker", "add", "deleteOne", "hasFrequency"]
|
||||
[[], [1], [1], [1]]
|
||||
<strong>Output</strong>
|
||||
[null, null, null, false]
|
||||
|
||||
<strong>Explanation</strong>
|
||||
FrequencyTracker frequencyTracker = new FrequencyTracker();
|
||||
frequencyTracker.add(1); // The data structure now contains [1]
|
||||
frequencyTracker.deleteOne(1); // The data structure becomes empty []
|
||||
frequencyTracker.hasFrequency(1); // Returns false, because the data structure is empty
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input</strong>
|
||||
["FrequencyTracker", "hasFrequency", "add", "hasFrequency"]
|
||||
[[], [2], [3], [1]]
|
||||
<strong>Output</strong>
|
||||
[null, false, null, true]
|
||||
|
||||
<strong>Explanation</strong>
|
||||
FrequencyTracker frequencyTracker = new FrequencyTracker();
|
||||
frequencyTracker.hasFrequency(2); // Returns false, because the data structure is empty
|
||||
frequencyTracker.add(3); // The data structure now contains [3]
|
||||
frequencyTracker.hasFrequency(1); // Returns true, because 3 occurs once
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= number <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= frequency <= 10<sup>5</sup></code></li>
|
||||
<li>At most, <code>2 * 10<sup>5</sup></code> calls will be made to <code>add</code>, <code>deleteOne</code>, and <code>hasFrequency</code> in <strong>total</strong>.</li>
|
||||
</ul>
|
File diff suppressed because it is too large
Load Diff
52
leetcode/originData/[no content]bikes-last-time-used.json
Normal file
52
leetcode/originData/[no content]bikes-last-time-used.json
Normal file
@ -0,0 +1,52 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2841",
|
||||
"questionFrontendId": "2687",
|
||||
"boundTopicId": null,
|
||||
"title": "Bikes Last Time Used ",
|
||||
"titleSlug": "bikes-last-time-used",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Easy",
|
||||
"likes": 3,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"exampleTestcases": null,
|
||||
"categoryTitle": "Database",
|
||||
"contributors": [],
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"73\", \"totalSubmission\": \"96\", \"totalAcceptedRaw\": 73, \"totalSubmissionRaw\": 96, \"acRate\": \"76.0%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\":{\"Bikes\":[\"ride_id\",\"bike_number\",\"start_time\",\"end_time\"]},\"rows\":{\"Bikes\":[[1,\"W00576\",\"2012-03-25 11:30:00\",\"2012-03-25 12:40:00\"],[2,\"W00300\",\"2012-03-25 10:30:00\",\"2012-03-25 10:50:00\"],[3,\"W00455\",\"2012-03-26 14:30:00\",\"2012-03-26 17:40:00\"],[4,\"W00455\",\"2012-03-25 12:30:00\",\"2012-03-25 13:40:00\"],[5,\"W00576\",\"2012-03-25 08:10:00\",\"2012-03-25 09:10:00\"],[6,\"W00576\",\"2012-03-28 02:30:00\",\"2012-03-28 02:50:00\"]]}}",
|
||||
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Bikes (ride_id int,bike_number varchar(100), start_time datetime,end_time datetime)\"\n ],\n \"mssql\": [\n \"Create table Bikes (ride_id int,bike_number varchar(100), start_time datetime,end_time datetime)\"\n ],\n \"oraclesql\": [\n \"Create table Bikes (ride_id int,bike_number varchar(100), start_time date,end_time date)\",\n \"ALTER SESSION SET nls_date_format='YYYY-MM-DD HH24:MI:SS'\"\n ],\n \"database\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Create table If Not Exists Bikes (ride_id int,bike_number varchar(100), start_time datetime,end_time datetime)",
|
||||
"Truncate table Bikes",
|
||||
"insert into Bikes (ride_id, bike_number, start_time, end_time) values ('1', 'W00576', '2012-03-25 11:30:00', '2012-03-25 12:40:00')",
|
||||
"insert into Bikes (ride_id, bike_number, start_time, end_time) values ('2', 'W00300', '2012-03-25 10:30:00', '2012-03-25 10:50:00')",
|
||||
"insert into Bikes (ride_id, bike_number, start_time, end_time) values ('3', 'W00455', '2012-03-26 14:30:00', '2012-03-26 17:40:00')",
|
||||
"insert into Bikes (ride_id, bike_number, start_time, end_time) values ('4', 'W00455', '2012-03-25 12:30:00', '2012-03-25 13:40:00')",
|
||||
"insert into Bikes (ride_id, bike_number, start_time, end_time) values ('5', 'W00576', '2012-03-25 08:10:00', '2012-03-25 09:10:00')",
|
||||
"insert into Bikes (ride_id, bike_number, start_time, end_time) values ('6', 'W00576', '2012-03-28 02:30:00', '2012-03-28 02:50:00')"
|
||||
],
|
||||
"enableRunCode": true,
|
||||
"enableTestMode": false,
|
||||
"enableDebugger": false,
|
||||
"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>\"]}",
|
||||
"libraryUrl": null,
|
||||
"adminUrl": null,
|
||||
"challengeQuestion": null,
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2830",
|
||||
"questionFrontendId": "2669",
|
||||
"boundTopicId": null,
|
||||
"title": "Count Artist Occurrences On Spotify Ranking List",
|
||||
"titleSlug": "count-artist-occurrences-on-spotify-ranking-list",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Easy",
|
||||
"likes": 5,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"exampleTestcases": null,
|
||||
"categoryTitle": "Database",
|
||||
"contributors": [],
|
||||
"topicTags": [
|
||||
{
|
||||
"name": "Database",
|
||||
"slug": "database",
|
||||
"translatedName": null,
|
||||
"__typename": "TopicTagNode"
|
||||
}
|
||||
],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"183\", \"totalSubmission\": \"333\", \"totalAcceptedRaw\": 183, \"totalSubmissionRaw\": 333, \"acRate\": \"55.0%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\":{\"Spotify\":[\"id\",\"track_name\",\"artist\"]},\"rows\":{\"Spotify\":[[303651,\"Heart Won't Forget\",\"Ed Sheeran\"],[1046089,\"Shape of you\",\"Sia\"],[33445,\"I'm the one\",\"DJ Khalid\"],[811266,\"Young Dumb & Broke\",\"DJ Khalid\"],[505727,\"Happier\",\"Ed Sheeran\"]]}}",
|
||||
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Spotify (id int,track_name varchar(100),artist varchar(100))\"\n ],\n \"mssql\": [\n \"Create table Spotify (id int,track_name varchar(100),artist varchar(100))\"\n ],\n \"oraclesql\": [\n \"Create table Spotify (id int,track_name varchar(100),artist varchar(100))\"\n ],\n \"database\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Create table If Not Exists Spotify (id int,track_name varchar(100),artist varchar(100))",
|
||||
"Truncate table Spotify",
|
||||
"insert into Spotify (id, track_name, artist) values ('303651', 'Heart Won't Forget', 'Ed Sheeran')",
|
||||
"insert into Spotify (id, track_name, artist) values ('1046089', 'Shape of you', 'Sia')",
|
||||
"insert into Spotify (id, track_name, artist) values ('33445', 'I'm the one', 'DJ Khalid')",
|
||||
"insert into Spotify (id, track_name, artist) values ('811266', 'Young Dumb & Broke', 'DJ Khalid')",
|
||||
"insert into Spotify (id, track_name, artist) values ('505727', 'Happier', 'Ed Sheeran')"
|
||||
],
|
||||
"enableRunCode": true,
|
||||
"enableTestMode": false,
|
||||
"enableDebugger": false,
|
||||
"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>\"]}",
|
||||
"libraryUrl": null,
|
||||
"adminUrl": null,
|
||||
"challengeQuestion": null,
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
52
leetcode/originData/[no content]find-active-users.json
Normal file
52
leetcode/originData/[no content]find-active-users.json
Normal file
@ -0,0 +1,52 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2842",
|
||||
"questionFrontendId": "2688",
|
||||
"boundTopicId": null,
|
||||
"title": "Find Active Users",
|
||||
"titleSlug": "find-active-users",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Medium",
|
||||
"likes": 2,
|
||||
"dislikes": 1,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"exampleTestcases": null,
|
||||
"categoryTitle": "Database",
|
||||
"contributors": [],
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"55\", \"totalSubmission\": \"181\", \"totalAcceptedRaw\": 55, \"totalSubmissionRaw\": 181, \"acRate\": \"30.4%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\":{\"Users\":[\"user_id\",\"item\",\"created_at\",\"amount\"]},\"rows\":{\"Users\":[[5,\"Smart Crock Pot\",\"2021-09-18\",698882],[6,\"Smart Lock\",\"2021-09-14\",11487],[6,\"Smart Thermostat\",\"2021-09-10\",674762],[8,\"Smart Light Strip\",\"2021-09-29\",630773],[4,\"Smart Cat Feeder\",\"2021-09-02\",693545],[4,\"Smart Bed\",\"2021-09-13\",170249]]}}",
|
||||
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Users (user_id int, item varchar(100),created_at date,amount int)\"\n ],\n \"mssql\": [\n \"Create table Users (user_id int, item varchar(100),created_at date,amount int)\"\n ],\n \"oraclesql\": [\n \"Create table Users (user_id int, item varchar(100),created_at date,amount int)\",\n \"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"\n ],\n \"database\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Create table If Not Exists Users (user_id int, item varchar(100),created_at date,amount int)",
|
||||
"Truncate table Users",
|
||||
"insert into Users (user_id, item, created_at, amount) values ('5', 'Smart Crock Pot', '2021-09-18', '698882')",
|
||||
"insert into Users (user_id, item, created_at, amount) values ('6', 'Smart Lock', '2021-09-14', '11487')",
|
||||
"insert into Users (user_id, item, created_at, amount) values ('6', 'Smart Thermostat', '2021-09-10', '674762')",
|
||||
"insert into Users (user_id, item, created_at, amount) values ('8', 'Smart Light Strip', '2021-09-29', '630773')",
|
||||
"insert into Users (user_id, item, created_at, amount) values ('4', 'Smart Cat Feeder', '2021-09-02', '693545')",
|
||||
"insert into Users (user_id, item, created_at, amount) values ('4', 'Smart Bed', '2021-09-13', '170249')"
|
||||
],
|
||||
"enableRunCode": true,
|
||||
"enableTestMode": false,
|
||||
"enableDebugger": false,
|
||||
"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>\"]}",
|
||||
"libraryUrl": null,
|
||||
"adminUrl": null,
|
||||
"challengeQuestion": null,
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
63
leetcode/originData/[no content]find-latest-salaries.json
Normal file
63
leetcode/originData/[no content]find-latest-salaries.json
Normal file
@ -0,0 +1,63 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2829",
|
||||
"questionFrontendId": "2668",
|
||||
"boundTopicId": null,
|
||||
"title": "Find Latest Salaries",
|
||||
"titleSlug": "find-latest-salaries",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Easy",
|
||||
"likes": 6,
|
||||
"dislikes": 4,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"exampleTestcases": null,
|
||||
"categoryTitle": "Database",
|
||||
"contributors": [],
|
||||
"topicTags": [
|
||||
{
|
||||
"name": "Database",
|
||||
"slug": "database",
|
||||
"translatedName": null,
|
||||
"__typename": "TopicTagNode"
|
||||
}
|
||||
],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"202\", \"totalSubmission\": \"416\", \"totalAcceptedRaw\": 202, \"totalSubmissionRaw\": 416, \"acRate\": \"48.6%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\":{\"Salary\":[\"emp_id\",\"firstname\",\"lastname\",\"salary\",\"department_id\"]},\"rows\":{\"Salary\":[[1,\"Todd\",\"Wilson\",110000,\"D1006\"],[1,\"Todd\",\"Wilson\",106119,\"D1006\"],[2,\"Justin\",\"Simon\",128922,\"D1005\"],[2,\"Justin\",\"Simon\",130000,\"D1005\"],[3,\"Kelly\",\"Rosario\",42689,\"D1002\"],[4,\"Patricia\",\"Powell\",162825,\"D1004\"],[4,\"Patricia\",\"Powell\",170000,\"D1004\"],[5,\"Sherry\",\"Golden\",44101,\"D1002\"],[6,\"Natasha\",\"Swanson\",79632,\"D1005\"],[6,\"Natasha\",\"Swanson\",90000,\"D1005\"]]}}",
|
||||
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Salary (emp_id int,firstname varchar(100),lastname varchar(100),salary int, department_id varchar(100))\"\n ],\n \"mssql\": [\n \"Create table Salary (emp_id int,firstname varchar(100),lastname varchar(100),salary int, department_id varchar(100))\"\n ],\n \"oraclesql\": [\n \"Create table Salary (emp_id int,firstname varchar(100),lastname varchar(100),salary int, department_id varchar(100))\"\n ],\n \"database\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Create table If Not Exists Salary (emp_id int,firstname varchar(100),lastname varchar(100),salary int, department_id varchar(100))",
|
||||
"Truncate table Salary",
|
||||
"insert into Salary (emp_id, firstname, lastname, salary, department_id) values ('1', 'Todd', 'Wilson', '110000', 'D1006')",
|
||||
"insert into Salary (emp_id, firstname, lastname, salary, department_id) values ('1', 'Todd', 'Wilson', '106119', 'D1006')",
|
||||
"insert into Salary (emp_id, firstname, lastname, salary, department_id) values ('2', 'Justin', 'Simon', '128922', 'D1005')",
|
||||
"insert into Salary (emp_id, firstname, lastname, salary, department_id) values ('2', 'Justin', 'Simon', '130000', 'D1005')",
|
||||
"insert into Salary (emp_id, firstname, lastname, salary, department_id) values ('3', 'Kelly', 'Rosario', '42689', 'D1002')",
|
||||
"insert into Salary (emp_id, firstname, lastname, salary, department_id) values ('4', 'Patricia', 'Powell', '162825', 'D1004')",
|
||||
"insert into Salary (emp_id, firstname, lastname, salary, department_id) values ('4', 'Patricia', 'Powell', '170000', 'D1004')",
|
||||
"insert into Salary (emp_id, firstname, lastname, salary, department_id) values ('5', 'Sherry', 'Golden', '44101', 'D1002')",
|
||||
"insert into Salary (emp_id, firstname, lastname, salary, department_id) values ('6', 'Natasha', 'Swanson', '79632', 'D1005')",
|
||||
"insert into Salary (emp_id, firstname, lastname, salary, department_id) values ('6', 'Natasha', 'Swanson', '90000', 'D1005')"
|
||||
],
|
||||
"enableRunCode": true,
|
||||
"enableTestMode": false,
|
||||
"enableDebugger": false,
|
||||
"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>\"]}",
|
||||
"libraryUrl": null,
|
||||
"adminUrl": null,
|
||||
"challengeQuestion": null,
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2840",
|
||||
"questionFrontendId": "2686",
|
||||
"boundTopicId": null,
|
||||
"title": "Immediate Food Delivery III",
|
||||
"titleSlug": "immediate-food-delivery-iii",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Medium",
|
||||
"likes": 3,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"exampleTestcases": null,
|
||||
"categoryTitle": "Database",
|
||||
"contributors": [],
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"40\", \"totalSubmission\": \"104\", \"totalAcceptedRaw\": 40, \"totalSubmissionRaw\": 104, \"acRate\": \"38.5%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\":{\"Delivery\":[\"delivery_id\",\"customer_id\",\"order_date\",\"customer_pref_delivery_date\"]},\"rows\":{\"Delivery\":[[1,1,\"2019-08-01\",\"2019-08-02\"],[2,2,\"2019-08-01\",\"2019-08-01\"],[3,1,\"2019-08-01\",\"2019-08-01\"],[4,3,\"2019-08-02\",\"2019-08-13\"],[5,3,\"2019-08-02\",\"2019-08-02\"],[6,2,\"2019-08-02\",\"2019-08-02\"],[7,4,\"2019-08-03\",\"2019-08-03\"],[8,1,\"2019-08-03\",\"2019-08-03\"],[9,5,\"2019-08-04\",\"2019-08-18\"],[10,2,\"2019-08-04\",\"2019-08-18\"]]}}",
|
||||
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Delivery (delivery_id int, customer_id int, order_date date, customer_pref_delivery_date date)\"\n ],\n \"mssql\": [\n \"Create table Delivery (delivery_id int, customer_id int, order_date date, customer_pref_delivery_date date)\"\n ],\n \"oraclesql\": [\n \"Create table Delivery (delivery_id int, customer_id int, order_date date, customer_pref_delivery_date date)\",\n \"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"\n ],\n \"database\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Create table If Not Exists Delivery (delivery_id int, customer_id int, order_date date, customer_pref_delivery_date date)",
|
||||
"Truncate table Delivery",
|
||||
"insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('1', '1', '2019-08-01', '2019-08-02')",
|
||||
"insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('2', '2', '2019-08-01', '2019-08-01')",
|
||||
"insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('3', '1', '2019-08-01', '2019-08-01')",
|
||||
"insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('4', '3', '2019-08-02', '2019-08-13')",
|
||||
"insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('5', '3', '2019-08-02', '2019-08-02')",
|
||||
"insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('6', '2', '2019-08-02', '2019-08-02')",
|
||||
"insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('7', '4', '2019-08-03', '2019-08-03')",
|
||||
"insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('8', '1', '2019-08-03', '2019-08-03')",
|
||||
"insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('9', '5', '2019-08-04', '2019-08-18')",
|
||||
"insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('10', '2', '2019-08-04', '2019-08-18')"
|
||||
],
|
||||
"enableRunCode": true,
|
||||
"enableTestMode": false,
|
||||
"enableDebugger": false,
|
||||
"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>\"]}",
|
||||
"libraryUrl": null,
|
||||
"adminUrl": null,
|
||||
"challengeQuestion": null,
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
62
leetcode/originData/[no content]the-knights-tour.json
Normal file
62
leetcode/originData/[no content]the-knights-tour.json
Normal file
File diff suppressed because one or more lines are too long
63
leetcode/originData/allow-one-function-call.json
Normal file
63
leetcode/originData/allow-one-function-call.json
Normal file
@ -0,0 +1,63 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2796",
|
||||
"questionFrontendId": "2666",
|
||||
"boundTopicId": null,
|
||||
"title": "Allow One Function Call",
|
||||
"titleSlug": "allow-one-function-call",
|
||||
"content": "<p>Given a function <code>fn</code>, return a new function that is identical to the original function except that it ensures <code>fn</code> is called at most once.</p>\n\n<ul>\n\t<li>The first time the returned function is called, it should return the same result as <code>fn</code>.</li>\n\t<li>Every subsequent time it is called, it should return <code>undefined</code>.</li>\n</ul>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> fn = (a,b,c) => (a + b + c), calls = [[1,2,3],[2,3,6]]\n<strong>Output:</strong> [{"calls":1,"value":6}]\n<strong>Explanation:</strong>\nconst onceFn = once(fn);\nonceFn(1, 2, 3); // 6\nonceFn(2, 3, 6); // undefined, fn was not called\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> fn = (a,b,c) => (a * b * c), calls = [[5,7,4],[2,3,6],[4,6,8]]\n<strong>Output:</strong> [{"calls":1,"value":140}]\n<strong>Explanation:</strong>\nconst onceFn = once(fn);\nonceFn(5, 7, 4); // 140\nonceFn(2, 3, 6); // undefined, fn was not called\nonceFn(4, 6, 8); // undefined, fn was not called\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= calls.length <= 10</code></li>\n\t<li><code>1 <= calls[i].length <= 100</code></li>\n\t<li><code>2 <= JSON.stringify(calls).length <= 1000</code></li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Easy",
|
||||
"likes": 175,
|
||||
"dislikes": 11,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"exampleTestcases": "(a,b,c) => (a + b + c)\n[[1,2,3],[2,3,6]]\n(a,b,c) => (a * b * c)\n[[5,7,4],[2,3,6],[4,6,8]]",
|
||||
"categoryTitle": "JavaScript",
|
||||
"contributors": [],
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": [
|
||||
{
|
||||
"lang": "JavaScript",
|
||||
"langSlug": "javascript",
|
||||
"code": "/**\n * @param {Function} fn\n * @return {Function}\n */\nvar once = function(fn) {\n return function(...args){\n \n }\n};\n\n/**\n * let fn = (a,b,c) => (a + b + c)\n * let onceFn = once(fn)\n *\n * onceFn(1,2,3); // 6\n * onceFn(2,3,6); // returns undefined without calling fn\n */\n",
|
||||
"__typename": "CodeSnippetNode"
|
||||
},
|
||||
{
|
||||
"lang": "TypeScript",
|
||||
"langSlug": "typescript",
|
||||
"code": "function once<T extends (...args: any[]) => any>(fn: T): \n ((...args: Parameters<T>) => ReturnType<T> | undefined) {\n return function (...args) {\n\n };\n}\n\n/**\n * let fn = (a,b,c) => (a + b + c)\n * let onceFn = once(fn)\n *\n * onceFn(1,2,3); // 6\n * onceFn(2,3,6); // returns undefined without calling fn\n */",
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"11.8K\", \"totalSubmission\": \"12.9K\", \"totalAcceptedRaw\": 11792, \"totalSubmissionRaw\": 12852, \"acRate\": \"91.8%\"}",
|
||||
"hints": [],
|
||||
"solution": {
|
||||
"id": "1893",
|
||||
"canSeeDetail": true,
|
||||
"paidOnly": false,
|
||||
"hasVideoSolution": false,
|
||||
"paidOnlyVideo": true,
|
||||
"__typename": "ArticleNode"
|
||||
},
|
||||
"status": null,
|
||||
"sampleTestCase": "(a,b,c) => (a + b + c)\n[[1,2,3],[2,3,6]]",
|
||||
"metaData": "{\n \"name\": \"once\",\n \"params\": [\n {\n \"name\": \"fn\",\n \"type\": \"string\"\n },\n {\n \"type\": \"string\",\n \"name\": \"calls\"\n }\n ],\n \"return\": {\n \"type\": \"integer\"\n },\n \"languages\": [\n \"javascript\",\n \"typescript\"\n ],\n \"manual\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [],
|
||||
"enableRunCode": true,
|
||||
"enableTestMode": false,
|
||||
"enableDebugger": false,
|
||||
"envInfo": "{\"javascript\": [\"JavaScript\", \"<p><code>Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES6 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\\r\\n\\r\\n<p>For Priority Queue / Queue data structures, you may use 5.3.0 version of <a href=\\\"https://github.com/datastructures-js/priority-queue/tree/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\">datastructures-js/priority-queue</a> and 4.2.1 version of <a href=\\\"https://github.com/datastructures-js/queue/tree/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\">datastructures-js/queue</a>.</p>\"], \"typescript\": [\"Typescript\", \"<p><code>TypeScript 4.5.4, Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES2020 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\"]}",
|
||||
"libraryUrl": null,
|
||||
"adminUrl": null,
|
||||
"challengeQuestion": null,
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
60
leetcode/originData/array-of-objects-to-matrix.json
Normal file
60
leetcode/originData/array-of-objects-to-matrix.json
Normal file
@ -0,0 +1,60 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2769",
|
||||
"questionFrontendId": "2675",
|
||||
"boundTopicId": null,
|
||||
"title": "Array of Objects to Matrix",
|
||||
"titleSlug": "array-of-objects-to-matrix",
|
||||
"content": "<p>Write a function that converts an array of objects <code>arr</code> into a matrix <code>m</code>.</p>\n\n<p><code>arr</code> is an array of objects or arrays. Each item in the array can be deeply nested with child arrays and child objects. It can also contain numbers, strings, booleans, and null values.</p>\n\n<p>The first row <code>m</code> should be the column names. If there is no nesting, the column names are the unique keys within the objects. If there is nesting, the column names are the respective paths in the object separated by <code>"."</code>.</p>\n\n<p>Each of the remaining rows corresponds to an object in <code>arr</code>. Each value in the matrix corresponds to a value in an object. If a given object doesn't contain a value for a given column, the cell should contain an empty string <code>""</code>.</p>\n\n<p>The colums in the matrix should be in <strong>lexographically ascending</strong> order.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \narr = [\n {"b": 1, "a": 2},\n {"b": 3, "a": 4}\n]\n<strong>Output:</strong> \n[\n ["a", "b"],\n [2, 1],\n [4, 3]\n]\n\n<strong>Explanation:</strong>\nThere are two unique column names in the two objects: "a" and "b".\n"a" corresponds with [2, 4].\n"b" coresponds with [1, 3].\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> \narr = [\n {"a": 1, "b": 2},\n {"c": 3, "d": 4},\n {}\n]\n<strong>Output:</strong> \n[\n ["a", "b", "c", "d"],\n [1, 2, "", ""],\n ["", "", 3, 4],\n ["", "", "", ""]\n]\n\n<strong>Explanation:</strong>\nThere are 4 unique column names: "a", "b", "c", "d".\nThe first object has values associated with "a" and "b".\nThe second object has values associated with "c" and "d".\nThe third object has no keys, so it is just a row of empty strings.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> \narr = [\n {"a": {"b": 1, "c": 2}},\n {"a": {"b": 3, "d": 4}}\n]\n<strong>Output:</strong> \n[\n ["a.b", "a.c", "a.d"],\n [1, 2, ""],\n [3, "", 4]\n]\n\n<strong>Explanation:</strong>\nIn this example, the objects are nested. The keys represent the full path to each value separated by periods.\nThere are three paths: "a.b", "a.c", "a.d".\n</pre>\n\n<p><strong class=\"example\">Example 4:</strong></p>\n\n<pre>\n<strong>Input:</strong> \narr = [\n [{"a": null}],\n [{"b": true}],\n [{"c": "x"}]\n]\n<strong>Output:</strong> \n[\n ["0.a", "0.b", "0.c"],\n [null, "", ""],\n ["", true, ""],\n ["", "", "x"]\n]\n\n<strong>Explanation:</strong>\nArrays are also considered objects with their keys being their indices.\nEach array has one element so the keys are "0.a", "0.b", and "0.c".\n</pre>\n\n<p><strong class=\"example\">Example 5:</strong></p>\n\n<pre>\n<strong>Input:</strong> \narr = [\n {},\n {},\n {},\n]\n<strong>Output:</strong> \n[\n [],\n [],\n [],\n []\n]\n\n<strong>Explanation:</strong>\nThere are no keys so every row is an empty array.</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= arr.length <= 1000</code></li>\n\t<li><code>unique keys <= 1000</code></li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Medium",
|
||||
"likes": 14,
|
||||
"dislikes": 2,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[{\"title\": \"JSON Deep Equal\", \"titleSlug\": \"json-deep-equal\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Convert Object to JSON String\", \"titleSlug\": \"convert-object-to-json-string\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
|
||||
"exampleTestcases": "[{\"b\":1,\"a\":2},{\"b\":3,\"a\":4}]\n[{\"a\":1,\"b\":2},{\"c\":3,\"d\":4},{}]\n[{\"a\":{\"b\":1,\"c\":2}},{\"a\":{\"b\":3,\"d\":4}}]\n[[{\"a\":null}],[{\"b\":true}],[{\"c\":\"x\"}]]\n[{},{},{}]",
|
||||
"categoryTitle": "JavaScript",
|
||||
"contributors": [],
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": [
|
||||
{
|
||||
"lang": "JavaScript",
|
||||
"langSlug": "javascript",
|
||||
"code": "/**\n * @param {Array} arr\n * @return {Matrix}\n */\nvar jsonToMatrix = function(arr) {\n \n};",
|
||||
"__typename": "CodeSnippetNode"
|
||||
},
|
||||
{
|
||||
"lang": "TypeScript",
|
||||
"langSlug": "typescript",
|
||||
"code": "function jsonToMatrix(arr: any[]): (string | number | boolean | null)[] {\n\n};",
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"207\", \"totalSubmission\": \"321\", \"totalAcceptedRaw\": 207, \"totalSubmissionRaw\": 321, \"acRate\": \"64.5%\"}",
|
||||
"hints": [
|
||||
"How could you split the problem up into sub-problems?",
|
||||
"1.) Write a function that converts a single object into a dictionary that maps the path name to values. You can solve this recursively by keeping track of current path list.",
|
||||
"2.) Write a function that converts a list of dictionaries into a matrix. Start by creating a list of all possible paths in any of the dictionaries. This will represent the columns."
|
||||
],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "[{\"b\":1,\"a\":2},{\"b\":3,\"a\":4}]",
|
||||
"metaData": "{\n \"name\": \"jsonToMatrix\",\n \"params\": [\n {\n \"name\": \"arr\",\n \"type\": \"string\"\n }\n ],\n \"return\": {\n \"type\": \"string\"\n },\n \"languages\": [\n \"typescript\",\n \"javascript\"\n ],\n \"manual\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [],
|
||||
"enableRunCode": true,
|
||||
"enableTestMode": false,
|
||||
"enableDebugger": false,
|
||||
"envInfo": "{\"javascript\": [\"JavaScript\", \"<p><code>Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES6 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\\r\\n\\r\\n<p>For Priority Queue / Queue data structures, you may use 5.3.0 version of <a href=\\\"https://github.com/datastructures-js/priority-queue/tree/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\">datastructures-js/priority-queue</a> and 4.2.1 version of <a href=\\\"https://github.com/datastructures-js/queue/tree/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\">datastructures-js/queue</a>.</p>\"], \"typescript\": [\"Typescript\", \"<p><code>TypeScript 4.5.4, Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES2020 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\"]}",
|
||||
"libraryUrl": null,
|
||||
"adminUrl": null,
|
||||
"challengeQuestion": null,
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
56
leetcode/originData/chunk-array.json
Normal file
56
leetcode/originData/chunk-array.json
Normal file
@ -0,0 +1,56 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2798",
|
||||
"questionFrontendId": "2677",
|
||||
"boundTopicId": null,
|
||||
"title": "Chunk Array",
|
||||
"titleSlug": "chunk-array",
|
||||
"content": "<p>Given an array <code>arr</code> and a chunk size <code>size</code>, return a <strong>chunked</strong> array. A <strong>chunked</strong> array contains the original elements in <code>arr</code>, but consists of subarrays each of length <code>size</code>. The length of the last subarray may be less than <code>size</code> if <code>arr.length</code> is not evenly divisible by <code>size</code>.</p>\n\n<p>You may assume the array is the output of <code>JSON.parse</code>. In other words, it is valid JSON.</p>\n\n<p>Please solve it without using lodash's <code>_.chunk</code> function.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr = [1,2,3,4,5], size = 1\n<strong>Output:</strong> [[1],[2],[3],[4],[5]]\n<strong>Explanation:</strong> The arr has been split into subarrays each with 1 element.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr = [1,9,6,3,2], size = 3\n<strong>Output:</strong> [[1,9,6],[3,2]]\n<strong>Explanation:</strong> The arr has been split into subarrays with 3 elements. However, only two elements are left for the 2nd subarray.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr = [8,5,3,2,6], size = 6\n<strong>Output:</strong> [[8,5,3,2,6]]\n<strong>Explanation:</strong> Size is greater than arr.length thus all elements are in the first subarray.\n</pre>\n\n<p><strong class=\"example\">Example 4:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr = [], size = 1\n<strong>Output:</strong> []\n<strong>Explanation:</strong> There are no elements to be chunked so an empty array is returned.</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>arr is a valid JSON array</code></li>\n\t<li><code>2 <= JSON.stringify(arr).length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= size <= arr.length + 1</code></li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Easy",
|
||||
"likes": 35,
|
||||
"dislikes": 1,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"exampleTestcases": "[1,2,3,4,5]\n1\n[1,9,6,3,2]\n3\n[8,5,3,2,6]\n6\n[]\n1",
|
||||
"categoryTitle": "JavaScript",
|
||||
"contributors": [],
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": [
|
||||
{
|
||||
"lang": "JavaScript",
|
||||
"langSlug": "javascript",
|
||||
"code": "/**\n * @param {Array} arr\n * @param {number} size\n * @return {Array[]}\n */\nvar chunk = function(arr, size) {\n \n};\n",
|
||||
"__typename": "CodeSnippetNode"
|
||||
},
|
||||
{
|
||||
"lang": "TypeScript",
|
||||
"langSlug": "typescript",
|
||||
"code": "function chunk(arr: any[], size: number): any[][] {\n\n};\n",
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"1.1K\", \"totalSubmission\": \"1.3K\", \"totalAcceptedRaw\": 1096, \"totalSubmissionRaw\": 1329, \"acRate\": \"82.5%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "[1,2,3,4,5]\n1",
|
||||
"metaData": "{\n \"name\": \"chunkify\",\n \"params\": [\n {\n \"name\": \"arr\",\n \"type\": \"string\"\n },\n {\n \"type\": \"integer\",\n \"name\": \"size\"\n }\n ],\n \"return\": {\n \"type\": \"integer\"\n },\n \"languages\": [\n \"javascript\",\n \"typescript\"\n ],\n \"manual\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [],
|
||||
"enableRunCode": true,
|
||||
"enableTestMode": false,
|
||||
"enableDebugger": false,
|
||||
"envInfo": "{\"javascript\": [\"JavaScript\", \"<p><code>Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES6 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\\r\\n\\r\\n<p>For Priority Queue / Queue data structures, you may use 5.3.0 version of <a href=\\\"https://github.com/datastructures-js/priority-queue/tree/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\">datastructures-js/priority-queue</a> and 4.2.1 version of <a href=\\\"https://github.com/datastructures-js/queue/tree/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\">datastructures-js/queue</a>.</p>\"], \"typescript\": [\"Typescript\", \"<p><code>TypeScript 4.5.4, Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES2020 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\"]}",
|
||||
"libraryUrl": null,
|
||||
"adminUrl": null,
|
||||
"challengeQuestion": null,
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
162
leetcode/originData/count-the-number-of-complete-components.json
Normal file
162
leetcode/originData/count-the-number-of-complete-components.json
Normal file
File diff suppressed because one or more lines are too long
66
leetcode/originData/counter-ii.json
Normal file
66
leetcode/originData/counter-ii.json
Normal file
@ -0,0 +1,66 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2789",
|
||||
"questionFrontendId": "2665",
|
||||
"boundTopicId": null,
|
||||
"title": "Counter II",
|
||||
"titleSlug": "counter-ii",
|
||||
"content": "<p>Write a function <code>createCounter</code>. It should accept an initial integer <code>init</code>. It should return an object with three functions.</p>\n\n<p>The three functions are:</p>\n\n<ul>\n\t<li><code>increment()</code> increases the current value by 1 and then returns it.</li>\n\t<li><code>decrement()</code> reduces the current value by 1 and then returns it.</li>\n\t<li><code>reset()</code> sets the current value to <code>init</code> and then returns it.</li>\n</ul>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> init = 5, calls = ["increment","reset","decrement"]\n<strong>Output:</strong> [6,5,4]\n<strong>Explanation:</strong>\nconst counter = createCounter(5);\ncounter.increment(); // 6\ncounter.reset(); // 5\ncounter.decrement(); // 4\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> init = 0, calls = ["increment","increment","decrement","reset","reset"]\n<strong>Output:</strong> [1,2,1,0,0]\n<strong>Explanation:</strong>\nconst counter = createCounter(0);\ncounter.increment(); // 1\ncounter.increment(); // 2\ncounter.decrement(); // 1\ncounter.reset(); // 0\ncounter.reset(); // 0\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>-1000 <= init <= 1000</code></li>\n\t<li><code>total calls not to exceed 1000</code></li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Easy",
|
||||
"likes": 270,
|
||||
"dislikes": 4,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[{\"title\": \"Counter\", \"titleSlug\": \"counter\", \"difficulty\": \"Easy\", \"translatedTitle\": null}]",
|
||||
"exampleTestcases": "5\n[\"increment\",\"reset\",\"decrement\"]\n0\n[\"increment\",\"increment\",\"decrement\",\"reset\",\"reset\"]",
|
||||
"categoryTitle": "JavaScript",
|
||||
"contributors": [],
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": [
|
||||
{
|
||||
"lang": "JavaScript",
|
||||
"langSlug": "javascript",
|
||||
"code": "/**\n * @param {integer} init\n * @return { increment: Function, decrement: Function, reset: Function }\n */\nvar createCounter = function(init) {\n \n};\n\n/**\n * const counter = createCounter(5)\n * counter.increment(); // 6\n * counter.reset(); // 5\n * counter.decrement(); // 4\n */",
|
||||
"__typename": "CodeSnippetNode"
|
||||
},
|
||||
{
|
||||
"lang": "TypeScript",
|
||||
"langSlug": "typescript",
|
||||
"code": "type ReturnObj = {\n increment: () => number,\n decrement: () => number,\n reset: () => number,\n}\n\nfunction createCounter(init: number): ReturnObj {\n\n};\n\n/**\n * const counter = createCounter(5)\n * counter.increment(); // 6\n * counter.reset(); // 5\n * counter.decrement(); // 4\n */",
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"18K\", \"totalSubmission\": \"20K\", \"totalAcceptedRaw\": 17957, \"totalSubmissionRaw\": 20004, \"acRate\": \"89.8%\"}",
|
||||
"hints": [
|
||||
"You can return an object with methods.",
|
||||
"Initialize a variable for currentCount. Inside these methods, add the appropriate logic which mutates currentCount."
|
||||
],
|
||||
"solution": {
|
||||
"id": "1881",
|
||||
"canSeeDetail": true,
|
||||
"paidOnly": false,
|
||||
"hasVideoSolution": false,
|
||||
"paidOnlyVideo": true,
|
||||
"__typename": "ArticleNode"
|
||||
},
|
||||
"status": null,
|
||||
"sampleTestCase": "5\n[\"increment\",\"reset\",\"decrement\"]",
|
||||
"metaData": "{\n \"name\": \"createCounter\",\n \"params\": [\n {\n \"name\": \"init\",\n \"type\": \"integer\"\n },\n {\n \"type\": \"string[]\",\n \"name\": \"calls\"\n }\n ],\n \"return\": {\n \"type\": \"integer\"\n },\n \"languages\": [\n \"javascript\",\n \"typescript\"\n ],\n \"manual\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [],
|
||||
"enableRunCode": true,
|
||||
"enableTestMode": false,
|
||||
"enableDebugger": false,
|
||||
"envInfo": "{\"javascript\": [\"JavaScript\", \"<p><code>Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES6 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\\r\\n\\r\\n<p>For Priority Queue / Queue data structures, you may use 5.3.0 version of <a href=\\\"https://github.com/datastructures-js/priority-queue/tree/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\">datastructures-js/priority-queue</a> and 4.2.1 version of <a href=\\\"https://github.com/datastructures-js/queue/tree/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\">datastructures-js/queue</a>.</p>\"], \"typescript\": [\"Typescript\", \"<p><code>TypeScript 4.5.4, Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES2020 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\"]}",
|
||||
"libraryUrl": null,
|
||||
"adminUrl": null,
|
||||
"challengeQuestion": null,
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
63
leetcode/originData/create-hello-world-function.json
Normal file
63
leetcode/originData/create-hello-world-function.json
Normal file
@ -0,0 +1,63 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2809",
|
||||
"questionFrontendId": "2667",
|
||||
"boundTopicId": null,
|
||||
"title": "Create Hello World Function",
|
||||
"titleSlug": "create-hello-world-function",
|
||||
"content": "Write a function <code>createHelloWorld</code>. It should return a new function that always returns <code>"Hello World"</code>.\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> args = []\n<strong>Output:</strong> "Hello World"\n<strong>Explanation:</strong>\nconst f = createHelloWorld();\nf(); // "Hello World"\n\nThe function returned by createHelloWorld should always return "Hello World".\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> args = [{},null,42]\n<strong>Output:</strong> "Hello World"\n<strong>Explanation:</strong>\nconst f = createHelloWorld();\nf({}, null, 42); // "Hello World"\n\nAny arguments could be passed to the function but it should still always return "Hello World".\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>0 <= args.length <= 10</code></li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Easy",
|
||||
"likes": 380,
|
||||
"dislikes": 39,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"exampleTestcases": "[]\n[{},null,42]",
|
||||
"categoryTitle": "JavaScript",
|
||||
"contributors": [],
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": [
|
||||
{
|
||||
"lang": "JavaScript",
|
||||
"langSlug": "javascript",
|
||||
"code": "/**\n * @return {Function}\n */\nvar createHelloWorld = function() {\n return function(...args) {\n \n }\n};\n\n/**\n * const f = createHelloWorld();\n * f(); // \"Hello World\"\n */",
|
||||
"__typename": "CodeSnippetNode"
|
||||
},
|
||||
{
|
||||
"lang": "TypeScript",
|
||||
"langSlug": "typescript",
|
||||
"code": "function createHelloWorld() {\n\treturn function(...args): string {\n \n };\n};\n\n/**\n * const f = createHelloWorld();\n * f(); // \"Hello World\"\n */",
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"26K\", \"totalSubmission\": \"28K\", \"totalAcceptedRaw\": 25993, \"totalSubmissionRaw\": 28010, \"acRate\": \"92.8%\"}",
|
||||
"hints": [],
|
||||
"solution": {
|
||||
"id": "1873",
|
||||
"canSeeDetail": true,
|
||||
"paidOnly": false,
|
||||
"hasVideoSolution": false,
|
||||
"paidOnlyVideo": true,
|
||||
"__typename": "ArticleNode"
|
||||
},
|
||||
"status": null,
|
||||
"sampleTestCase": "[]",
|
||||
"metaData": "{\n \"name\": \"createHelloWorld\",\n \"params\": [\n {\n \"name\": \"args\",\n \"type\": \"string\"\n }\n ],\n \"return\": {\n \"type\": \"string\"\n },\n \"languages\": [\n \"javascript\",\n \"typescript\"\n ],\n \"manual\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [],
|
||||
"enableRunCode": true,
|
||||
"enableTestMode": false,
|
||||
"enableDebugger": false,
|
||||
"envInfo": "{\"javascript\": [\"JavaScript\", \"<p><code>Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES6 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\\r\\n\\r\\n<p>For Priority Queue / Queue data structures, you may use 5.3.0 version of <a href=\\\"https://github.com/datastructures-js/priority-queue/tree/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\">datastructures-js/priority-queue</a> and 4.2.1 version of <a href=\\\"https://github.com/datastructures-js/queue/tree/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\">datastructures-js/queue</a>.</p>\"], \"typescript\": [\"Typescript\", \"<p><code>TypeScript 4.5.4, Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES2020 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\"]}",
|
||||
"libraryUrl": null,
|
||||
"adminUrl": null,
|
||||
"challengeQuestion": null,
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
174
leetcode/originData/find-the-distinct-difference-array.json
Normal file
174
leetcode/originData/find-the-distinct-difference-array.json
Normal file
File diff suppressed because one or more lines are too long
160
leetcode/originData/find-the-losers-of-the-circular-game.json
Normal file
160
leetcode/originData/find-the-losers-of-the-circular-game.json
Normal file
File diff suppressed because one or more lines are too long
175
leetcode/originData/frequency-tracker.json
Normal file
175
leetcode/originData/frequency-tracker.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
161
leetcode/originData/maximum-number-of-moves-in-a-grid.json
Normal file
161
leetcode/originData/maximum-number-of-moves-in-a-grid.json
Normal file
File diff suppressed because one or more lines are too long
161
leetcode/originData/maximum-or.json
Normal file
161
leetcode/originData/maximum-or.json
Normal file
File diff suppressed because one or more lines are too long
161
leetcode/originData/neighboring-bitwise-xor.json
Normal file
161
leetcode/originData/neighboring-bitwise-xor.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user