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
e5097bc0f6
commit
25bf8d9df8
@ -1,6 +1,6 @@
|
|||||||
# 力扣题库(完整版)
|
# 力扣题库(完整版)
|
||||||
|
|
||||||
> 最后更新日期: **2023.06.22**
|
> 最后更新日期: **2023.07.03**
|
||||||
>
|
>
|
||||||
> 使用脚本前请务必仔细完整阅读本 `README.md` 文件
|
> 使用脚本前请务必仔细完整阅读本 `README.md` 文件
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,50 @@
|
|||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"question": {
|
||||||
|
"questionId": "2770",
|
||||||
|
"questionFrontendId": "2754",
|
||||||
|
"categoryTitle": "JavaScript",
|
||||||
|
"boundTopicId": 2323990,
|
||||||
|
"title": "Bind Function to Context",
|
||||||
|
"titleSlug": "bind-function-to-context",
|
||||||
|
"content": null,
|
||||||
|
"translatedTitle": "将函数绑定到上下文",
|
||||||
|
"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\": \"20\", \"totalAcceptedRaw\": 18, \"totalSubmissionRaw\": 20, \"acRate\": \"90.0%\"}",
|
||||||
|
"hints": [
|
||||||
|
"The easiest way to solve this is to use the built-in fn.apply() method.",
|
||||||
|
"Without built-in methods, you need to figure out a way to call the function (this) from context object. That will associate \"this\" appropriately.",
|
||||||
|
"You can create a new Symbol(). Attach the symbol to the context object and set the method to be \"this\". Then call the method on the symbol."
|
||||||
|
],
|
||||||
|
"solution": null,
|
||||||
|
"status": null,
|
||||||
|
"sampleTestCase": "function f(multiplier) { return this.x * multiplier; }\n{\"x\":10}\n[5]",
|
||||||
|
"metaData": "{\n \"name\": \"jsonParse\",\n \"params\": [\n {\n \"name\": \"fn\",\n \"type\": \"string\"\n },\n {\n \"type\": \"string\",\n \"name\": \"obj\"\n },\n {\n \"type\": \"string\",\n \"name\": \"inputs\"\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": "function f(multiplier) { return this.x * multiplier; }\n{\"x\":10}\n[5]\nfunction speak() { return \"My name is \" + this.name; }\n{\"name\":\"Kathy\"}\n[]",
|
||||||
|
"__typename": "QuestionNode"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"question": {
|
||||||
|
"questionId": "2851",
|
||||||
|
"questionFrontendId": "2759",
|
||||||
|
"categoryTitle": "JavaScript",
|
||||||
|
"boundTopicId": 2323991,
|
||||||
|
"title": "Convert JSON String to Object",
|
||||||
|
"titleSlug": "convert-json-string-to-object",
|
||||||
|
"content": null,
|
||||||
|
"translatedTitle": "将 JSON 字符串转换为对象",
|
||||||
|
"translatedContent": null,
|
||||||
|
"isPaidOnly": true,
|
||||||
|
"difficulty": "Hard",
|
||||||
|
"likes": 0,
|
||||||
|
"dislikes": 0,
|
||||||
|
"isLiked": null,
|
||||||
|
"similarQuestions": "[]",
|
||||||
|
"contributors": [],
|
||||||
|
"langToValidPlayground": null,
|
||||||
|
"topicTags": [],
|
||||||
|
"companyTagStats": null,
|
||||||
|
"codeSnippets": null,
|
||||||
|
"stats": "{\"totalAccepted\": \"2\", \"totalSubmission\": \"3\", \"totalAcceptedRaw\": 2, \"totalSubmissionRaw\": 3, \"acRate\": \"66.7%\"}",
|
||||||
|
"hints": [],
|
||||||
|
"solution": null,
|
||||||
|
"status": null,
|
||||||
|
"sampleTestCase": "'{\"a\":2,\"b\":[1,2,3]}'",
|
||||||
|
"metaData": "{\n \"name\": \"jsonParse\",\n \"params\": [\n {\n \"name\": \"str\",\n \"type\": \"string\"\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\":2,\"b\":[1,2,3]}'\n'true'\n'[1,5,\"false\",{\"a\":2}]'",
|
||||||
|
"__typename": "QuestionNode"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,58 @@
|
|||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"question": {
|
||||||
|
"questionId": "2852",
|
||||||
|
"questionFrontendId": "2752",
|
||||||
|
"categoryTitle": "Database",
|
||||||
|
"boundTopicId": 2322212,
|
||||||
|
"title": "Customers with Maximum Number of Transactions on Consecutive Days",
|
||||||
|
"titleSlug": "customers-with-maximum-number-of-transactions-on-consecutive-days",
|
||||||
|
"content": null,
|
||||||
|
"translatedTitle": "在连续天数上进行了最多交易次数的顾客",
|
||||||
|
"translatedContent": null,
|
||||||
|
"isPaidOnly": true,
|
||||||
|
"difficulty": "Hard",
|
||||||
|
"likes": 0,
|
||||||
|
"dislikes": 0,
|
||||||
|
"isLiked": null,
|
||||||
|
"similarQuestions": "[]",
|
||||||
|
"contributors": [],
|
||||||
|
"langToValidPlayground": null,
|
||||||
|
"topicTags": [],
|
||||||
|
"companyTagStats": null,
|
||||||
|
"codeSnippets": null,
|
||||||
|
"stats": "{\"totalAccepted\": \"17\", \"totalSubmission\": \"30\", \"totalAcceptedRaw\": 17, \"totalSubmissionRaw\": 30, \"acRate\": \"56.7%\"}",
|
||||||
|
"hints": [],
|
||||||
|
"solution": null,
|
||||||
|
"status": null,
|
||||||
|
"sampleTestCase": "{\"headers\":{\"Transactions\":[\"transaction_id\",\"customer_id\",\"transaction_date\",\"amount\"]},\"rows\":{\"Transactions\":[[1,101,\"2023-05-01\",100],[2,101,\"2023-05-02\",150],[3,101,\"2023-05-03\",200],[4,102,\"2023-05-01\",50],[5,102,\"2023-05-03\",100],[6,102,\"2023-05-04\",200],[7,105,\"2023-05-01\",100],[8,105,\"2023-05-02\",150],[9,105,\"2023-05-03\",200]]}}",
|
||||||
|
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Transactions (transaction_id int, customer_id int, transaction_date date, amount int)\"\n ],\n \"mssql\": [\n \"Create table Transactions (transaction_id int, customer_id int, transaction_date date, amount int)\"\n ],\n \"oraclesql\": [\n \"Create table Transactions (transaction_id int, customer_id int, transaction_date date, amount int)\",\n \"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"\n ],\n \"database\": true,\n \"languages\": [\n \"mysql\",\n \"mssql\",\n \"oraclesql\"\n ]\n}",
|
||||||
|
"judgerAvailable": true,
|
||||||
|
"judgeType": "large",
|
||||||
|
"mysqlSchemas": [
|
||||||
|
"Create table If Not Exists Transactions (transaction_id int, customer_id int, transaction_date date, amount int)",
|
||||||
|
"Truncate table Transactions",
|
||||||
|
"insert into Transactions (transaction_id, customer_id, transaction_date, amount) values ('1', '101', '2023-05-01', '100')",
|
||||||
|
"insert into Transactions (transaction_id, customer_id, transaction_date, amount) values ('2', '101', '2023-05-02', '150')",
|
||||||
|
"insert into Transactions (transaction_id, customer_id, transaction_date, amount) values ('3', '101', '2023-05-03', '200')",
|
||||||
|
"insert into Transactions (transaction_id, customer_id, transaction_date, amount) values ('4', '102', '2023-05-01', '50')",
|
||||||
|
"insert into Transactions (transaction_id, customer_id, transaction_date, amount) values ('5', '102', '2023-05-03', '100')",
|
||||||
|
"insert into Transactions (transaction_id, customer_id, transaction_date, amount) values ('6', '102', '2023-05-04', '200')",
|
||||||
|
"insert into Transactions (transaction_id, customer_id, transaction_date, amount) values ('7', '105', '2023-05-01', '100')",
|
||||||
|
"insert into Transactions (transaction_id, customer_id, transaction_date, amount) values ('8', '105', '2023-05-02', '150')",
|
||||||
|
"insert into Transactions (transaction_id, customer_id, transaction_date, amount) values ('9', '105', '2023-05-03', '200')"
|
||||||
|
],
|
||||||
|
"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\":{\"Transactions\":[\"transaction_id\",\"customer_id\",\"transaction_date\",\"amount\"]},\"rows\":{\"Transactions\":[[1,101,\"2023-05-01\",100],[2,101,\"2023-05-02\",150],[3,101,\"2023-05-03\",200],[4,102,\"2023-05-01\",50],[5,102,\"2023-05-03\",100],[6,102,\"2023-05-04\",200],[7,105,\"2023-05-01\",100],[8,105,\"2023-05-02\",150],[9,105,\"2023-05-03\",200]]}}",
|
||||||
|
"__typename": "QuestionNode"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"question": {
|
||||||
|
"questionId": "2795",
|
||||||
|
"questionFrontendId": "2755",
|
||||||
|
"categoryTitle": "JavaScript",
|
||||||
|
"boundTopicId": 2323992,
|
||||||
|
"title": "Deep Merge of Two Objects",
|
||||||
|
"titleSlug": "deep-merge-of-two-objects",
|
||||||
|
"content": null,
|
||||||
|
"translatedTitle": "深度合并两个对象",
|
||||||
|
"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\": \"30\", \"totalAcceptedRaw\": 18, \"totalSubmissionRaw\": 30, \"acRate\": \"60.0%\"}",
|
||||||
|
"hints": [],
|
||||||
|
"solution": null,
|
||||||
|
"status": null,
|
||||||
|
"sampleTestCase": "{\"a\": 1, \"c\": 3}\n{\"a\": 2, \"b\": 2}",
|
||||||
|
"metaData": "{\n \"name\": \"deepMerge\",\n \"params\": [\n {\n \"name\": \"obj1\",\n \"type\": \"string\"\n },\n {\n \"type\": \"string\",\n \"name\": \"obj2\"\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": "{\"a\": 1, \"c\": 3}\n{\"a\": 2, \"b\": 2}\n[{}, 2, 3]\n[[], 5]\n{\"a\": 1, \"b\": {\"c\": [1,[2,7],5], \"d\": 2}}\n{\"a\": 1, \"b\": {\"c\": [6,[6],[9]], \"e\": 3}}\ntrue\nnull",
|
||||||
|
"__typename": "QuestionNode"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"question": {
|
||||||
|
"questionId": "2814",
|
||||||
|
"questionFrontendId": "2757",
|
||||||
|
"categoryTitle": "JavaScript",
|
||||||
|
"boundTopicId": 2323988,
|
||||||
|
"title": "Generate Circular Array Values",
|
||||||
|
"titleSlug": "generate-circular-array-values",
|
||||||
|
"content": null,
|
||||||
|
"translatedTitle": "生成循环数组的值",
|
||||||
|
"translatedContent": null,
|
||||||
|
"isPaidOnly": true,
|
||||||
|
"difficulty": "Medium",
|
||||||
|
"likes": 0,
|
||||||
|
"dislikes": 0,
|
||||||
|
"isLiked": null,
|
||||||
|
"similarQuestions": "[]",
|
||||||
|
"contributors": [],
|
||||||
|
"langToValidPlayground": null,
|
||||||
|
"topicTags": [],
|
||||||
|
"companyTagStats": null,
|
||||||
|
"codeSnippets": null,
|
||||||
|
"stats": "{\"totalAccepted\": \"9\", \"totalSubmission\": \"13\", \"totalAcceptedRaw\": 9, \"totalSubmissionRaw\": 13, \"acRate\": \"69.2%\"}",
|
||||||
|
"hints": [],
|
||||||
|
"solution": null,
|
||||||
|
"status": null,
|
||||||
|
"sampleTestCase": "[1,2,3,4,5]\n[1,2,6]\n0",
|
||||||
|
"metaData": "{\n \"name\": \"cycleGenerator\",\n \"params\": [\n {\n \"name\": \"arr\",\n \"type\": \"integer[]\"\n },\n {\n \"type\": \"integer[]\",\n \"name\": \"steps\"\n },\n {\n \"type\": \"integer\",\n \"name\": \"startIndex\"\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]\n[1,2,6]\n0\n[10,11,12,13,14,15]\n[1,4,0,-1,-3]\n1\n[2,4,6,7,8,10]\n[-4,5,-3,10]\n3",
|
||||||
|
"__typename": "QuestionNode"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
46
leetcode-cn/originData/[no content]next-day.json
Normal file
46
leetcode-cn/originData/[no content]next-day.json
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"question": {
|
||||||
|
"questionId": "2822",
|
||||||
|
"questionFrontendId": "2758",
|
||||||
|
"categoryTitle": "JavaScript",
|
||||||
|
"boundTopicId": 2323987,
|
||||||
|
"title": "Next Day",
|
||||||
|
"titleSlug": "next-day",
|
||||||
|
"content": null,
|
||||||
|
"translatedTitle": "下一天",
|
||||||
|
"translatedContent": null,
|
||||||
|
"isPaidOnly": true,
|
||||||
|
"difficulty": "Easy",
|
||||||
|
"likes": 0,
|
||||||
|
"dislikes": 0,
|
||||||
|
"isLiked": null,
|
||||||
|
"similarQuestions": "[]",
|
||||||
|
"contributors": [],
|
||||||
|
"langToValidPlayground": null,
|
||||||
|
"topicTags": [],
|
||||||
|
"companyTagStats": null,
|
||||||
|
"codeSnippets": null,
|
||||||
|
"stats": "{\"totalAccepted\": \"19\", \"totalSubmission\": \"23\", \"totalAcceptedRaw\": 19, \"totalSubmissionRaw\": 23, \"acRate\": \"82.6%\"}",
|
||||||
|
"hints": [],
|
||||||
|
"solution": null,
|
||||||
|
"status": null,
|
||||||
|
"sampleTestCase": "\"2014-06-20\"",
|
||||||
|
"metaData": "{\n \"name\": \"foobar\",\n \"params\": [\n {\n \"type\": \"string\",\n \"name\": \"date\"\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": "\"2014-06-20\"\n\"2017-10-31\"",
|
||||||
|
"__typename": "QuestionNode"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
46
leetcode-cn/originData/[no content]query-batching.json
Normal file
46
leetcode-cn/originData/[no content]query-batching.json
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"question": {
|
||||||
|
"questionId": "2806",
|
||||||
|
"questionFrontendId": "2756",
|
||||||
|
"categoryTitle": "JavaScript",
|
||||||
|
"boundTopicId": 2323989,
|
||||||
|
"title": "Query Batching",
|
||||||
|
"titleSlug": "query-batching",
|
||||||
|
"content": null,
|
||||||
|
"translatedTitle": "批处理查询",
|
||||||
|
"translatedContent": null,
|
||||||
|
"isPaidOnly": true,
|
||||||
|
"difficulty": "Hard",
|
||||||
|
"likes": 0,
|
||||||
|
"dislikes": 0,
|
||||||
|
"isLiked": null,
|
||||||
|
"similarQuestions": "[]",
|
||||||
|
"contributors": [],
|
||||||
|
"langToValidPlayground": null,
|
||||||
|
"topicTags": [],
|
||||||
|
"companyTagStats": null,
|
||||||
|
"codeSnippets": null,
|
||||||
|
"stats": "{\"totalAccepted\": \"6\", \"totalSubmission\": \"10\", \"totalAcceptedRaw\": 6, \"totalSubmissionRaw\": 10, \"acRate\": \"60.0%\"}",
|
||||||
|
"hints": [],
|
||||||
|
"solution": null,
|
||||||
|
"status": null,
|
||||||
|
"sampleTestCase": "async function(keys) { return keys.map(key => key + '!'); }\n100\n[{\"key\": \"a\", \"time\": 10}, {\"key\": \"b\", \"time\": 20}, {\"key\": \"c\", \"time\": 30}]",
|
||||||
|
"metaData": "{\n \"name\": \"QueryBatcher\",\n \"params\": [\n {\n \"name\": \"queryMultiple\",\n \"type\": \"string\"\n },\n {\n \"type\": \"integer\",\n \"name\": \"t\"\n },\n {\n \"type\": \"string\",\n \"name\": \"calls\"\n }\n ],\n \"return\": {\n \"type\": \"integer\"\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": "async function(keys) { return keys.map(key => key + '!'); }\n100\n[{\"key\": \"a\", \"time\": 10}, {\"key\": \"b\", \"time\": 20}, {\"key\": \"c\", \"time\": 30}]\nasync function(keys) { await new Promise(res => setTimeout(res, 100)); return keys.map(key => key + '!'); }\n100\n[{\"key\": \"a\", \"time\": 10}, {\"key\": \"b\", \"time\": 20}, {\"key\": \"c\", \"time\": 30}]\nasync function(keys) { await new Promise(res => setTimeout(res, keys.length * 100)); return keys.map(key => key + '!'); }\n100\n[{\"key\": \"a\", \"time\": 10}, {\"key\": \"b\", \"time\": 20}, {\"key\": \"c\", \"time\": 30}, {\"key\": \"d\", \"time\": 40}, {\"key\": \"e\", \"time\": 250}, {\"key\": \"f\", \"time\": 300}]",
|
||||||
|
"__typename": "QuestionNode"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
184
leetcode-cn/originData/construct-the-longest-new-string.json
Normal file
184
leetcode-cn/originData/construct-the-longest-new-string.json
Normal file
File diff suppressed because one or more lines are too long
164
leetcode-cn/originData/continuous-subarrays.json
Normal file
164
leetcode-cn/originData/continuous-subarrays.json
Normal file
File diff suppressed because one or more lines are too long
190
leetcode-cn/originData/count-zero-request-servers.json
Normal file
190
leetcode-cn/originData/count-zero-request-servers.json
Normal file
File diff suppressed because one or more lines are too long
178
leetcode-cn/originData/decremental-string-concatenation.json
Normal file
178
leetcode-cn/originData/decremental-string-concatenation.json
Normal file
File diff suppressed because one or more lines are too long
189
leetcode-cn/originData/find-maximum-number-of-string-pairs.json
Normal file
189
leetcode-cn/originData/find-maximum-number-of-string-pairs.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
File diff suppressed because one or more lines are too long
183
leetcode-cn/originData/number-of-beautiful-pairs.json
Normal file
183
leetcode-cn/originData/number-of-beautiful-pairs.json
Normal file
File diff suppressed because one or more lines are too long
164
leetcode-cn/originData/prime-pairs-with-target-sum.json
Normal file
164
leetcode-cn/originData/prime-pairs-with-target-sum.json
Normal file
File diff suppressed because one or more lines are too long
190
leetcode-cn/originData/robot-collisions.json
Normal file
190
leetcode-cn/originData/robot-collisions.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
File diff suppressed because one or more lines are too long
@ -0,0 +1,46 @@
|
|||||||
|
<p>给你一个下标从 <strong>0</strong> 开始的整数数组 <code>nums</code> 。<code>nums</code> 的一个子数组如果满足以下条件,那么它是 <strong>不间断</strong> 的:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>i</code>,<code>i + 1</code> ,...,<code>j</code><sub> </sub> 表示子数组中的下标。对于所有满足 <code>i <= i<sub>1</sub>, i<sub>2</sub> <= j</code> 的下标对,都有 <code>0 <= |nums[i<sub>1</sub>] - nums[i<sub>2</sub>]| <= 2</code> 。</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>请你返回 <strong>不间断</strong> 子数组的总数目。</p>
|
||||||
|
|
||||||
|
<p>子数组是一个数组中一段连续 <strong>非空</strong> 的元素序列。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<b>输入:</b>nums = [5,4,2,4]
|
||||||
|
<strong>输出:</strong>8
|
||||||
|
<b>解释:</b>
|
||||||
|
大小为 1 的不间断子数组:[5], [4], [2], [4] 。
|
||||||
|
大小为 2 的不间断子数组:[5,4], [4,2], [2,4] 。
|
||||||
|
大小为 3 的不间断子数组:[4,2,4] 。
|
||||||
|
没有大小为 4 的不间断子数组。
|
||||||
|
不间断子数组的总数目为 4 + 3 + 1 = 8 。
|
||||||
|
除了这些以外,没有别的不间断子数组。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<b>输入:</b>nums = [1,2,3]
|
||||||
|
<b>输出:</b>6
|
||||||
|
<b>解释:</b>
|
||||||
|
大小为 1 的不间断子数组:[1], [2], [3] 。
|
||||||
|
大小为 2 的不间断子数组:[1,2], [2,3] 。
|
||||||
|
大小为 3 的不间断子数组:[1,2,3] 。
|
||||||
|
不间断子数组的总数目为 3 + 2 + 1 = 6 。
|
||||||
|
</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>
|
@ -0,0 +1,36 @@
|
|||||||
|
<p>给你一个整数 <code>n</code> 。如果两个整数 <code>x</code> 和 <code>y</code> 满足下述条件,则认为二者形成一个质数对:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= x <= y <= n</code></li>
|
||||||
|
<li><code>x + y == n</code></li>
|
||||||
|
<li><code>x</code> 和 <code>y</code> 都是质数</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>请你以二维有序列表的形式返回符合题目要求的所有 <code>[x<sub>i</sub>, y<sub>i</sub>]</code> ,列表需要按 <code>x<sub>i</sub></code> 的 <strong>非递减顺序</strong> 排序。如果不存在符合要求的质数对,则返回一个空数组。</p>
|
||||||
|
|
||||||
|
<p><strong>注意:</strong>质数是大于 <code>1</code> 的自然数,并且只有两个因子,即它本身和 <code>1</code> 。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre><strong>输入:</strong>n = 10
|
||||||
|
<strong>输出:</strong>[[3,7],[5,5]]
|
||||||
|
<strong>解释:</strong>在这个例子中,存在满足条件的两个质数对。
|
||||||
|
这两个质数对分别是 [3,7] 和 [5,5],按照题面描述中的方式排序后返回。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre><strong>输入:</strong>n = 2
|
||||||
|
<strong>输出:</strong>[]
|
||||||
|
<strong>解释:</strong>可以证明不存在和为 2 的质数对,所以返回一个空数组。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= n <= 10<sup>6</sup></code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,61 @@
|
|||||||
|
<p>给你一个下标从 <strong>0</strong> 开始的数组 <code>words</code> ,它包含 <code>n</code> 个字符串。</p>
|
||||||
|
|
||||||
|
<p>定义 <strong>连接</strong> 操作 <code>join(x, y)</code> 表示将字符串 <code>x</code> 和 <code>y</code> 连在一起,得到 <code>xy</code> 。如果 <code>x</code> 的最后一个字符与 <code>y</code> 的第一个字符相等,连接后两个字符中的一个会被 <strong>删除</strong> 。</p>
|
||||||
|
|
||||||
|
<p>比方说 <code>join("ab", "ba") = "aba"</code> , <code>join("ab", "cde") = "abcde"</code> 。</p>
|
||||||
|
|
||||||
|
<p>你需要执行 <code>n - 1</code> 次 <strong>连接</strong> 操作。令 <code>str<sub>0</sub> = words[0]</code> ,从 <code>i = 1</code> 直到 <code>i = n - 1</code> ,对于第 <code>i</code> 个操作,你可以执行以下操作之一:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>令 <code>str<sub>i</sub> = join(str<sub>i - 1</sub>, words[i])</code></li>
|
||||||
|
<li>令 <code>str<sub>i</sub> = join(words[i], str<sub>i - 1</sub>)</code></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>你的任务是使 <code>str<sub>n - 1</sub></code> 的长度<strong> 最小 </strong>。</p>
|
||||||
|
|
||||||
|
<p>请你返回一个整数,表示 <code>str<sub>n - 1</sub></code> 的最小长度。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<b>输入:</b>words = ["aa","ab","bc"]
|
||||||
|
<b>输出:</b>4
|
||||||
|
<strong>解释:</strong>这个例子中,我们按以下顺序执行连接操作,得到 <code>str<sub>2</sub></code> 的最小长度:
|
||||||
|
<code>str<sub>0</sub> = "aa"</code>
|
||||||
|
<code>str<sub>1</sub> = join(str<sub>0</sub>, "ab") = "aab"
|
||||||
|
</code><code>str<sub>2</sub> = join(str<sub>1</sub>, "bc") = "aabc"</code>
|
||||||
|
<code>str<sub>2</sub></code> 的最小长度为 4 。</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<b>输入:</b>words = ["ab","b"]
|
||||||
|
<b>输出:</b>2
|
||||||
|
<b>解释:</b>这个例子中,str<sub>0</sub> = "ab",可以得到两个不同的 str<sub>1</sub>:
|
||||||
|
join(str<sub>0</sub>, "b") = "ab" 或者 join("b", str<sub>0</sub>) = "bab" 。
|
||||||
|
第一个字符串 "ab" 的长度最短,所以答案为 2 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 3:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<b>输入:</b>words = ["aaa","c","aba"]
|
||||||
|
<b>输出:</b>6
|
||||||
|
<b>解释:</b>这个例子中,我们按以下顺序执行连接操作,得到 <code>str<sub>2</sub> 的最小长度:</code>
|
||||||
|
<code>str<sub>0</sub> = "</code>aaa"
|
||||||
|
<code>str<sub>1</sub> = join(str<sub>0</sub>, "c") = "aaac"</code>
|
||||||
|
<code>str<sub>2</sub> = join("aba", str<sub>1</sub>) = "abaaac"</code>
|
||||||
|
<code>str<sub>2</sub></code> 的最小长度为 6 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= words.length <= 1000</code></li>
|
||||||
|
<li><code>1 <= words[i].length <= 50</code></li>
|
||||||
|
<li><code>words[i]</code> 中只包含小写英文字母。</li>
|
||||||
|
</ul>
|
@ -0,0 +1,36 @@
|
|||||||
|
<p>给你一个二元数组 <code>nums</code> 。</p>
|
||||||
|
|
||||||
|
<p>如果数组中的某个子数组 <strong>恰好</strong> 只存在 <strong>一</strong> 个值为 <code>1</code> 的元素,则认为该子数组是一个 <strong>好子数组</strong> 。</p>
|
||||||
|
|
||||||
|
<p>请你统计将数组 <code>nums</code> 划分成若干 <strong>好子数组</strong> 的方法数,并以整数形式返回。由于数字可能很大,返回其对 <code>10<sup>9</sup> + 7</code> <strong>取余 </strong>之后的结果。</p>
|
||||||
|
|
||||||
|
<p>子数组是数组中的一个连续 <strong>非空</strong> 元素序列。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre><strong>输入:</strong>nums = [0,1,0,0,1]
|
||||||
|
<strong>输出:</strong>3
|
||||||
|
<strong>解释:</strong>存在 3 种可以将 nums 划分成若干好子数组的方式:
|
||||||
|
- [0,1] [0,0,1]
|
||||||
|
- [0,1,0] [0,1]
|
||||||
|
- [0,1,0,0] [1]
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre><strong>输入:</strong>nums = [0,1,0]
|
||||||
|
<strong>输出:</strong>1
|
||||||
|
<strong>解释:</strong>存在 1 种可以将 nums 划分成若干好子数组的方式:
|
||||||
|
- [0,1,0]
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>0 <= nums[i] <= 1</code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,38 @@
|
|||||||
|
<p>给你两个整数:<code>num1</code> 和 <code>num2</code> 。</p>
|
||||||
|
|
||||||
|
<p>在一步操作中,你需要从范围 <code>[0, 60]</code> 中选出一个整数 <code>i</code> ,并从 <code>num1</code> 减去 <code>2<sup>i</sup> + num2</code> 。</p>
|
||||||
|
|
||||||
|
<p>请你计算,要想使 <code>num1</code> 等于 <code>0</code> 需要执行的最少操作数,并以整数形式返回。</p>
|
||||||
|
|
||||||
|
<p>如果无法使 <code>num1</code> 等于 <code>0</code> ,返回 <code>-1</code> 。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>输入:</strong>num1 = 3, num2 = -2
|
||||||
|
<strong>输出:</strong>3
|
||||||
|
<strong>解释:</strong>可以执行下述步骤使 3 等于 0 :
|
||||||
|
- 选择 i = 2 ,并从 3 减去 2<sup>2</sup> + (-2) ,num1 = 3 - (4 + (-2)) = 1 。
|
||||||
|
- 选择 i = 2 ,并从 1 减去 2<sup>2</sup> + (-2) ,num1 = 1 - (4 + (-2)) = -1 。
|
||||||
|
- 选择 i = 0 ,并从 -1 减去 2<sup>0</sup> + (-2) ,num1 = (-1) - (1 + (-2)) = 0 。
|
||||||
|
可以证明 3 是需要执行的最少操作数。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>输入:</strong>num1 = 5, num2 = 7
|
||||||
|
<strong>输出:</strong>-1
|
||||||
|
<strong>解释:</strong>可以证明,执行操作无法使 5 等于 0 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= num1 <= 10<sup>9</sup></code></li>
|
||||||
|
<li><code>-10<sup>9</sup> <= num2 <= 10<sup>9</sup></code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,48 @@
|
|||||||
|
<p>一个长度为 <code>n</code> 下标从 <strong>0</strong> 开始的整数数组 <code>arr</code> 的 <strong>不平衡数字</strong> 定义为,在 <code>sarr = sorted(arr)</code> 数组中,满足以下条件的下标数目:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>0 <= i < n - 1</code> ,和</li>
|
||||||
|
<li><code>sarr[i+1] - sarr[i] > 1</code></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>这里,<code>sorted(arr)</code> 表示将数组 <code>arr</code> 排序后得到的数组。</p>
|
||||||
|
|
||||||
|
<p>给你一个下标从 <strong>0</strong> 开始的整数数组 <code>nums</code> ,请你返回它所有 <strong>子数组</strong> 的 <strong>不平衡数字</strong> 之和。</p>
|
||||||
|
|
||||||
|
<p>子数组指的是一个数组中连续一段 <strong>非空</strong> 的元素序列。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre><strong>输入:</strong>nums = [2,3,1,4]
|
||||||
|
<b>输出:</b>3
|
||||||
|
<b>解释:</b>总共有 3 个子数组有非 0 不平衡数字:
|
||||||
|
- 子数组 [3, 1] ,不平衡数字为 1 。
|
||||||
|
- 子数组 [3, 1, 4] ,不平衡数字为 1 。
|
||||||
|
- 子数组 [1, 4] ,不平衡数字为 1 。
|
||||||
|
其他所有子数组的不平衡数字都是 0 ,所以所有子数组的不平衡数字之和为 3 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre><b>输入:</b>nums = [1,3,3,3,5]
|
||||||
|
<b>输出:</b>8
|
||||||
|
<b>解释:</b>总共有 7 个子数组有非 0 不平衡数字:
|
||||||
|
- 子数组 [1, 3] ,不平衡数字为 1 。
|
||||||
|
- 子数组 [1, 3, 3] ,不平衡数字为 1 。
|
||||||
|
- 子数组 [1, 3, 3, 3] ,不平衡数字为 1 。
|
||||||
|
- 子数组 [1, 3, 3, 3, 5] ,不平衡数字为 2 。
|
||||||
|
- 子数组 [3, 3, 3, 5] ,不平衡数字为 1 。
|
||||||
|
- 子数组 [3, 3, 5] ,不平衡数字为 1 。
|
||||||
|
- 子数组 [3, 5] ,不平衡数字为 1 。
|
||||||
|
其他所有子数组的不平衡数字都是 0 ,所以所有子数组的不平衡数字之和为 8 。</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= nums.length <= 1000</code></li>
|
||||||
|
<li><code>1 <= nums[i] <= nums.length</code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,54 @@
|
|||||||
|
<p>给你一个下标从 <strong>0</strong> 开始的数组 <code>words</code> ,数组中包含 <strong>互不相同</strong> 的字符串。</p>
|
||||||
|
|
||||||
|
<p>如果字符串 <code>words[i]</code> 与字符串 <code>words[j]</code> 满足以下条件,我们称它们可以匹配:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>字符串 <code>words[i]</code> 等于 <code>words[j]</code> 的反转字符串。</li>
|
||||||
|
<li><code>0 <= i < j < words.length</code></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>请你返回数组 <code>words</code> 中的 <strong>最大</strong> 匹配数目。</p>
|
||||||
|
|
||||||
|
<p>注意,每个字符串最多匹配一次。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<b>输入:</b>words = ["cd","ac","dc","ca","zz"]
|
||||||
|
<b>输出:</b>2
|
||||||
|
<strong>解释:</strong>在此示例中,我们可以通过以下方式匹配 2 对字符串:
|
||||||
|
- 我们将第 0 个字符串与第 2 个字符串匹配,因为 word[0] 的反转字符串是 "dc" 并且等于 words[2]。
|
||||||
|
- 我们将第 1 个字符串与第 3 个字符串匹配,因为 word[1] 的反转字符串是 "ca" 并且等于 words[3]。
|
||||||
|
可以证明最多匹配数目是 2 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<b>输入:</b>words = ["ab","ba","cc"]
|
||||||
|
<b>输出:</b>1
|
||||||
|
<b>解释:</b>在此示例中,我们可以通过以下方式匹配 1 对字符串:
|
||||||
|
- 我们将第 0 个字符串与第 1 个字符串匹配,因为 words[1] 的反转字符串 "ab" 与 words[0] 相等。
|
||||||
|
可以证明最多匹配数目是 1 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 3:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<b>输入:</b>words = ["aa","ab"]
|
||||||
|
<b>输出:</b>0
|
||||||
|
<strong>解释:</strong>这个例子中,无法匹配任何字符串。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= words.length <= 50</code></li>
|
||||||
|
<li><code>words[i].length == 2</code></li>
|
||||||
|
<li><code>words</code> 包含的字符串互不相同。</li>
|
||||||
|
<li><code>words[i]</code> 只包含小写英文字母。</li>
|
||||||
|
</ul>
|
@ -0,0 +1,50 @@
|
|||||||
|
<p>给你一个下标从 <strong>0</strong> 开始的整数数组 <code>nums</code> 和一个整数 <code>threshold</code> 。</p>
|
||||||
|
|
||||||
|
<p>请你从 <code>nums</code> 的子数组中找出以下标 <code>l</code> 开头、下标 <code>r</code> 结尾 <code>(0 <= l <= r < nums.length)</code> 且满足以下条件的 <strong>最长子数组</strong> :</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>nums[l] % 2 == 0</code></li>
|
||||||
|
<li>对于范围 <code>[l, r - 1]</code> 内的所有下标 <code>i</code> ,<code>nums[i] % 2 != nums[i + 1] % 2</code></li>
|
||||||
|
<li>对于范围 <code>[l, r]</code> 内的所有下标 <code>i</code> ,<code>nums[i] <= threshold</code></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>以整数形式返回满足题目要求的最长子数组的长度。</p>
|
||||||
|
|
||||||
|
<p><strong>注意:子数组</strong> 是数组中的一个连续非空元素序列。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre><strong>输入:</strong>nums = [3,2,5,4], threshold = 5
|
||||||
|
<strong>输出:</strong>3
|
||||||
|
<strong>解释:</strong>在这个示例中,我们选择从 l = 1 开始、到 r = 3 结束的子数组 => [2,5,4] ,满足上述条件。
|
||||||
|
因此,答案就是这个子数组的长度 3 。可以证明 3 是满足题目要求的最大长度。</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre><strong>输入:</strong>nums = [1,2], threshold = 2
|
||||||
|
<strong>输出:</strong>1
|
||||||
|
<strong>解释:</strong>
|
||||||
|
在这个示例中,我们选择从 l = 1 开始、到 r = 1 结束的子数组 => [2] 。
|
||||||
|
该子数组满足上述全部条件。可以证明 1 是满足题目要求的最大长度。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 3:</strong></p>
|
||||||
|
|
||||||
|
<pre><strong>输入:</strong>nums = [2,3,4,5], threshold = 4
|
||||||
|
<strong>输出:</strong>3
|
||||||
|
<strong>解释:</strong>
|
||||||
|
在这个示例中,我们选择从 l = 0 开始、到 r = 2 结束的子数组 => [2,3,4] 。
|
||||||
|
该子数组满足上述全部条件。
|
||||||
|
因此,答案就是这个子数组的长度 3 。可以证明 3 是满足题目要求的最大长度。</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= nums.length <= 100 </code></li>
|
||||||
|
<li><code>1 <= nums[i] <= 100 </code></li>
|
||||||
|
<li><code>1 <= threshold <= 100</code></li>
|
||||||
|
</ul>
|
55
leetcode-cn/problem (Chinese)/机器人碰撞 [robot-collisions].html
Normal file
55
leetcode-cn/problem (Chinese)/机器人碰撞 [robot-collisions].html
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<p>现有 <code>n</code> 个机器人,编号从 <strong>1</strong> 开始,每个机器人包含在路线上的位置、健康度和移动方向。</p>
|
||||||
|
|
||||||
|
<p>给你下标从 <strong>0</strong> 开始的两个整数数组 <code>positions</code>、<code>healths</code> 和一个字符串 <code>directions</code>(<code>directions[i]</code> 为 <strong>'L'</strong> 表示 <strong>向左</strong> 或 <strong>'R'</strong> 表示 <strong>向右</strong>)。 <code>positions</code> 中的所有整数 <strong>互不相同</strong> 。</p>
|
||||||
|
|
||||||
|
<p>所有机器人以 <strong>相同速度</strong> <strong>同时</strong> 沿给定方向在路线上移动。如果两个机器人移动到相同位置,则会发生 <strong>碰撞</strong> 。</p>
|
||||||
|
|
||||||
|
<p>如果两个机器人发生碰撞,则将 <strong>健康度较低</strong> 的机器人从路线中 <strong>移除</strong> ,并且另一个机器人的健康度 <strong>减少 1</strong> 。幸存下来的机器人将会继续沿着与之前 <strong>相同</strong> 的方向前进。如果两个机器人的健康度相同,则将二者都从路线中移除。</p>
|
||||||
|
|
||||||
|
<p>请你确定全部碰撞后幸存下的所有机器人的 <strong>健康度</strong> ,并按照原来机器人编号的顺序排列。即机器人 1 (如果幸存)的最终健康度,机器人 2 (如果幸存)的最终健康度等。 如果不存在幸存的机器人,则返回空数组。</p>
|
||||||
|
|
||||||
|
<p>在不再发生任何碰撞后,请你以数组形式,返回所有剩余机器人的健康度(按机器人输入中的编号顺序)。</p>
|
||||||
|
|
||||||
|
<p><strong>注意:</strong>位置 <code>positions</code> 可能是乱序的。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<p><img height="169" src="https://assets.leetcode.com/uploads/2023/05/15/image-20230516011718-12.png" width="808" /></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>输入:</strong>positions = [5,4,3,2,1], healths = [2,17,9,15,10], directions = "RRRRR"
|
||||||
|
<strong>输出:</strong>[2,17,9,15,10]
|
||||||
|
<strong>解释:</strong>在本例中不存在碰撞,因为所有机器人向同一方向移动。所以,从第一个机器人开始依序返回健康度,[2, 17, 9, 15, 10] 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<p><img height="176" src="https://assets.leetcode.com/uploads/2023/05/15/image-20230516004433-7.png" width="717" /></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>输入:</strong>positions = [3,5,2,6], healths = [10,10,15,12], directions = "RLRL"
|
||||||
|
<strong>输出:</strong>[14]
|
||||||
|
<strong>解释:</strong>本例中发生 2 次碰撞。首先,机器人 1 和机器人 2 将会碰撞,因为二者健康度相同,二者都将被从路线中移除。接下来,机器人 3 和机器人 4 将会发生碰撞,由于机器人 4 的健康度更小,则它会被移除,而机器人 3 的健康度变为 15 - 1 = 14 。仅剩机器人 3 ,所以返回 [14] 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 3:</strong></p>
|
||||||
|
|
||||||
|
<p><img height="172" src="https://assets.leetcode.com/uploads/2023/05/15/image-20230516005114-9.png" width="732" /></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>输入:</strong>positions = [1,2,5,6], healths = [10,10,11,11], directions = "RLRL"
|
||||||
|
<strong>输出:</strong>[]
|
||||||
|
<strong>解释:</strong>机器人 1 和机器人 2 将会碰撞,因为二者健康度相同,二者都将被从路线中移除。机器人 3 和机器人 4 将会碰撞,因为二者健康度相同,二者都将被从路线中移除。所以返回空数组 [] 。</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= positions.length == healths.length == directions.length == n <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>1 <= positions[i], healths[i] <= 10<sup>9</sup></code></li>
|
||||||
|
<li><code>directions[i] == 'L'</code> 或 <code>directions[i] == 'R'</code></li>
|
||||||
|
<li><code>positions</code> 中的所有值互不相同</li>
|
||||||
|
</ul>
|
@ -0,0 +1,35 @@
|
|||||||
|
<p>给你三个整数 <code>x</code> ,<code>y</code> 和 <code>z</code> 。</p>
|
||||||
|
|
||||||
|
<p>这三个整数表示你有 <code>x</code> 个 <code>"AA"</code> 字符串,<code>y</code> 个 <code>"BB"</code> 字符串,和 <code>z</code> 个 <code>"AB"</code> 字符串。你需要选择这些字符串中的部分字符串(可以全部选择也可以一个都不选择),将它们按顺序连接得到一个新的字符串。新字符串不能包含子字符串 <code>"AAA"</code> 或者 <code>"BBB"</code> 。</p>
|
||||||
|
|
||||||
|
<p>请你返回新字符串的最大可能长度。</p>
|
||||||
|
|
||||||
|
<p><strong>子字符串</strong> 是一个字符串中一段连续 <strong>非空</strong> 的字符序列。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong class="example">示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<b>输入:</b>x = 2, y = 5, z = 1
|
||||||
|
<b>输出:</b>12
|
||||||
|
<strong>解释: </strong>我们可以按顺序连接 "BB" ,"AA" ,"BB" ,"AA" ,"BB" 和 "AB" ,得到新字符串 "BBAABBAABBAB" 。
|
||||||
|
字符串长度为 12 ,无法得到一个更长的符合题目要求的字符串。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<b>输入:</b>x = 3, y = 2, z = 2
|
||||||
|
<b>输出:</b>14
|
||||||
|
<b>解释:</b>我们可以按顺序连接 "AB" ,"AB" ,"AA" ,"BB" ,"AA" ,"BB" 和 "AA" ,得到新字符串 "ABABAABBAABBAA" 。
|
||||||
|
字符串长度为 14 ,无法得到一个更长的符合题目要求的字符串。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= x, y, z <= 50</code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,44 @@
|
|||||||
|
<p>给你一个整数 <code>n</code> ,表示服务器的总数目,再给你一个下标从 <strong>0</strong> 开始的 <strong>二维</strong> 整数数组 <code>logs</code> ,其中 <code>logs[i] = [server_id, time]</code> 表示 id 为 <code>server_id</code> 的服务器在 <code>time</code> 时收到了一个请求。</p>
|
||||||
|
|
||||||
|
<p>同时给你一个整数 <code>x</code> 和一个下标从 <strong>0</strong> 开始的整数数组 <code>queries</code> 。</p>
|
||||||
|
|
||||||
|
<p>请你返回一个长度等于 <code>queries.length</code> 的数组 <code>arr</code> ,其中 <code>arr[i]</code> 表示在时间区间 <code>[queries[i] - x, queries[i]]</code> 内没有收到请求的服务器数目。</p>
|
||||||
|
|
||||||
|
<p>注意时间区间是个闭区间。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<b>输入:</b>n = 3, logs = [[1,3],[2,6],[1,5]], x = 5, queries = [10,11]
|
||||||
|
<b>输出:</b>[1,2]
|
||||||
|
<b>解释:</b>
|
||||||
|
对于 queries[0]:id 为 1 和 2 的服务器在区间 [5, 10] 内收到了请求,所以只有服务器 3 没有收到请求。
|
||||||
|
对于 queries[1]:id 为 2 的服务器在区间 [6,11] 内收到了请求,所以 id 为 1 和 3 的服务器在这个时间段内没有收到请求。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<b>输入:</b>n = 3, logs = [[2,4],[2,1],[1,2],[3,1]], x = 2, queries = [3,4]
|
||||||
|
<b>输出:</b>[0,1]
|
||||||
|
<b>解释:</b>
|
||||||
|
对于 queries[0]:区间 [1, 3] 内所有服务器都收到了请求。
|
||||||
|
对于 queries[1]:只有 id 为 3 的服务器在区间 [2,4] 内没有收到请求。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= n <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>1 <= logs.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>1 <= queries.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>logs[i].length == 2</code></li>
|
||||||
|
<li><code>1 <= logs[i][0] <= n</code></li>
|
||||||
|
<li><code>1 <= logs[i][1] <= 10<sup>6</sup></code></li>
|
||||||
|
<li><code>1 <= x <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>x < queries[i] <= 10<sup>6</sup></code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,41 @@
|
|||||||
|
<p>给你一个下标从 <strong>0</strong> 开始的整数数组 <code>nums</code> 。如果下标对 <code>i</code>、<code>j</code> 满足 <code>0 ≤ i < j < nums.length</code> ,如果 <code>nums[i]</code> 的 <strong>第一个数字</strong> 和 <code>nums[j]</code> 的 <strong>最后一个数字</strong> <strong>互质</strong> ,则认为 <code>nums[i]</code> 和 <code>nums[j]</code> 是一组 <strong>美丽下标对</strong> 。</p>
|
||||||
|
|
||||||
|
<p>返回 <code>nums</code> 中 <strong>美丽下标对</strong> 的总数目。</p>
|
||||||
|
|
||||||
|
<p>对于两个整数 <code>x</code> 和 <code>y</code> ,如果不存在大于 1 的整数可以整除它们,则认为 <code>x</code> 和 <code>y</code> <strong>互质</strong> 。换而言之,如果 <code>gcd(x, y) == 1</code> ,则认为 <code>x</code> 和 <code>y</code> 互质,其中 <code>gcd(x, y)</code> 是 <code>x</code> 和 <code>k</code> <strong>最大公因数</strong> 。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>输入:</strong>nums = [2,5,1,4]
|
||||||
|
<strong>输出:</strong>5
|
||||||
|
<strong>解释:</strong>nums 中共有 5 组美丽下标对:
|
||||||
|
i = 0 和 j = 1 :nums[0] 的第一个数字是 2 ,nums[1] 的最后一个数字是 5 。2 和 5 互质,因此 gcd(2,5) == 1 。
|
||||||
|
i = 0 和 j = 2 :nums[0] 的第一个数字是 2 ,nums[1] 的最后一个数字是 1 。2 和 5 互质,因此 gcd(2,1) == 1 。
|
||||||
|
i = 1 和 j = 2 :nums[0] 的第一个数字是 5 ,nums[1] 的最后一个数字是 1 。2 和 5 互质,因此 gcd(5,1) == 1 。
|
||||||
|
i = 1 和 j = 3 :nums[0] 的第一个数字是 5 ,nums[1] 的最后一个数字是 4 。2 和 5 互质,因此 gcd(5,4) == 1 。
|
||||||
|
i = 2 和 j = 3 :nums[0] 的第一个数字是 1 ,nums[1] 的最后一个数字是 4 。2 和 5 互质,因此 gcd(1,4) == 1 。
|
||||||
|
因此,返回 5 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>输入:</strong>nums = [11,21,12]
|
||||||
|
<strong>输出:</strong>2
|
||||||
|
<strong>解释:</strong>共有 2 组美丽下标对:
|
||||||
|
i = 0 和 j = 1 :nums[0] 的第一个数字是 1 ,nums[1] 的最后一个数字是 1 。gcd(1,1) == 1 。
|
||||||
|
i = 0 和 j = 2 :nums[0] 的第一个数字是 1 ,nums[1] 的最后一个数字是 2 。gcd(1,2) == 1 。
|
||||||
|
因此,返回 2 。</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>2 <= nums.length <= 100</code></li>
|
||||||
|
<li><code>1 <= nums[i] <= 9999</code></li>
|
||||||
|
<li><code>nums[i] % 10 != 0</code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,46 @@
|
|||||||
|
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A subarray of <code>nums</code> is called <strong>continuous</strong> if:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>Let <code>i</code>, <code>i + 1</code>, ..., <code>j</code><sub> </sub>be the indices in the subarray. Then, for each pair of indices <code>i <= i<sub>1</sub>, i<sub>2</sub> <= j</code>, <code><font face="monospace">0 <=</font> |nums[i<sub>1</sub>] - nums[i<sub>2</sub>]| <= 2</code>.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Return <em>the total number of <strong>continuous</strong> subarrays.</em></p>
|
||||||
|
|
||||||
|
<p>A subarray is a contiguous <strong>non-empty</strong> sequence of elements within an array.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [5,4,2,4]
|
||||||
|
<strong>Output:</strong> 8
|
||||||
|
<strong>Explanation:</strong>
|
||||||
|
Continuous subarray of size 1: [5], [4], [2], [4].
|
||||||
|
Continuous subarray of size 2: [5,4], [4,2], [2,4].
|
||||||
|
Continuous subarray of size 3: [4,2,4].
|
||||||
|
Thereare no subarrys of size 4.
|
||||||
|
Total continuous subarrays = 4 + 3 + 1 = 8.
|
||||||
|
It can be shown that there are no more continuous subarrays.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [1,2,3]
|
||||||
|
<strong>Output:</strong> 6
|
||||||
|
<strong>Explanation:</strong>
|
||||||
|
Continuous subarray of size 1: [1], [2], [3].
|
||||||
|
Continuous subarray of size 2: [1,2], [2,3].
|
||||||
|
Continuous subarray of size 3: [1,2,3].
|
||||||
|
Total continuous subarrays = 3 + 2 + 1 = 6.
|
||||||
|
</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,36 @@
|
|||||||
|
<p>You are given an integer <code>n</code>. We say that two integers <code>x</code> and <code>y</code> form a prime number pair if:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= x <= y <= n</code></li>
|
||||||
|
<li><code>x + y == n</code></li>
|
||||||
|
<li><code>x</code> and <code>y</code> are prime numbers</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Return <em>the 2D sorted list of prime number pairs</em> <code>[x<sub>i</sub>, y<sub>i</sub>]</code>. The list should be sorted in <strong>increasing</strong> order of <code>x<sub>i</sub></code>. If there are no prime number pairs at all, return <em>an empty array</em>.</p>
|
||||||
|
|
||||||
|
<p><strong>Note:</strong> A prime number is a natural number greater than <code>1</code> with only two factors, itself and <code>1</code>.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> n = 10
|
||||||
|
<strong>Output:</strong> [[3,7],[5,5]]
|
||||||
|
<strong>Explanation:</strong> In this example, there are two prime pairs that satisfy the criteria.
|
||||||
|
These pairs are [3,7] and [5,5], and we return them in the sorted order as described in the problem statement.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> n = 2
|
||||||
|
<strong>Output:</strong> []
|
||||||
|
<strong>Explanation:</strong> We can show that there is no prime number pair that gives a sum of 2, so we return an empty array.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= n <= 10<sup>6</sup></code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,61 @@
|
|||||||
|
<p>You are given a <strong>0-indexed</strong> array <code>words</code> containing <code>n</code> strings.</p>
|
||||||
|
|
||||||
|
<p>Let's define a <strong>join</strong> operation <code>join(x, y)</code> between two strings <code>x</code> and <code>y</code> as concatenating them into <code>xy</code>. However, if the last character of <code>x</code> is equal to the first character of <code>y</code>, one of them is <strong>deleted</strong>.</p>
|
||||||
|
|
||||||
|
<p>For example <code>join("ab", "ba") = "aba"</code> and <code>join("ab", "cde") = "abcde"</code>.</p>
|
||||||
|
|
||||||
|
<p>You are to perform <code>n - 1</code> <strong>join</strong> operations. Let <code>str<sub>0</sub> = words[0]</code>. Starting from <code>i = 1</code> up to <code>i = n - 1</code>, for the <code>i<sup>th</sup></code> operation, you can do one of the following:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>Make <code>str<sub>i</sub> = join(str<sub>i - 1</sub>, words[i])</code></li>
|
||||||
|
<li>Make <code>str<sub>i</sub> = join(words[i], str<sub>i - 1</sub>)</code></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Your task is to <strong>minimize</strong> the length of <code>str<sub>n - 1</sub></code>.</p>
|
||||||
|
|
||||||
|
<p>Return <em>an integer denoting the minimum possible length of</em> <code>str<sub>n - 1</sub></code>.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> words = ["aa","ab","bc"]
|
||||||
|
<strong>Output:</strong> 4
|
||||||
|
<strong>Explanation: </strong>In this example, we can perform join operations in the following order to minimize the length of str<sub>2</sub>:
|
||||||
|
str<sub>0</sub> = "aa"
|
||||||
|
str<sub>1</sub> = join(str<sub>0</sub>, "ab") = "aab"
|
||||||
|
str<sub>2</sub> = join(str<sub>1</sub>, "bc") = "aabc"
|
||||||
|
It can be shown that the minimum possible length of str<sub>2</sub> is 4.</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> words = ["ab","b"]
|
||||||
|
<strong>Output:</strong> 2
|
||||||
|
<strong>Explanation:</strong> In this example, str<sub>0</sub> = "ab", there are two ways to get str<sub>1</sub>:
|
||||||
|
join(str<sub>0</sub>, "b") = "ab" or join("b", str<sub>0</sub>) = "bab".
|
||||||
|
The first string, "ab", has the minimum length. Hence, the answer is 2.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 3:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> words = ["aaa","c","aba"]
|
||||||
|
<strong>Output:</strong> 6
|
||||||
|
<strong>Explanation:</strong> In this example, we can perform join operations in the following order to minimize the length of str<sub>2</sub>:
|
||||||
|
str<sub>0</sub> = "aaa"
|
||||||
|
str<sub>1</sub> = join(str<sub>0</sub>, "c") = "aaac"
|
||||||
|
str<sub>2</sub> = join("aba", str<sub>1</sub>) = "abaaac"
|
||||||
|
It can be shown that the minimum possible length of str<sub>2</sub> is 6.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<div class="notranslate" style="all: initial;"> </div>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= words.length <= 1000</code></li>
|
||||||
|
<li><code>1 <= words[i].length <= 50</code></li>
|
||||||
|
<li>Each character in <code>words[i]</code> is an English lowercase letter</li>
|
||||||
|
</ul>
|
@ -0,0 +1,36 @@
|
|||||||
|
<p>You are given a binary array <code>nums</code>.</p>
|
||||||
|
|
||||||
|
<p>A subarray of an array is <strong>good</strong> if it contains <strong>exactly</strong> <strong>one</strong> element with the value <code>1</code>.</p>
|
||||||
|
|
||||||
|
<p>Return <em>an integer denoting the number of ways to split the array </em><code>nums</code><em> into <strong>good</strong> subarrays</em>. As the number may be too large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
|
||||||
|
|
||||||
|
<p>A subarray is a contiguous <strong>non-empty</strong> sequence of elements within an array.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [0,1,0,0,1]
|
||||||
|
<strong>Output:</strong> 3
|
||||||
|
<strong>Explanation:</strong> There are 3 ways to split nums into good subarrays:
|
||||||
|
- [0,1] [0,0,1]
|
||||||
|
- [0,1,0] [0,1]
|
||||||
|
- [0,1,0,0] [1]
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [0,1,0]
|
||||||
|
<strong>Output:</strong> 1
|
||||||
|
<strong>Explanation:</strong> There is 1 way to split nums into good subarrays:
|
||||||
|
- [0,1,0]
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>0 <= nums[i] <= 1</code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,36 @@
|
|||||||
|
<p>You are given two integers <code>num1</code> and <code>num2</code>.</p>
|
||||||
|
|
||||||
|
<p>In one operation, you can choose integer <code>i</code> in the range <code>[0, 60]</code> and subtract <code>2<sup>i</sup> + num2</code> from <code>num1</code>.</p>
|
||||||
|
|
||||||
|
<p>Return <em>the integer denoting the <strong>minimum</strong> number of operations needed to make</em> <code>num1</code> <em>equal to</em> <code>0</code>.</p>
|
||||||
|
|
||||||
|
<p>If it is impossible to make <code>num1</code> equal to <code>0</code>, return <code>-1</code>.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> num1 = 3, num2 = -2
|
||||||
|
<strong>Output:</strong> 3
|
||||||
|
<strong>Explanation:</strong> We can make 3 equal to 0 with the following operations:
|
||||||
|
- We choose i = 2 and substract 2<sup>2</sup> + (-2) from 3, 3 - (4 + (-2)) = 1.
|
||||||
|
- We choose i = 2 and substract 2<sup>2</sup> + (-2) from 1, 1 - (4 + (-2)) = -1.
|
||||||
|
- We choose i = 0 and substract 2<sup>0</sup> + (-2) from -1, (-1) - (1 + (-2)) = 0.
|
||||||
|
It can be proven, that 3 is the minimum number of operations that we need to perform.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> num1 = 5, num2 = 7
|
||||||
|
<strong>Output:</strong> -1
|
||||||
|
<strong>Explanation:</strong> It can be proven, that it is impossible to make 5 equal to 0 with the given operation.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= num1 <= 10<sup>9</sup></code></li>
|
||||||
|
<li><code><font face="monospace">-10<sup>9</sup> <= num2 <= 10<sup>9</sup></font></code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,48 @@
|
|||||||
|
<p>The <strong>imbalance number</strong> of a <strong>0-indexed</strong> integer array <code>arr</code> of length <code>n</code> is defined as the number of indices in <code>sarr = sorted(arr)</code> such that:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>0 <= i < n - 1</code>, and</li>
|
||||||
|
<li><code>sarr[i+1] - sarr[i] > 1</code></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Here, <code>sorted(arr)</code> is the function that returns the sorted version of <code>arr</code>.</p>
|
||||||
|
|
||||||
|
<p>Given a <strong>0-indexed</strong> integer array <code>nums</code>, return <em>the <strong>sum of imbalance numbers</strong> of all its <strong>subarrays</strong></em>.</p>
|
||||||
|
|
||||||
|
<p>A <strong>subarray</strong> is a contiguous <strong>non-empty</strong> sequence of elements within an array.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [2,3,1,4]
|
||||||
|
<strong>Output:</strong> 3
|
||||||
|
<strong>Explanation:</strong> There are 3 subarrays with non-zero<strong> </strong>imbalance numbers:
|
||||||
|
- Subarray [3, 1] with an imbalance number of 1.
|
||||||
|
- Subarray [3, 1, 4] with an imbalance number of 1.
|
||||||
|
- Subarray [1, 4] with an imbalance number of 1.
|
||||||
|
The imbalance number of all other subarrays is 0. Hence, the sum of imbalance numbers of all the subarrays of nums is 3.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [1,3,3,3,5]
|
||||||
|
<strong>Output:</strong> 8
|
||||||
|
<strong>Explanation:</strong> There are 7 subarrays with non-zero imbalance numbers:
|
||||||
|
- Subarray [1, 3] with an imbalance number of 1.
|
||||||
|
- Subarray [1, 3, 3] with an imbalance number of 1.
|
||||||
|
- Subarray [1, 3, 3, 3] with an imbalance number of 1.
|
||||||
|
- Subarray [1, 3, 3, 3, 5] with an imbalance number of 2.
|
||||||
|
- Subarray [3, 3, 3, 5] with an imbalance number of 1.
|
||||||
|
- Subarray [3, 3, 5] with an imbalance number of 1.
|
||||||
|
- Subarray [3, 5] with an imbalance number of 1.
|
||||||
|
The imbalance number of all other subarrays is 0. Hence, the sum of imbalance numbers of all the subarrays of nums is 8. </pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= nums.length <= 1000</code></li>
|
||||||
|
<li><code>1 <= nums[i] <= nums.length</code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,51 @@
|
|||||||
|
<p>You are given a <strong>0-indexed</strong> array <code>words</code> consisting of <strong>distinct</strong> strings.</p>
|
||||||
|
|
||||||
|
<p>The string <code>words[i]</code> can be paired with the string <code>words[j]</code> if:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>The string <code>words[i]</code> is equal to the reversed string of <code>words[j]</code>.</li>
|
||||||
|
<li><code>0 <= i < j < words.length</code>.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Return <em>the <strong>maximum</strong> number of pairs that can be formed from the array </em><code>words</code><em>.</em></p>
|
||||||
|
|
||||||
|
<p>Note that each string can belong in <strong>at most one</strong> pair.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> words = ["cd","ac","dc","ca","zz"]
|
||||||
|
<strong>Output:</strong> 2
|
||||||
|
<strong>Explanation:</strong> In this example, we can form 2 pair of strings in the following way:
|
||||||
|
- We pair the 0<sup>th</sup> string with the 2<sup>nd</sup> string, as the reversed string of word[0] is "dc" and is equal to words[2].
|
||||||
|
- We pair the 1<sup>st</sup> string with the 3<sup>rd</sup> string, as the reversed string of word[1] is "ca" and is equal to words[3].
|
||||||
|
It can be proven that 2 is the maximum number of pairs that can be formed.</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> words = ["ab","ba","cc"]
|
||||||
|
<strong>Output:</strong> 1
|
||||||
|
<strong>Explanation:</strong> In this example, we can form 1 pair of strings in the following way:
|
||||||
|
- We pair the 0<sup>th</sup> string with the 1<sup>st</sup> string, as the reversed string of words[1] is "ab" and is equal to words[0].
|
||||||
|
It can be proven that 1 is the maximum number of pairs that can be formed.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 3:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> words = ["aa","ab"]
|
||||||
|
<strong>Output:</strong> 0
|
||||||
|
<strong>Explanation:</strong> In this example, we are unable to form any pair of strings.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= words.length <= 50</code></li>
|
||||||
|
<li><code>words[i].length == 2</code></li>
|
||||||
|
<li><code>words</code> consists of distinct strings.</li>
|
||||||
|
<li><code>words[i]</code> contains only lowercase English letters.</li>
|
||||||
|
</ul>
|
@ -0,0 +1,50 @@
|
|||||||
|
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> and an integer <code>threshold</code>.</p>
|
||||||
|
|
||||||
|
<p>Find the length of the <strong>longest subarray</strong> of <code>nums</code> starting at index <code>l</code> and ending at index <code>r</code> <code>(0 <= l <= r < nums.length)</code> that satisfies the following conditions:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>nums[l] % 2 == 0</code></li>
|
||||||
|
<li>For all indices <code>i</code> in the range <code>[l, r - 1]</code>, <code>nums[i] % 2 != nums[i + 1] % 2</code></li>
|
||||||
|
<li>For all indices <code>i</code> in the range <code>[l, r]</code>, <code>nums[i] <= threshold</code></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Return <em>an integer denoting the length of the longest such subarray.</em></p>
|
||||||
|
|
||||||
|
<p><strong>Note:</strong> A <strong>subarray</strong> is a contiguous non-empty sequence of elements within an array.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [3,2,5,4], threshold = 5
|
||||||
|
<strong>Output:</strong> 3
|
||||||
|
<strong>Explanation:</strong> In this example, we can select the subarray that starts at l = 1 and ends at r = 3 => [2,5,4]. This subarray satisfies the conditions.
|
||||||
|
Hence, the answer is the length of the subarray, 3. We can show that 3 is the maximum possible achievable length.</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [1,2], threshold = 2
|
||||||
|
<strong>Output:</strong> 1
|
||||||
|
<strong>Explanation:</strong> In this example, we can select the subarray that starts at l = 1 and ends at r = 1 => [2].
|
||||||
|
It satisfies all the conditions and we can show that 1 is the maximum possible achievable length.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 3:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [2,3,4,5], threshold = 4
|
||||||
|
<strong>Output:</strong> 3
|
||||||
|
<strong>Explanation:</strong> In this example, we can select the subarray that starts at l = 0 and ends at r = 2 => [2,3,4].
|
||||||
|
It satisfies all the conditions.
|
||||||
|
Hence, the answer is the length of the subarray, 3. We can show that 3 is the maximum possible achievable length.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= nums.length <= 100 </code></li>
|
||||||
|
<li><code>1 <= nums[i] <= 100 </code></li>
|
||||||
|
<li><code>1 <= threshold <= 100</code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,55 @@
|
|||||||
|
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p>
|
||||||
|
|
||||||
|
<p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <strong>'L'</strong> for <strong>left</strong> or <strong>'R'</strong> for <strong>right</strong>). All integers in <code>positions</code> are <strong>unique</strong>.</p>
|
||||||
|
|
||||||
|
<p>All robots start moving on the line<strong> simultaneously</strong> at the <strong>same speed </strong>in their given directions. If two robots ever share the same position while moving, they will <strong>collide</strong>.</p>
|
||||||
|
|
||||||
|
<p>If two robots collide, the robot with <strong>lower health</strong> is <strong>removed</strong> from the line, and the health of the other robot <strong>decreases</strong> <strong>by one</strong>. The surviving robot continues in the <strong>same</strong> direction it was going. If both robots have the <strong>same</strong> health, they are both<strong> </strong>removed from the line.</p>
|
||||||
|
|
||||||
|
<p>Your task is to determine the <strong>health</strong> of the robots that survive the collisions, in the same <strong>order </strong>that the robots were given,<strong> </strong>i.e. final heath of robot 1 (if survived), final health of robot 2 (if survived), and so on. If there are no survivors, return an empty array.</p>
|
||||||
|
|
||||||
|
<p>Return <em>an array containing the health of the remaining robots (in the order they were given in the input), after no further collisions can occur.</em></p>
|
||||||
|
|
||||||
|
<p><strong>Note:</strong> The positions may be unsorted.</p>
|
||||||
|
|
||||||
|
<div class="notranslate" style="all: initial;"> </div>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<p><img height="169" src="https://assets.leetcode.com/uploads/2023/05/15/image-20230516011718-12.png" width="808" /></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> positions = [5,4,3,2,1], healths = [2,17,9,15,10], directions = "RRRRR"
|
||||||
|
<strong>Output:</strong> [2,17,9,15,10]
|
||||||
|
<strong>Explanation:</strong> No collision occurs in this example, since all robots are moving in the same direction. So, the health of the robots in order from the first robot is returned, [2, 17, 9, 15, 10].
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<p><img height="176" src="https://assets.leetcode.com/uploads/2023/05/15/image-20230516004433-7.png" width="717" /></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> positions = [3,5,2,6], healths = [10,10,15,12], directions = "RLRL"
|
||||||
|
<strong>Output:</strong> [14]
|
||||||
|
<strong>Explanation:</strong> There are 2 collisions in this example. Firstly, robot 1 and robot 2 will collide, and since both have the same health, they will be removed from the line. Next, robot 3 and robot 4 will collide and since robot 4's health is smaller, it gets removed, and robot 3's health becomes 15 - 1 = 14. Only robot 3 remains, so we return [14].
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 3:</strong></p>
|
||||||
|
|
||||||
|
<p><img height="172" src="https://assets.leetcode.com/uploads/2023/05/15/image-20230516005114-9.png" width="732" /></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> positions = [1,2,5,6], healths = [10,10,11,11], directions = "RLRL"
|
||||||
|
<strong>Output:</strong> []
|
||||||
|
<strong>Explanation:</strong> Robot 1 and robot 2 will collide and since both have the same health, they are both removed. Robot 3 and 4 will collide and since both have the same health, they are both removed. So, we return an empty array, [].</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= positions.length == healths.length == directions.length == n <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>1 <= positions[i], healths[i] <= 10<sup>9</sup></code></li>
|
||||||
|
<li><code>directions[i] == 'L'</code> or <code>directions[i] == 'R'</code></li>
|
||||||
|
<li>All values in <code>positions</code> are distinct</li>
|
||||||
|
</ul>
|
@ -0,0 +1,33 @@
|
|||||||
|
<p>You are given three integers <code>x</code>, <code>y</code>, and <code>z</code>.</p>
|
||||||
|
|
||||||
|
<p>You have <code>x</code> strings equal to <code>"AA"</code>, <code>y</code> strings equal to <code>"BB"</code>, and <code>z</code> strings equal to <code>"AB"</code>. You want to choose some (possibly all or none) of these strings and concactenate them in some order to form a new string. This new string must not contain <code>"AAA"</code> or <code>"BBB"</code> as a substring.</p>
|
||||||
|
|
||||||
|
<p>Return <em>the maximum possible length of the new string</em>.</p>
|
||||||
|
|
||||||
|
<p>A <b>substring</b> is a contiguous <strong>non-empty</strong> sequence of characters within a string.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> x = 2, y = 5, z = 1
|
||||||
|
<strong>Output:</strong> 12
|
||||||
|
<strong>Explanation: </strong>We can concactenate the strings "BB", "AA", "BB", "AA", "BB", and "AB" in that order. Then, our new string is "BBAABBAABBAB".
|
||||||
|
That string has length 12, and we can show that it is impossible to construct a string of longer length.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> x = 3, y = 2, z = 2
|
||||||
|
<strong>Output:</strong> 14
|
||||||
|
<strong>Explanation:</strong> We can concactenate the strings "AB", "AB", "AA", "BB", "AA", "BB", and "AA" in that order. Then, our new string is "ABABAABBAABBAA".
|
||||||
|
That string has length 14, and we can show that it is impossible to construct a string of longer length.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= x, y, z <= 50</code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,44 @@
|
|||||||
|
<p>You are given an integer <code>n</code> denoting the total number of servers and a <strong>2D</strong> <strong>0-indexed </strong>integer array <code>logs</code>, where <code>logs[i] = [server_id, time]</code> denotes that the server with id <code>server_id</code> received a request at time <code>time</code>.</p>
|
||||||
|
|
||||||
|
<p>You are also given an integer <code>x</code> and a <strong>0-indexed</strong> integer array <code>queries</code>.</p>
|
||||||
|
|
||||||
|
<p>Return <em>a <strong>0-indexed</strong> integer array</em> <code>arr</code> <em>of length</em> <code>queries.length</code> <em>where</em> <code>arr[i]</code> <em>represents the number of servers that <strong>did not receive</strong> any requests during the time interval</em> <code>[queries[i] - x, queries[i]]</code>.</p>
|
||||||
|
|
||||||
|
<p>Note that the time intervals are inclusive.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> n = 3, logs = [[1,3],[2,6],[1,5]], x = 5, queries = [10,11]
|
||||||
|
<strong>Output:</strong> [1,2]
|
||||||
|
<strong>Explanation:</strong>
|
||||||
|
For queries[0]: The servers with ids 1 and 2 get requests in the duration of [5, 10]. Hence, only server 3 gets zero requests.
|
||||||
|
For queries[1]: Only the server with id 2 gets a request in duration of [6,11]. Hence, the servers with ids 1 and 3 are the only servers that do not receive any requests during that time period.
|
||||||
|
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> n = 3, logs = [[2,4],[2,1],[1,2],[3,1]], x = 2, queries = [3,4]
|
||||||
|
<strong>Output:</strong> [0,1]
|
||||||
|
<strong>Explanation:</strong>
|
||||||
|
For queries[0]: All servers get at least one request in the duration of [1, 3].
|
||||||
|
For queries[1]: Only server with id 3 gets no request in the duration [2,4].
|
||||||
|
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= n <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>1 <= logs.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>1 <= queries.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code><font face="monospace">logs[i].length == 2</font></code></li>
|
||||||
|
<li><code>1 <= logs[i][0] <= n</code></li>
|
||||||
|
<li><code>1 <= logs[i][1] <= 10<sup>6</sup></code></li>
|
||||||
|
<li><code>1 <= x <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>x < queries[i] <= 10<sup>6</sup></code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,40 @@
|
|||||||
|
<p>You are given a <strong>0-indexed </strong>integer array <code>nums</code>. A pair of indices <code>i</code>, <code>j</code> where <code>0 <= i < j < nums.length</code> is called beautiful if the <strong>first digit</strong> of <code>nums[i]</code> and the <strong>last digit</strong> of <code>nums[j]</code> are <strong>coprime</strong>.</p>
|
||||||
|
|
||||||
|
<p>Return <em>the total number of beautiful pairs in </em><code>nums</code>.</p>
|
||||||
|
|
||||||
|
<p>Two integers <code>x</code> and <code>y</code> are <strong>coprime</strong> if there is no integer greater than 1 that divides both of them. In other words, <code>x</code> and <code>y</code> are coprime if <code>gcd(x, y) == 1</code>, where <code>gcd(x, y)</code> is the <strong>greatest common divisor</strong> of <code>x</code> and <code>y</code>.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [2,5,1,4]
|
||||||
|
<strong>Output:</strong> 5
|
||||||
|
<strong>Explanation:</strong> There are 5 beautiful pairs in nums:
|
||||||
|
When i = 0 and j = 1: the first digit of nums[0] is 2, and the last digit of nums[1] is 5. We can confirm that 2 and 5 are coprime, since gcd(2,5) == 1.
|
||||||
|
When i = 0 and j = 2: the first digit of nums[0] is 2, and the last digit of nums[2] is 1. Indeed, gcd(2,1) == 1.
|
||||||
|
When i = 1 and j = 2: the first digit of nums[1] is 5, and the last digit of nums[2] is 1. Indeed, gcd(5,1) == 1.
|
||||||
|
When i = 1 and j = 3: the first digit of nums[1] is 5, and the last digit of nums[3] is 4. Indeed, gcd(5,4) == 1.
|
||||||
|
When i = 2 and j = 3: the first digit of nums[2] is 1, and the last digit of nums[3] is 4. Indeed, gcd(1,4) == 1.
|
||||||
|
Thus, we return 5.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [11,21,12]
|
||||||
|
<strong>Output:</strong> 2
|
||||||
|
<strong>Explanation:</strong> There are 2 beautiful pairs:
|
||||||
|
When i = 0 and j = 1: the first digit of nums[0] is 1, and the last digit of nums[1] is 1. Indeed, gcd(1,1) == 1.
|
||||||
|
When i = 0 and j = 2: the first digit of nums[0] is 1, and the last digit of nums[2] is 2. Indeed, gcd(1,2) == 1.
|
||||||
|
Thus, we return 2.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>2 <= nums.length <= 100</code></li>
|
||||||
|
<li><code>1 <= nums[i] <= 9999</code></li>
|
||||||
|
<li><code>nums[i] % 10 != 0</code></li>
|
||||||
|
</ul>
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,47 @@
|
|||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"question": {
|
||||||
|
"questionId": "2770",
|
||||||
|
"questionFrontendId": "2754",
|
||||||
|
"boundTopicId": null,
|
||||||
|
"title": "Bind Function to Context",
|
||||||
|
"titleSlug": "bind-function-to-context",
|
||||||
|
"content": null,
|
||||||
|
"translatedTitle": null,
|
||||||
|
"translatedContent": null,
|
||||||
|
"isPaidOnly": true,
|
||||||
|
"difficulty": "Medium",
|
||||||
|
"likes": 5,
|
||||||
|
"dislikes": 0,
|
||||||
|
"isLiked": null,
|
||||||
|
"similarQuestions": "[]",
|
||||||
|
"exampleTestcases": "function f(multiplier) { return this.x * multiplier; }\n{\"x\":10}\n[5]\nfunction speak() { return \"My name is \" + this.name; }\n{\"name\":\"Kathy\"}\n[]",
|
||||||
|
"categoryTitle": "JavaScript",
|
||||||
|
"contributors": [],
|
||||||
|
"topicTags": [],
|
||||||
|
"companyTagStats": null,
|
||||||
|
"codeSnippets": null,
|
||||||
|
"stats": "{\"totalAccepted\": \"59\", \"totalSubmission\": \"63\", \"totalAcceptedRaw\": 59, \"totalSubmissionRaw\": 63, \"acRate\": \"93.7%\"}",
|
||||||
|
"hints": [
|
||||||
|
"The easiest way to solve this is to use the built-in fn.apply() method.",
|
||||||
|
"Without built-in methods, you need to figure out a way to call the function (this) from context object. That will associate \"this\" appropriately.",
|
||||||
|
"You can create a new Symbol(). Attach the symbol to the context object and set the method to be \"this\". Then call the method on the symbol."
|
||||||
|
],
|
||||||
|
"solution": null,
|
||||||
|
"status": null,
|
||||||
|
"sampleTestCase": "function f(multiplier) { return this.x * multiplier; }\n{\"x\":10}\n[5]",
|
||||||
|
"metaData": "{\n \"name\": \"jsonParse\",\n \"params\": [\n {\n \"name\": \"fn\",\n \"type\": \"string\"\n },\n {\n \"type\": \"string\",\n \"name\": \"obj\"\n },\n {\n \"type\": \"string\",\n \"name\": \"inputs\"\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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"question": {
|
||||||
|
"questionId": "2851",
|
||||||
|
"questionFrontendId": "2759",
|
||||||
|
"boundTopicId": null,
|
||||||
|
"title": "Convert JSON String to Object",
|
||||||
|
"titleSlug": "convert-json-string-to-object",
|
||||||
|
"content": null,
|
||||||
|
"translatedTitle": null,
|
||||||
|
"translatedContent": null,
|
||||||
|
"isPaidOnly": true,
|
||||||
|
"difficulty": "Hard",
|
||||||
|
"likes": 4,
|
||||||
|
"dislikes": 0,
|
||||||
|
"isLiked": null,
|
||||||
|
"similarQuestions": "[]",
|
||||||
|
"exampleTestcases": "'{\"a\":2,\"b\":[1,2,3]}'\n'true'\n'[1,5,\"false\",{\"a\":2}]'",
|
||||||
|
"categoryTitle": "JavaScript",
|
||||||
|
"contributors": [],
|
||||||
|
"topicTags": [],
|
||||||
|
"companyTagStats": null,
|
||||||
|
"codeSnippets": null,
|
||||||
|
"stats": "{\"totalAccepted\": \"27\", \"totalSubmission\": \"37\", \"totalAcceptedRaw\": 27, \"totalSubmissionRaw\": 37, \"acRate\": \"73.0%\"}",
|
||||||
|
"hints": [],
|
||||||
|
"solution": null,
|
||||||
|
"status": null,
|
||||||
|
"sampleTestCase": "'{\"a\":2,\"b\":[1,2,3]}'",
|
||||||
|
"metaData": "{\n \"name\": \"jsonParse\",\n \"params\": [\n {\n \"name\": \"str\",\n \"type\": \"string\"\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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,62 @@
|
|||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"question": {
|
||||||
|
"questionId": "2852",
|
||||||
|
"questionFrontendId": "2752",
|
||||||
|
"boundTopicId": null,
|
||||||
|
"title": "Customers with Maximum Number of Transactions on Consecutive Days",
|
||||||
|
"titleSlug": "customers-with-maximum-number-of-transactions-on-consecutive-days",
|
||||||
|
"content": null,
|
||||||
|
"translatedTitle": null,
|
||||||
|
"translatedContent": null,
|
||||||
|
"isPaidOnly": true,
|
||||||
|
"difficulty": "Hard",
|
||||||
|
"likes": 6,
|
||||||
|
"dislikes": 1,
|
||||||
|
"isLiked": null,
|
||||||
|
"similarQuestions": "[]",
|
||||||
|
"exampleTestcases": "{\"headers\":{\"Transactions\":[\"transaction_id\",\"customer_id\",\"transaction_date\",\"amount\"]},\"rows\":{\"Transactions\":[[1,101,\"2023-05-01\",100],[2,101,\"2023-05-02\",150],[3,101,\"2023-05-03\",200],[4,102,\"2023-05-01\",50],[5,102,\"2023-05-03\",100],[6,102,\"2023-05-04\",200],[7,105,\"2023-05-01\",100],[8,105,\"2023-05-02\",150],[9,105,\"2023-05-03\",200]]}}",
|
||||||
|
"categoryTitle": "Database",
|
||||||
|
"contributors": [],
|
||||||
|
"topicTags": [
|
||||||
|
{
|
||||||
|
"name": "Database",
|
||||||
|
"slug": "database",
|
||||||
|
"translatedName": null,
|
||||||
|
"__typename": "TopicTagNode"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"companyTagStats": null,
|
||||||
|
"codeSnippets": null,
|
||||||
|
"stats": "{\"totalAccepted\": \"80\", \"totalSubmission\": \"180\", \"totalAcceptedRaw\": 80, \"totalSubmissionRaw\": 180, \"acRate\": \"44.4%\"}",
|
||||||
|
"hints": [],
|
||||||
|
"solution": null,
|
||||||
|
"status": null,
|
||||||
|
"sampleTestCase": "{\"headers\":{\"Transactions\":[\"transaction_id\",\"customer_id\",\"transaction_date\",\"amount\"]},\"rows\":{\"Transactions\":[[1,101,\"2023-05-01\",100],[2,101,\"2023-05-02\",150],[3,101,\"2023-05-03\",200],[4,102,\"2023-05-01\",50],[5,102,\"2023-05-03\",100],[6,102,\"2023-05-04\",200],[7,105,\"2023-05-01\",100],[8,105,\"2023-05-02\",150],[9,105,\"2023-05-03\",200]]}}",
|
||||||
|
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Transactions (transaction_id int, customer_id int, transaction_date date, amount int)\"\n ],\n \"mssql\": [\n \"Create table Transactions (transaction_id int, customer_id int, transaction_date date, amount int)\"\n ],\n \"oraclesql\": [\n \"Create table Transactions (transaction_id int, customer_id int, transaction_date date, amount int)\",\n \"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"\n ],\n \"database\": true,\n \"languages\": [\n \"mysql\",\n \"mssql\",\n \"oraclesql\"\n ]\n}",
|
||||||
|
"judgerAvailable": true,
|
||||||
|
"judgeType": "large",
|
||||||
|
"mysqlSchemas": [
|
||||||
|
"Create table If Not Exists Transactions (transaction_id int, customer_id int, transaction_date date, amount int)",
|
||||||
|
"Truncate table Transactions",
|
||||||
|
"insert into Transactions (transaction_id, customer_id, transaction_date, amount) values ('1', '101', '2023-05-01', '100')",
|
||||||
|
"insert into Transactions (transaction_id, customer_id, transaction_date, amount) values ('2', '101', '2023-05-02', '150')",
|
||||||
|
"insert into Transactions (transaction_id, customer_id, transaction_date, amount) values ('3', '101', '2023-05-03', '200')",
|
||||||
|
"insert into Transactions (transaction_id, customer_id, transaction_date, amount) values ('4', '102', '2023-05-01', '50')",
|
||||||
|
"insert into Transactions (transaction_id, customer_id, transaction_date, amount) values ('5', '102', '2023-05-03', '100')",
|
||||||
|
"insert into Transactions (transaction_id, customer_id, transaction_date, amount) values ('6', '102', '2023-05-04', '200')",
|
||||||
|
"insert into Transactions (transaction_id, customer_id, transaction_date, amount) values ('7', '105', '2023-05-01', '100')",
|
||||||
|
"insert into Transactions (transaction_id, customer_id, transaction_date, amount) values ('8', '105', '2023-05-02', '150')",
|
||||||
|
"insert into Transactions (transaction_id, customer_id, transaction_date, amount) values ('9', '105', '2023-05-03', '200')"
|
||||||
|
],
|
||||||
|
"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,43 @@
|
|||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"question": {
|
||||||
|
"questionId": "2795",
|
||||||
|
"questionFrontendId": "2755",
|
||||||
|
"boundTopicId": null,
|
||||||
|
"title": "Deep Merge of Two Objects",
|
||||||
|
"titleSlug": "deep-merge-of-two-objects",
|
||||||
|
"content": null,
|
||||||
|
"translatedTitle": null,
|
||||||
|
"translatedContent": null,
|
||||||
|
"isPaidOnly": true,
|
||||||
|
"difficulty": "Medium",
|
||||||
|
"likes": 6,
|
||||||
|
"dislikes": 0,
|
||||||
|
"isLiked": null,
|
||||||
|
"similarQuestions": "[]",
|
||||||
|
"exampleTestcases": "{\"a\": 1, \"c\": 3}\n{\"a\": 2, \"b\": 2}\n[{}, 2, 3]\n[[], 5]\n{\"a\": 1, \"b\": {\"c\": [1,[2,7],5], \"d\": 2}}\n{\"a\": 1, \"b\": {\"c\": [6,[6],[9]], \"e\": 3}}\ntrue\nnull",
|
||||||
|
"categoryTitle": "JavaScript",
|
||||||
|
"contributors": [],
|
||||||
|
"topicTags": [],
|
||||||
|
"companyTagStats": null,
|
||||||
|
"codeSnippets": null,
|
||||||
|
"stats": "{\"totalAccepted\": \"53\", \"totalSubmission\": \"74\", \"totalAcceptedRaw\": 53, \"totalSubmissionRaw\": 74, \"acRate\": \"71.6%\"}",
|
||||||
|
"hints": [],
|
||||||
|
"solution": null,
|
||||||
|
"status": null,
|
||||||
|
"sampleTestCase": "{\"a\": 1, \"c\": 3}\n{\"a\": 2, \"b\": 2}",
|
||||||
|
"metaData": "{\n \"name\": \"deepMerge\",\n \"params\": [\n {\n \"name\": \"obj1\",\n \"type\": \"string\"\n },\n {\n \"type\": \"string\",\n \"name\": \"obj2\"\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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"question": {
|
||||||
|
"questionId": "2814",
|
||||||
|
"questionFrontendId": "2757",
|
||||||
|
"boundTopicId": null,
|
||||||
|
"title": "Generate Circular Array Values",
|
||||||
|
"titleSlug": "generate-circular-array-values",
|
||||||
|
"content": null,
|
||||||
|
"translatedTitle": null,
|
||||||
|
"translatedContent": null,
|
||||||
|
"isPaidOnly": true,
|
||||||
|
"difficulty": "Medium",
|
||||||
|
"likes": 5,
|
||||||
|
"dislikes": 1,
|
||||||
|
"isLiked": null,
|
||||||
|
"similarQuestions": "[]",
|
||||||
|
"exampleTestcases": "[1,2,3,4,5]\n[1,2,6]\n0\n[10,11,12,13,14,15]\n[1,4,0,-1,-3]\n1\n[2,4,6,7,8,10]\n[-4,5,-3,10]\n3",
|
||||||
|
"categoryTitle": "JavaScript",
|
||||||
|
"contributors": [],
|
||||||
|
"topicTags": [],
|
||||||
|
"companyTagStats": null,
|
||||||
|
"codeSnippets": null,
|
||||||
|
"stats": "{\"totalAccepted\": \"34\", \"totalSubmission\": \"39\", \"totalAcceptedRaw\": 34, \"totalSubmissionRaw\": 39, \"acRate\": \"87.2%\"}",
|
||||||
|
"hints": [],
|
||||||
|
"solution": null,
|
||||||
|
"status": null,
|
||||||
|
"sampleTestCase": "[1,2,3,4,5]\n[1,2,6]\n0",
|
||||||
|
"metaData": "{\n \"name\": \"cycleGenerator\",\n \"params\": [\n {\n \"name\": \"arr\",\n \"type\": \"integer[]\"\n },\n {\n \"type\": \"integer[]\",\n \"name\": \"steps\"\n },\n {\n \"type\": \"integer\",\n \"name\": \"startIndex\"\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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
43
leetcode/originData/[no content]next-day.json
Normal file
43
leetcode/originData/[no content]next-day.json
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"question": {
|
||||||
|
"questionId": "2822",
|
||||||
|
"questionFrontendId": "2758",
|
||||||
|
"boundTopicId": null,
|
||||||
|
"title": "Next Day",
|
||||||
|
"titleSlug": "next-day",
|
||||||
|
"content": null,
|
||||||
|
"translatedTitle": null,
|
||||||
|
"translatedContent": null,
|
||||||
|
"isPaidOnly": true,
|
||||||
|
"difficulty": "Easy",
|
||||||
|
"likes": 5,
|
||||||
|
"dislikes": 1,
|
||||||
|
"isLiked": null,
|
||||||
|
"similarQuestions": "[]",
|
||||||
|
"exampleTestcases": "\"2014-06-20\"\n\"2017-10-31\"",
|
||||||
|
"categoryTitle": "JavaScript",
|
||||||
|
"contributors": [],
|
||||||
|
"topicTags": [],
|
||||||
|
"companyTagStats": null,
|
||||||
|
"codeSnippets": null,
|
||||||
|
"stats": "{\"totalAccepted\": \"105\", \"totalSubmission\": \"113\", \"totalAcceptedRaw\": 105, \"totalSubmissionRaw\": 113, \"acRate\": \"92.9%\"}",
|
||||||
|
"hints": [],
|
||||||
|
"solution": null,
|
||||||
|
"status": null,
|
||||||
|
"sampleTestCase": "\"2014-06-20\"",
|
||||||
|
"metaData": "{\n \"name\": \"foobar\",\n \"params\": [\n {\n \"type\": \"string\",\n \"name\": \"date\"\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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
43
leetcode/originData/[no content]query-batching.json
Normal file
43
leetcode/originData/[no content]query-batching.json
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"question": {
|
||||||
|
"questionId": "2806",
|
||||||
|
"questionFrontendId": "2756",
|
||||||
|
"boundTopicId": null,
|
||||||
|
"title": "Query Batching",
|
||||||
|
"titleSlug": "query-batching",
|
||||||
|
"content": null,
|
||||||
|
"translatedTitle": null,
|
||||||
|
"translatedContent": null,
|
||||||
|
"isPaidOnly": true,
|
||||||
|
"difficulty": "Hard",
|
||||||
|
"likes": 6,
|
||||||
|
"dislikes": 2,
|
||||||
|
"isLiked": null,
|
||||||
|
"similarQuestions": "[]",
|
||||||
|
"exampleTestcases": "async function(keys) { return keys.map(key => key + '!'); }\n100\n[{\"key\": \"a\", \"time\": 10}, {\"key\": \"b\", \"time\": 20}, {\"key\": \"c\", \"time\": 30}]\nasync function(keys) { await new Promise(res => setTimeout(res, 100)); return keys.map(key => key + '!'); }\n100\n[{\"key\": \"a\", \"time\": 10}, {\"key\": \"b\", \"time\": 20}, {\"key\": \"c\", \"time\": 30}]\nasync function(keys) { await new Promise(res => setTimeout(res, keys.length * 100)); return keys.map(key => key + '!'); }\n100\n[{\"key\": \"a\", \"time\": 10}, {\"key\": \"b\", \"time\": 20}, {\"key\": \"c\", \"time\": 30}, {\"key\": \"d\", \"time\": 40}, {\"key\": \"e\", \"time\": 250}, {\"key\": \"f\", \"time\": 300}]",
|
||||||
|
"categoryTitle": "JavaScript",
|
||||||
|
"contributors": [],
|
||||||
|
"topicTags": [],
|
||||||
|
"companyTagStats": null,
|
||||||
|
"codeSnippets": null,
|
||||||
|
"stats": "{\"totalAccepted\": \"26\", \"totalSubmission\": \"33\", \"totalAcceptedRaw\": 26, \"totalSubmissionRaw\": 33, \"acRate\": \"78.8%\"}",
|
||||||
|
"hints": [],
|
||||||
|
"solution": null,
|
||||||
|
"status": null,
|
||||||
|
"sampleTestCase": "async function(keys) { return keys.map(key => key + '!'); }\n100\n[{\"key\": \"a\", \"time\": 10}, {\"key\": \"b\", \"time\": 20}, {\"key\": \"c\", \"time\": 30}]",
|
||||||
|
"metaData": "{\n \"name\": \"QueryBatcher\",\n \"params\": [\n {\n \"name\": \"queryMultiple\",\n \"type\": \"string\"\n },\n {\n \"type\": \"integer\",\n \"name\": \"t\"\n },\n {\n \"type\": \"string\",\n \"name\": \"calls\"\n }\n ],\n \"return\": {\n \"type\": \"integer\"\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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
181
leetcode/originData/construct-the-longest-new-string.json
Normal file
181
leetcode/originData/construct-the-longest-new-string.json
Normal file
File diff suppressed because one or more lines are too long
161
leetcode/originData/continuous-subarrays.json
Normal file
161
leetcode/originData/continuous-subarrays.json
Normal file
File diff suppressed because one or more lines are too long
187
leetcode/originData/count-zero-request-servers.json
Normal file
187
leetcode/originData/count-zero-request-servers.json
Normal file
File diff suppressed because one or more lines are too long
181
leetcode/originData/decremental-string-concatenation.json
Normal file
181
leetcode/originData/decremental-string-concatenation.json
Normal file
File diff suppressed because one or more lines are too long
186
leetcode/originData/find-maximum-number-of-string-pairs.json
Normal file
186
leetcode/originData/find-maximum-number-of-string-pairs.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
File diff suppressed because one or more lines are too long
180
leetcode/originData/number-of-beautiful-pairs.json
Normal file
180
leetcode/originData/number-of-beautiful-pairs.json
Normal file
File diff suppressed because one or more lines are too long
161
leetcode/originData/prime-pairs-with-target-sum.json
Normal file
161
leetcode/originData/prime-pairs-with-target-sum.json
Normal file
File diff suppressed because one or more lines are too long
187
leetcode/originData/robot-collisions.json
Normal file
187
leetcode/originData/robot-collisions.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
181
leetcode/originData/ways-to-split-array-into-good-subarrays.json
Normal file
181
leetcode/originData/ways-to-split-array-into-good-subarrays.json
Normal file
File diff suppressed because one or more lines are too long
33
leetcode/problem/construct-the-longest-new-string.html
Normal file
33
leetcode/problem/construct-the-longest-new-string.html
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<p>You are given three integers <code>x</code>, <code>y</code>, and <code>z</code>.</p>
|
||||||
|
|
||||||
|
<p>You have <code>x</code> strings equal to <code>"AA"</code>, <code>y</code> strings equal to <code>"BB"</code>, and <code>z</code> strings equal to <code>"AB"</code>. You want to choose some (possibly all or none) of these strings and concactenate them in some order to form a new string. This new string must not contain <code>"AAA"</code> or <code>"BBB"</code> as a substring.</p>
|
||||||
|
|
||||||
|
<p>Return <em>the maximum possible length of the new string</em>.</p>
|
||||||
|
|
||||||
|
<p>A <b>substring</b> is a contiguous <strong>non-empty</strong> sequence of characters within a string.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> x = 2, y = 5, z = 1
|
||||||
|
<strong>Output:</strong> 12
|
||||||
|
<strong>Explanation: </strong>We can concactenate the strings "BB", "AA", "BB", "AA", "BB", and "AB" in that order. Then, our new string is "BBAABBAABBAB".
|
||||||
|
That string has length 12, and we can show that it is impossible to construct a string of longer length.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> x = 3, y = 2, z = 2
|
||||||
|
<strong>Output:</strong> 14
|
||||||
|
<strong>Explanation:</strong> We can concactenate the strings "AB", "AB", "AA", "BB", "AA", "BB", and "AA" in that order. Then, our new string is "ABABAABBAABBAA".
|
||||||
|
That string has length 14, and we can show that it is impossible to construct a string of longer length.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= x, y, z <= 50</code></li>
|
||||||
|
</ul>
|
46
leetcode/problem/continuous-subarrays.html
Normal file
46
leetcode/problem/continuous-subarrays.html
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A subarray of <code>nums</code> is called <strong>continuous</strong> if:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>Let <code>i</code>, <code>i + 1</code>, ..., <code>j</code><sub> </sub>be the indices in the subarray. Then, for each pair of indices <code>i <= i<sub>1</sub>, i<sub>2</sub> <= j</code>, <code><font face="monospace">0 <=</font> |nums[i<sub>1</sub>] - nums[i<sub>2</sub>]| <= 2</code>.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Return <em>the total number of <strong>continuous</strong> subarrays.</em></p>
|
||||||
|
|
||||||
|
<p>A subarray is a contiguous <strong>non-empty</strong> sequence of elements within an array.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [5,4,2,4]
|
||||||
|
<strong>Output:</strong> 8
|
||||||
|
<strong>Explanation:</strong>
|
||||||
|
Continuous subarray of size 1: [5], [4], [2], [4].
|
||||||
|
Continuous subarray of size 2: [5,4], [4,2], [2,4].
|
||||||
|
Continuous subarray of size 3: [4,2,4].
|
||||||
|
Thereare no subarrys of size 4.
|
||||||
|
Total continuous subarrays = 4 + 3 + 1 = 8.
|
||||||
|
It can be shown that there are no more continuous subarrays.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [1,2,3]
|
||||||
|
<strong>Output:</strong> 6
|
||||||
|
<strong>Explanation:</strong>
|
||||||
|
Continuous subarray of size 1: [1], [2], [3].
|
||||||
|
Continuous subarray of size 2: [1,2], [2,3].
|
||||||
|
Continuous subarray of size 3: [1,2,3].
|
||||||
|
Total continuous subarrays = 3 + 2 + 1 = 6.
|
||||||
|
</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>
|
44
leetcode/problem/count-zero-request-servers.html
Normal file
44
leetcode/problem/count-zero-request-servers.html
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<p>You are given an integer <code>n</code> denoting the total number of servers and a <strong>2D</strong> <strong>0-indexed </strong>integer array <code>logs</code>, where <code>logs[i] = [server_id, time]</code> denotes that the server with id <code>server_id</code> received a request at time <code>time</code>.</p>
|
||||||
|
|
||||||
|
<p>You are also given an integer <code>x</code> and a <strong>0-indexed</strong> integer array <code>queries</code>.</p>
|
||||||
|
|
||||||
|
<p>Return <em>a <strong>0-indexed</strong> integer array</em> <code>arr</code> <em>of length</em> <code>queries.length</code> <em>where</em> <code>arr[i]</code> <em>represents the number of servers that <strong>did not receive</strong> any requests during the time interval</em> <code>[queries[i] - x, queries[i]]</code>.</p>
|
||||||
|
|
||||||
|
<p>Note that the time intervals are inclusive.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> n = 3, logs = [[1,3],[2,6],[1,5]], x = 5, queries = [10,11]
|
||||||
|
<strong>Output:</strong> [1,2]
|
||||||
|
<strong>Explanation:</strong>
|
||||||
|
For queries[0]: The servers with ids 1 and 2 get requests in the duration of [5, 10]. Hence, only server 3 gets zero requests.
|
||||||
|
For queries[1]: Only the server with id 2 gets a request in duration of [6,11]. Hence, the servers with ids 1 and 3 are the only servers that do not receive any requests during that time period.
|
||||||
|
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> n = 3, logs = [[2,4],[2,1],[1,2],[3,1]], x = 2, queries = [3,4]
|
||||||
|
<strong>Output:</strong> [0,1]
|
||||||
|
<strong>Explanation:</strong>
|
||||||
|
For queries[0]: All servers get at least one request in the duration of [1, 3].
|
||||||
|
For queries[1]: Only server with id 3 gets no request in the duration [2,4].
|
||||||
|
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= n <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>1 <= logs.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>1 <= queries.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code><font face="monospace">logs[i].length == 2</font></code></li>
|
||||||
|
<li><code>1 <= logs[i][0] <= n</code></li>
|
||||||
|
<li><code>1 <= logs[i][1] <= 10<sup>6</sup></code></li>
|
||||||
|
<li><code>1 <= x <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>x < queries[i] <= 10<sup>6</sup></code></li>
|
||||||
|
</ul>
|
61
leetcode/problem/decremental-string-concatenation.html
Normal file
61
leetcode/problem/decremental-string-concatenation.html
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<p>You are given a <strong>0-indexed</strong> array <code>words</code> containing <code>n</code> strings.</p>
|
||||||
|
|
||||||
|
<p>Let's define a <strong>join</strong> operation <code>join(x, y)</code> between two strings <code>x</code> and <code>y</code> as concatenating them into <code>xy</code>. However, if the last character of <code>x</code> is equal to the first character of <code>y</code>, one of them is <strong>deleted</strong>.</p>
|
||||||
|
|
||||||
|
<p>For example <code>join("ab", "ba") = "aba"</code> and <code>join("ab", "cde") = "abcde"</code>.</p>
|
||||||
|
|
||||||
|
<p>You are to perform <code>n - 1</code> <strong>join</strong> operations. Let <code>str<sub>0</sub> = words[0]</code>. Starting from <code>i = 1</code> up to <code>i = n - 1</code>, for the <code>i<sup>th</sup></code> operation, you can do one of the following:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>Make <code>str<sub>i</sub> = join(str<sub>i - 1</sub>, words[i])</code></li>
|
||||||
|
<li>Make <code>str<sub>i</sub> = join(words[i], str<sub>i - 1</sub>)</code></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Your task is to <strong>minimize</strong> the length of <code>str<sub>n - 1</sub></code>.</p>
|
||||||
|
|
||||||
|
<p>Return <em>an integer denoting the minimum possible length of</em> <code>str<sub>n - 1</sub></code>.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> words = ["aa","ab","bc"]
|
||||||
|
<strong>Output:</strong> 4
|
||||||
|
<strong>Explanation: </strong>In this example, we can perform join operations in the following order to minimize the length of str<sub>2</sub>:
|
||||||
|
str<sub>0</sub> = "aa"
|
||||||
|
str<sub>1</sub> = join(str<sub>0</sub>, "ab") = "aab"
|
||||||
|
str<sub>2</sub> = join(str<sub>1</sub>, "bc") = "aabc"
|
||||||
|
It can be shown that the minimum possible length of str<sub>2</sub> is 4.</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> words = ["ab","b"]
|
||||||
|
<strong>Output:</strong> 2
|
||||||
|
<strong>Explanation:</strong> In this example, str<sub>0</sub> = "ab", there are two ways to get str<sub>1</sub>:
|
||||||
|
join(str<sub>0</sub>, "b") = "ab" or join("b", str<sub>0</sub>) = "bab".
|
||||||
|
The first string, "ab", has the minimum length. Hence, the answer is 2.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 3:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> words = ["aaa","c","aba"]
|
||||||
|
<strong>Output:</strong> 6
|
||||||
|
<strong>Explanation:</strong> In this example, we can perform join operations in the following order to minimize the length of str<sub>2</sub>:
|
||||||
|
str<sub>0</sub> = "aaa"
|
||||||
|
str<sub>1</sub> = join(str<sub>0</sub>, "c") = "aaac"
|
||||||
|
str<sub>2</sub> = join("aba", str<sub>1</sub>) = "abaaac"
|
||||||
|
It can be shown that the minimum possible length of str<sub>2</sub> is 6.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<div class="notranslate" style="all: initial;"> </div>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= words.length <= 1000</code></li>
|
||||||
|
<li><code>1 <= words[i].length <= 50</code></li>
|
||||||
|
<li>Each character in <code>words[i]</code> is an English lowercase letter</li>
|
||||||
|
</ul>
|
51
leetcode/problem/find-maximum-number-of-string-pairs.html
Normal file
51
leetcode/problem/find-maximum-number-of-string-pairs.html
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<p>You are given a <strong>0-indexed</strong> array <code>words</code> consisting of <strong>distinct</strong> strings.</p>
|
||||||
|
|
||||||
|
<p>The string <code>words[i]</code> can be paired with the string <code>words[j]</code> if:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>The string <code>words[i]</code> is equal to the reversed string of <code>words[j]</code>.</li>
|
||||||
|
<li><code>0 <= i < j < words.length</code>.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Return <em>the <strong>maximum</strong> number of pairs that can be formed from the array </em><code>words</code><em>.</em></p>
|
||||||
|
|
||||||
|
<p>Note that each string can belong in <strong>at most one</strong> pair.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> words = ["cd","ac","dc","ca","zz"]
|
||||||
|
<strong>Output:</strong> 2
|
||||||
|
<strong>Explanation:</strong> In this example, we can form 2 pair of strings in the following way:
|
||||||
|
- We pair the 0<sup>th</sup> string with the 2<sup>nd</sup> string, as the reversed string of word[0] is "dc" and is equal to words[2].
|
||||||
|
- We pair the 1<sup>st</sup> string with the 3<sup>rd</sup> string, as the reversed string of word[1] is "ca" and is equal to words[3].
|
||||||
|
It can be proven that 2 is the maximum number of pairs that can be formed.</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> words = ["ab","ba","cc"]
|
||||||
|
<strong>Output:</strong> 1
|
||||||
|
<strong>Explanation:</strong> In this example, we can form 1 pair of strings in the following way:
|
||||||
|
- We pair the 0<sup>th</sup> string with the 1<sup>st</sup> string, as the reversed string of words[1] is "ab" and is equal to words[0].
|
||||||
|
It can be proven that 1 is the maximum number of pairs that can be formed.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 3:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> words = ["aa","ab"]
|
||||||
|
<strong>Output:</strong> 0
|
||||||
|
<strong>Explanation:</strong> In this example, we are unable to form any pair of strings.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= words.length <= 50</code></li>
|
||||||
|
<li><code>words[i].length == 2</code></li>
|
||||||
|
<li><code>words</code> consists of distinct strings.</li>
|
||||||
|
<li><code>words[i]</code> contains only lowercase English letters.</li>
|
||||||
|
</ul>
|
@ -0,0 +1,50 @@
|
|||||||
|
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> and an integer <code>threshold</code>.</p>
|
||||||
|
|
||||||
|
<p>Find the length of the <strong>longest subarray</strong> of <code>nums</code> starting at index <code>l</code> and ending at index <code>r</code> <code>(0 <= l <= r < nums.length)</code> that satisfies the following conditions:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>nums[l] % 2 == 0</code></li>
|
||||||
|
<li>For all indices <code>i</code> in the range <code>[l, r - 1]</code>, <code>nums[i] % 2 != nums[i + 1] % 2</code></li>
|
||||||
|
<li>For all indices <code>i</code> in the range <code>[l, r]</code>, <code>nums[i] <= threshold</code></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Return <em>an integer denoting the length of the longest such subarray.</em></p>
|
||||||
|
|
||||||
|
<p><strong>Note:</strong> A <strong>subarray</strong> is a contiguous non-empty sequence of elements within an array.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [3,2,5,4], threshold = 5
|
||||||
|
<strong>Output:</strong> 3
|
||||||
|
<strong>Explanation:</strong> In this example, we can select the subarray that starts at l = 1 and ends at r = 3 => [2,5,4]. This subarray satisfies the conditions.
|
||||||
|
Hence, the answer is the length of the subarray, 3. We can show that 3 is the maximum possible achievable length.</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [1,2], threshold = 2
|
||||||
|
<strong>Output:</strong> 1
|
||||||
|
<strong>Explanation:</strong> In this example, we can select the subarray that starts at l = 1 and ends at r = 1 => [2].
|
||||||
|
It satisfies all the conditions and we can show that 1 is the maximum possible achievable length.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 3:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [2,3,4,5], threshold = 4
|
||||||
|
<strong>Output:</strong> 3
|
||||||
|
<strong>Explanation:</strong> In this example, we can select the subarray that starts at l = 0 and ends at r = 2 => [2,3,4].
|
||||||
|
It satisfies all the conditions.
|
||||||
|
Hence, the answer is the length of the subarray, 3. We can show that 3 is the maximum possible achievable length.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= nums.length <= 100 </code></li>
|
||||||
|
<li><code>1 <= nums[i] <= 100 </code></li>
|
||||||
|
<li><code>1 <= threshold <= 100</code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,36 @@
|
|||||||
|
<p>You are given two integers <code>num1</code> and <code>num2</code>.</p>
|
||||||
|
|
||||||
|
<p>In one operation, you can choose integer <code>i</code> in the range <code>[0, 60]</code> and subtract <code>2<sup>i</sup> + num2</code> from <code>num1</code>.</p>
|
||||||
|
|
||||||
|
<p>Return <em>the integer denoting the <strong>minimum</strong> number of operations needed to make</em> <code>num1</code> <em>equal to</em> <code>0</code>.</p>
|
||||||
|
|
||||||
|
<p>If it is impossible to make <code>num1</code> equal to <code>0</code>, return <code>-1</code>.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> num1 = 3, num2 = -2
|
||||||
|
<strong>Output:</strong> 3
|
||||||
|
<strong>Explanation:</strong> We can make 3 equal to 0 with the following operations:
|
||||||
|
- We choose i = 2 and substract 2<sup>2</sup> + (-2) from 3, 3 - (4 + (-2)) = 1.
|
||||||
|
- We choose i = 2 and substract 2<sup>2</sup> + (-2) from 1, 1 - (4 + (-2)) = -1.
|
||||||
|
- We choose i = 0 and substract 2<sup>0</sup> + (-2) from -1, (-1) - (1 + (-2)) = 0.
|
||||||
|
It can be proven, that 3 is the minimum number of operations that we need to perform.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> num1 = 5, num2 = 7
|
||||||
|
<strong>Output:</strong> -1
|
||||||
|
<strong>Explanation:</strong> It can be proven, that it is impossible to make 5 equal to 0 with the given operation.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= num1 <= 10<sup>9</sup></code></li>
|
||||||
|
<li><code><font face="monospace">-10<sup>9</sup> <= num2 <= 10<sup>9</sup></font></code></li>
|
||||||
|
</ul>
|
40
leetcode/problem/number-of-beautiful-pairs.html
Normal file
40
leetcode/problem/number-of-beautiful-pairs.html
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<p>You are given a <strong>0-indexed </strong>integer array <code>nums</code>. A pair of indices <code>i</code>, <code>j</code> where <code>0 <= i < j < nums.length</code> is called beautiful if the <strong>first digit</strong> of <code>nums[i]</code> and the <strong>last digit</strong> of <code>nums[j]</code> are <strong>coprime</strong>.</p>
|
||||||
|
|
||||||
|
<p>Return <em>the total number of beautiful pairs in </em><code>nums</code>.</p>
|
||||||
|
|
||||||
|
<p>Two integers <code>x</code> and <code>y</code> are <strong>coprime</strong> if there is no integer greater than 1 that divides both of them. In other words, <code>x</code> and <code>y</code> are coprime if <code>gcd(x, y) == 1</code>, where <code>gcd(x, y)</code> is the <strong>greatest common divisor</strong> of <code>x</code> and <code>y</code>.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [2,5,1,4]
|
||||||
|
<strong>Output:</strong> 5
|
||||||
|
<strong>Explanation:</strong> There are 5 beautiful pairs in nums:
|
||||||
|
When i = 0 and j = 1: the first digit of nums[0] is 2, and the last digit of nums[1] is 5. We can confirm that 2 and 5 are coprime, since gcd(2,5) == 1.
|
||||||
|
When i = 0 and j = 2: the first digit of nums[0] is 2, and the last digit of nums[2] is 1. Indeed, gcd(2,1) == 1.
|
||||||
|
When i = 1 and j = 2: the first digit of nums[1] is 5, and the last digit of nums[2] is 1. Indeed, gcd(5,1) == 1.
|
||||||
|
When i = 1 and j = 3: the first digit of nums[1] is 5, and the last digit of nums[3] is 4. Indeed, gcd(5,4) == 1.
|
||||||
|
When i = 2 and j = 3: the first digit of nums[2] is 1, and the last digit of nums[3] is 4. Indeed, gcd(1,4) == 1.
|
||||||
|
Thus, we return 5.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [11,21,12]
|
||||||
|
<strong>Output:</strong> 2
|
||||||
|
<strong>Explanation:</strong> There are 2 beautiful pairs:
|
||||||
|
When i = 0 and j = 1: the first digit of nums[0] is 1, and the last digit of nums[1] is 1. Indeed, gcd(1,1) == 1.
|
||||||
|
When i = 0 and j = 2: the first digit of nums[0] is 1, and the last digit of nums[2] is 2. Indeed, gcd(1,2) == 1.
|
||||||
|
Thus, we return 2.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>2 <= nums.length <= 100</code></li>
|
||||||
|
<li><code>1 <= nums[i] <= 9999</code></li>
|
||||||
|
<li><code>nums[i] % 10 != 0</code></li>
|
||||||
|
</ul>
|
36
leetcode/problem/prime-pairs-with-target-sum.html
Normal file
36
leetcode/problem/prime-pairs-with-target-sum.html
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<p>You are given an integer <code>n</code>. We say that two integers <code>x</code> and <code>y</code> form a prime number pair if:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= x <= y <= n</code></li>
|
||||||
|
<li><code>x + y == n</code></li>
|
||||||
|
<li><code>x</code> and <code>y</code> are prime numbers</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Return <em>the 2D sorted list of prime number pairs</em> <code>[x<sub>i</sub>, y<sub>i</sub>]</code>. The list should be sorted in <strong>increasing</strong> order of <code>x<sub>i</sub></code>. If there are no prime number pairs at all, return <em>an empty array</em>.</p>
|
||||||
|
|
||||||
|
<p><strong>Note:</strong> A prime number is a natural number greater than <code>1</code> with only two factors, itself and <code>1</code>.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> n = 10
|
||||||
|
<strong>Output:</strong> [[3,7],[5,5]]
|
||||||
|
<strong>Explanation:</strong> In this example, there are two prime pairs that satisfy the criteria.
|
||||||
|
These pairs are [3,7] and [5,5], and we return them in the sorted order as described in the problem statement.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> n = 2
|
||||||
|
<strong>Output:</strong> []
|
||||||
|
<strong>Explanation:</strong> We can show that there is no prime number pair that gives a sum of 2, so we return an empty array.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= n <= 10<sup>6</sup></code></li>
|
||||||
|
</ul>
|
55
leetcode/problem/robot-collisions.html
Normal file
55
leetcode/problem/robot-collisions.html
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<p>There are <code>n</code> <strong>1-indexed</strong> robots, each having a position on a line, health, and movement direction.</p>
|
||||||
|
|
||||||
|
<p>You are given <strong>0-indexed</strong> integer arrays <code>positions</code>, <code>healths</code>, and a string <code>directions</code> (<code>directions[i]</code> is either <strong>'L'</strong> for <strong>left</strong> or <strong>'R'</strong> for <strong>right</strong>). All integers in <code>positions</code> are <strong>unique</strong>.</p>
|
||||||
|
|
||||||
|
<p>All robots start moving on the line<strong> simultaneously</strong> at the <strong>same speed </strong>in their given directions. If two robots ever share the same position while moving, they will <strong>collide</strong>.</p>
|
||||||
|
|
||||||
|
<p>If two robots collide, the robot with <strong>lower health</strong> is <strong>removed</strong> from the line, and the health of the other robot <strong>decreases</strong> <strong>by one</strong>. The surviving robot continues in the <strong>same</strong> direction it was going. If both robots have the <strong>same</strong> health, they are both<strong> </strong>removed from the line.</p>
|
||||||
|
|
||||||
|
<p>Your task is to determine the <strong>health</strong> of the robots that survive the collisions, in the same <strong>order </strong>that the robots were given,<strong> </strong>i.e. final heath of robot 1 (if survived), final health of robot 2 (if survived), and so on. If there are no survivors, return an empty array.</p>
|
||||||
|
|
||||||
|
<p>Return <em>an array containing the health of the remaining robots (in the order they were given in the input), after no further collisions can occur.</em></p>
|
||||||
|
|
||||||
|
<p><strong>Note:</strong> The positions may be unsorted.</p>
|
||||||
|
|
||||||
|
<div class="notranslate" style="all: initial;"> </div>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<p><img height="169" src="https://assets.leetcode.com/uploads/2023/05/15/image-20230516011718-12.png" width="808" /></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> positions = [5,4,3,2,1], healths = [2,17,9,15,10], directions = "RRRRR"
|
||||||
|
<strong>Output:</strong> [2,17,9,15,10]
|
||||||
|
<strong>Explanation:</strong> No collision occurs in this example, since all robots are moving in the same direction. So, the health of the robots in order from the first robot is returned, [2, 17, 9, 15, 10].
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<p><img height="176" src="https://assets.leetcode.com/uploads/2023/05/15/image-20230516004433-7.png" width="717" /></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> positions = [3,5,2,6], healths = [10,10,15,12], directions = "RLRL"
|
||||||
|
<strong>Output:</strong> [14]
|
||||||
|
<strong>Explanation:</strong> There are 2 collisions in this example. Firstly, robot 1 and robot 2 will collide, and since both have the same health, they will be removed from the line. Next, robot 3 and robot 4 will collide and since robot 4's health is smaller, it gets removed, and robot 3's health becomes 15 - 1 = 14. Only robot 3 remains, so we return [14].
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 3:</strong></p>
|
||||||
|
|
||||||
|
<p><img height="172" src="https://assets.leetcode.com/uploads/2023/05/15/image-20230516005114-9.png" width="732" /></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> positions = [1,2,5,6], healths = [10,10,11,11], directions = "RLRL"
|
||||||
|
<strong>Output:</strong> []
|
||||||
|
<strong>Explanation:</strong> Robot 1 and robot 2 will collide and since both have the same health, they are both removed. Robot 3 and 4 will collide and since both have the same health, they are both removed. So, we return an empty array, [].</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= positions.length == healths.length == directions.length == n <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>1 <= positions[i], healths[i] <= 10<sup>9</sup></code></li>
|
||||||
|
<li><code>directions[i] == 'L'</code> or <code>directions[i] == 'R'</code></li>
|
||||||
|
<li>All values in <code>positions</code> are distinct</li>
|
||||||
|
</ul>
|
@ -0,0 +1,48 @@
|
|||||||
|
<p>The <strong>imbalance number</strong> of a <strong>0-indexed</strong> integer array <code>arr</code> of length <code>n</code> is defined as the number of indices in <code>sarr = sorted(arr)</code> such that:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>0 <= i < n - 1</code>, and</li>
|
||||||
|
<li><code>sarr[i+1] - sarr[i] > 1</code></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Here, <code>sorted(arr)</code> is the function that returns the sorted version of <code>arr</code>.</p>
|
||||||
|
|
||||||
|
<p>Given a <strong>0-indexed</strong> integer array <code>nums</code>, return <em>the <strong>sum of imbalance numbers</strong> of all its <strong>subarrays</strong></em>.</p>
|
||||||
|
|
||||||
|
<p>A <strong>subarray</strong> is a contiguous <strong>non-empty</strong> sequence of elements within an array.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [2,3,1,4]
|
||||||
|
<strong>Output:</strong> 3
|
||||||
|
<strong>Explanation:</strong> There are 3 subarrays with non-zero<strong> </strong>imbalance numbers:
|
||||||
|
- Subarray [3, 1] with an imbalance number of 1.
|
||||||
|
- Subarray [3, 1, 4] with an imbalance number of 1.
|
||||||
|
- Subarray [1, 4] with an imbalance number of 1.
|
||||||
|
The imbalance number of all other subarrays is 0. Hence, the sum of imbalance numbers of all the subarrays of nums is 3.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [1,3,3,3,5]
|
||||||
|
<strong>Output:</strong> 8
|
||||||
|
<strong>Explanation:</strong> There are 7 subarrays with non-zero imbalance numbers:
|
||||||
|
- Subarray [1, 3] with an imbalance number of 1.
|
||||||
|
- Subarray [1, 3, 3] with an imbalance number of 1.
|
||||||
|
- Subarray [1, 3, 3, 3] with an imbalance number of 1.
|
||||||
|
- Subarray [1, 3, 3, 3, 5] with an imbalance number of 2.
|
||||||
|
- Subarray [3, 3, 3, 5] with an imbalance number of 1.
|
||||||
|
- Subarray [3, 3, 5] with an imbalance number of 1.
|
||||||
|
- Subarray [3, 5] with an imbalance number of 1.
|
||||||
|
The imbalance number of all other subarrays is 0. Hence, the sum of imbalance numbers of all the subarrays of nums is 8. </pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= nums.length <= 1000</code></li>
|
||||||
|
<li><code>1 <= nums[i] <= nums.length</code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,36 @@
|
|||||||
|
<p>You are given a binary array <code>nums</code>.</p>
|
||||||
|
|
||||||
|
<p>A subarray of an array is <strong>good</strong> if it contains <strong>exactly</strong> <strong>one</strong> element with the value <code>1</code>.</p>
|
||||||
|
|
||||||
|
<p>Return <em>an integer denoting the number of ways to split the array </em><code>nums</code><em> into <strong>good</strong> subarrays</em>. As the number may be too large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
|
||||||
|
|
||||||
|
<p>A subarray is a contiguous <strong>non-empty</strong> sequence of elements within an array.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [0,1,0,0,1]
|
||||||
|
<strong>Output:</strong> 3
|
||||||
|
<strong>Explanation:</strong> There are 3 ways to split nums into good subarrays:
|
||||||
|
- [0,1] [0,0,1]
|
||||||
|
- [0,1,0] [0,1]
|
||||||
|
- [0,1,0,0] [1]
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [0,1,0]
|
||||||
|
<strong>Output:</strong> 1
|
||||||
|
<strong>Explanation:</strong> There is 1 way to split nums into good subarrays:
|
||||||
|
- [0,1,0]
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>0 <= nums[i] <= 1</code></li>
|
||||||
|
</ul>
|
Loading…
Reference in New Issue
Block a user