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
25bf8d9df8
commit
4baa9b5a57
@ -1,6 +1,6 @@
|
||||
# 力扣题库(完整版)
|
||||
|
||||
> 最后更新日期: **2023.07.03**
|
||||
> 最后更新日期: **2023.07.16**
|
||||
>
|
||||
> 使用脚本前请务必仔细完整阅读本 `README.md` 文件
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
50
leetcode-cn/originData/[no content]array-upper-bound.json
Normal file
50
leetcode-cn/originData/[no content]array-upper-bound.json
Normal file
@ -0,0 +1,50 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2768",
|
||||
"questionFrontendId": "2774",
|
||||
"categoryTitle": "JavaScript",
|
||||
"boundTopicId": 2341825,
|
||||
"title": "Array Upper Bound",
|
||||
"titleSlug": "array-upper-bound",
|
||||
"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\": \"15\", \"totalSubmission\": \"19\", \"totalAcceptedRaw\": 15, \"totalSubmissionRaw\": 19, \"acRate\": \"78.9%\"}",
|
||||
"hints": [
|
||||
"Inside the Array.prototype.upperBound function you have access to the \"this\" keyword. You can access array elements, values, and methods. For example \"this[0]\", \"this[1]\", \"this.length\", \"this.map()\", etc.",
|
||||
"The most efficient way to solve this problem is with binary search.",
|
||||
"Choose the middle element and check if it's less than or equal to the goal value. If so, you can rule out the left side of the array."
|
||||
],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "[3,4,5]\n5",
|
||||
"metaData": "{\n \"name\": \"upperBound\",\n \"params\": [\n {\n \"name\": \"nums\",\n \"type\": \"integer[]\"\n },\n {\n \"type\": \"integer\",\n \"name\": \"target\"\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 5.1.6<\\/p>\\r\\n\\r\\n<p>Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2022<\\/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": "[3,4,5]\n5\n[1,4,5]\n2\n[3,4,6,6,6,6,7]\n6",
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2782",
|
||||
"questionFrontendId": "2776",
|
||||
"categoryTitle": "JavaScript",
|
||||
"boundTopicId": 2341829,
|
||||
"title": "Convert Callback Based Function to Promise Based Function",
|
||||
"titleSlug": "convert-callback-based-function-to-promise-based-function",
|
||||
"content": null,
|
||||
"translatedTitle": "转换回调函数为 Promise 函数",
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Medium",
|
||||
"likes": 0,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"contributors": [],
|
||||
"langToValidPlayground": null,
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"8\", \"totalSubmission\": \"10\", \"totalAcceptedRaw\": 8, \"totalSubmissionRaw\": 10, \"acRate\": \"80.0%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "(callback, a, b, c) => callback(a * b * c)\n[1, 2, 3]",
|
||||
"metaData": "{\n \"name\": \"foobar\",\n \"params\": [\n {\n \"name\": \"fn\",\n \"type\": \"string\"\n },\n {\n \"type\": \"integer[][]\",\n \"name\": \"args\"\n }\n ],\n \"return\": {\n \"type\": \"integer\"\n },\n \"manual\": true,\n \"languages\": [\n \"javascript\",\n \"typescript\"\n ]\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 5.1.6<\\/p>\\r\\n\\r\\n<p>Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2022<\\/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": "(callback, a, b, c) => callback(a * b * c)\n[1, 2, 3]\n(callback, a, b, c) => callback(a * b * c, \"Promise Rejected\")\n[4, 5, 6]",
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
46
leetcode-cn/originData/[no content]date-range-generator.json
Normal file
46
leetcode-cn/originData/[no content]date-range-generator.json
Normal file
@ -0,0 +1,46 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2799",
|
||||
"questionFrontendId": "2777",
|
||||
"categoryTitle": "JavaScript",
|
||||
"boundTopicId": 2341830,
|
||||
"title": "Date Range Generator",
|
||||
"titleSlug": "date-range-generator",
|
||||
"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\": \"6\", \"totalSubmission\": \"6\", \"totalAcceptedRaw\": 6, \"totalSubmissionRaw\": 6, \"acRate\": \"100.0%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "\"2023-04-01\"\n\"2023-04-04\"\n1",
|
||||
"metaData": "{\n \"name\": \"dateRangeGenerator\",\n \"params\": [\n {\n \"name\": \"start\",\n \"type\": \"integer\"\n },\n {\n \"type\": \"integer\",\n \"name\": \"end\"\n },\n {\n \"type\": \"integer\",\n \"name\": \"step\"\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 5.1.6<\\/p>\\r\\n\\r\\n<p>Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2022<\\/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": "\"2023-04-01\"\n\"2023-04-04\"\n1\n\"2023-04-10\"\n\"2023-04-20\"\n3\n\"2023-04-10\"\n\"2023-04-10\"\n1",
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
46
leetcode-cn/originData/[no content]undefined-to-null.json
Normal file
46
leetcode-cn/originData/[no content]undefined-to-null.json
Normal file
@ -0,0 +1,46 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2781",
|
||||
"questionFrontendId": "2775",
|
||||
"categoryTitle": "JavaScript",
|
||||
"boundTopicId": 2341828,
|
||||
"title": "Undefined to Null",
|
||||
"titleSlug": "undefined-to-null",
|
||||
"content": null,
|
||||
"translatedTitle": "将 undefined 转为 null",
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Medium",
|
||||
"likes": 0,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"contributors": [],
|
||||
"langToValidPlayground": null,
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"16\", \"totalSubmission\": \"31\", \"totalAcceptedRaw\": 16, \"totalSubmissionRaw\": 31, \"acRate\": \"51.6%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"a\": undefined, \"b\":3}",
|
||||
"metaData": "{\n \"name\": \"undefinedToNull\",\n \"params\": [\n {\n \"name\": \"obj\",\n \"type\": \"string\"\n }\n ],\n \"return\": {\n \"type\": \"string\"\n },\n \"languages\": [\n \"javascript\",\n \"typescript\"\n ],\n \"manual\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [],
|
||||
"enableRunCode": true,
|
||||
"envInfo": "{\"javascript\":[\"JavaScript\",\"<p>\\u7248\\u672c\\uff1a<code>Node.js 16.13.2<\\/code><\\/p>\\r\\n\\r\\n<p>\\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a <code>--harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f <a href=\\\"http:\\/\\/node.green\\/\\\" target=\\\"_blank\\\">\\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"],\"typescript\":[\"TypeScript\",\"<p>TypeScript 5.1.6<\\/p>\\r\\n\\r\\n<p>Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2022<\\/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\": undefined, \"b\":3}\n{\"a\": undefined, \"b\":[\"a\", undefined]}",
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
170
leetcode-cn/originData/find-the-maximum-achievable-number.json
Normal file
170
leetcode-cn/originData/find-the-maximum-achievable-number.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
176
leetcode-cn/originData/longest-alternating-subarray.json
Normal file
176
leetcode-cn/originData/longest-alternating-subarray.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
File diff suppressed because one or more lines are too long
164
leetcode-cn/originData/minimum-index-of-a-valid-split.json
Normal file
164
leetcode-cn/originData/minimum-index-of-a-valid-split.json
Normal file
File diff suppressed because one or more lines are too long
185
leetcode-cn/originData/number-of-black-blocks.json
Normal file
185
leetcode-cn/originData/number-of-black-blocks.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
189
leetcode-cn/originData/relocate-marbles.json
Normal file
189
leetcode-cn/originData/relocate-marbles.json
Normal file
File diff suppressed because one or more lines are too long
164
leetcode-cn/originData/sum-of-squares-of-special-elements.json
Normal file
164
leetcode-cn/originData/sum-of-squares-of-special-elements.json
Normal file
File diff suppressed because one or more lines are too long
@ -0,0 +1,39 @@
|
||||
<p>给你一个下标从 <strong>0</strong> 开始的整数数组 <code>nums</code> 和一个正整数 <code>k</code> 。</p>
|
||||
|
||||
<p>你可以对数组执行下述操作 <strong>任意次</strong> :</p>
|
||||
|
||||
<ul>
|
||||
<li>从数组中选出长度为 <code>k</code> 的 <strong>任一</strong> 子数组,并将子数组中每个元素都 <strong>减去</strong> <code>1</code> 。</li>
|
||||
</ul>
|
||||
|
||||
<p>如果你可以使数组中的所有元素都等于 <code>0</code> ,返回 <code>true</code><em> </em>;否则,返回<em> </em><code>false</code><em> </em>。</p>
|
||||
|
||||
<p><strong>子数组</strong> 是数组中的一个非空连续元素序列。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>nums = [2,2,3,1,1,0], k = 3
|
||||
<strong>输出:</strong>true
|
||||
<strong>解释:</strong>可以执行下述操作:
|
||||
- 选出子数组 [2,2,3] ,执行操作后,数组变为 nums = [<em><strong>1</strong></em>,<em><strong>1</strong></em>,<em><strong>2</strong></em>,1,1,0] 。
|
||||
- 选出子数组 [2,1,1] ,执行操作后,数组变为 nums = [1,1,<em><strong>1</strong></em>,<em><strong>0</strong></em>,<em><strong>0</strong></em>,0] 。
|
||||
- 选出子数组 [1,1,1] ,执行操作后,数组变为 nums = [<em><strong>0</strong></em>,<em><strong>0</strong></em>,<em><strong>0</strong></em>,0,0,0] 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>nums = [1,3,1,1], k = 2
|
||||
<strong>输出:</strong>false
|
||||
<strong>解释:</strong>无法使数组中的所有元素等于 0 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= k <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>0 <= nums[i] <= 10<sup>6</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,53 @@
|
||||
<p>如果元素 <code>x</code> 在长度为 <code>m</code> 的整数数组 <code>arr</code> 中满足 <code>freq(x) * 2 > m</code> ,那么我们称 <code>x</code> 是 <strong>支配元素</strong> 。其中 <code>freq(x)</code> 是 <code>x</code> 在数组 <code>arr</code> 中出现的次数。注意,根据这个定义,数组 <code>arr</code> <strong>最多</strong> 只会有 <strong>一个</strong> 支配元素。</p>
|
||||
|
||||
<p>给你一个下标从 <strong>0</strong> 开始长度为 <code>n</code> 的整数数组 <code>nums</code> ,数据保证它含有一个支配元素。</p>
|
||||
|
||||
<p>你需要在下标 <code>i</code> 处将 <code>nums</code> 分割成两个数组 <code>nums[0, ..., i]</code> 和 <code>nums[i + 1, ..., n - 1]</code> ,如果一个分割满足以下条件,我们称它是 <strong>合法</strong> 的:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= i < n - 1</code></li>
|
||||
<li><code>nums[0, ..., i]</code> 和 <code>nums[i + 1, ..., n - 1]</code> 的支配元素相同。</li>
|
||||
</ul>
|
||||
|
||||
<p>这里, <code>nums[i, ..., j]</code> 表示 <code>nums</code> 的一个子数组,它开始于下标 <code>i</code> ,结束于下标 <code>j</code> ,两个端点都包含在子数组内。特别地,如果 <code>j < i</code> ,那么 <code>nums[i, ..., j]</code> 表示一个空数组。</p>
|
||||
|
||||
<p>请你返回一个 <strong>合法分割</strong> 的 <strong>最小</strong> 下标。如果合法分割不存在,返回 <code>-1</code> 。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>nums = [1,2,2,2]
|
||||
<b>输出:</b>2
|
||||
<b>解释:</b>我们将数组在下标 2 处分割,得到 [1,2,2] 和 [2] 。
|
||||
数组 [1,2,2] 中,元素 2 是支配元素,因为它在数组中出现了 2 次,且 2 * 2 > 3 。
|
||||
数组 [2] 中,元素 2 是支配元素,因为它在数组中出现了 1 次,且 1 * 2 > 1 。
|
||||
两个数组 [1,2,2] 和 [2] 都有与 nums 一样的支配元素,所以这是一个合法分割。
|
||||
下标 2 是合法分割中的最小下标。</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>nums = [2,1,3,1,1,1,7,1,2,1]
|
||||
<b>输出:</b>4
|
||||
<b>解释:</b>我们将数组在下标 4 处分割,得到 [2,1,3,1,1] 和 [1,7,1,2,1] 。
|
||||
数组 [2,1,3,1,1] 中,元素 1 是支配元素,因为它在数组中出现了 3 次,且 3 * 2 > 5 。
|
||||
数组 [1,7,1,2,1] 中,元素 1 是支配元素,因为它在数组中出现了 3 次,且 3 * 2 > 5 。
|
||||
两个数组 [2,1,3,1,1] 和 [1,7,1,2,1] 都有与 nums 一样的支配元素,所以这是一个合法分割。
|
||||
下标 4 是所有合法分割中的最小下标。</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>nums = [3,3,3,3,7,2,2]
|
||||
<b>输出:</b>-1
|
||||
<b>解释:</b>没有合法分割。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>
|
||||
<li><code>nums</code> 有且只有一个支配元素。</li>
|
||||
</ul>
|
@ -0,0 +1,49 @@
|
||||
<p>给你一个二进制字符串 <code>s</code> ,你需要将字符串分割成一个或者多个 <strong>子字符串</strong> ,使每个子字符串都是 <strong>美丽</strong> 的。</p>
|
||||
|
||||
<p>如果一个字符串满足以下条件,我们称它是 <strong>美丽</strong> 的:</p>
|
||||
|
||||
<ul>
|
||||
<li>它不包含前导 0 。</li>
|
||||
<li>它是 <code>5</code> 的幂的 <strong>二进制</strong> 表示。</li>
|
||||
</ul>
|
||||
|
||||
<p>请你返回分割后的子字符串的 <strong>最少</strong> 数目。如果无法将字符串 <code>s</code> 分割成美丽子字符串,请你返回 <code>-1</code> 。</p>
|
||||
|
||||
<p>子字符串是一个字符串中一段连续的字符序列。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>s = "1011"
|
||||
<b>输出:</b>2
|
||||
<b>解释:</b>我们可以将输入字符串分成 ["101", "1"] 。
|
||||
- 字符串 "101" 不包含前导 0 ,且它是整数 5<sup>1</sup> = 5 的二进制表示。
|
||||
- 字符串 "1" 不包含前导 0 ,且它是整数 5<sup>0</sup> = 1 的二进制表示。
|
||||
最少可以将 s 分成 2 个美丽子字符串。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>s = "111"
|
||||
<b>输出:</b>3
|
||||
<b>解释:</b>我们可以将输入字符串分成 ["1", "1", "1"] 。
|
||||
- 字符串 "1" 不包含前导 0 ,且它是整数 5<sup>0</sup> = 1 的二进制表示。
|
||||
最少可以将 s 分成 3 个美丽子字符串。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>s = "0"
|
||||
<b>输出:</b>-1
|
||||
<b>解释:</b>无法将给定字符串分成任何美丽子字符串。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= s.length <= 15</code></li>
|
||||
<li><code>s[i]</code> 要么是 <code>'0'</code> 要么是 <code>'1'</code> 。</li>
|
||||
</ul>
|
@ -0,0 +1,38 @@
|
||||
<p>给你两个整数 <code>num</code> 和 <code>t</code> 。</p>
|
||||
|
||||
<p>如果整数 <code>x</code> 可以在执行下述操作不超过 <code>t</code> 次的情况下变为与 <code>num</code> 相等,则称其为 <strong>可达成数字</strong> :</p>
|
||||
|
||||
<ul>
|
||||
<li>每次操作将 <code>x</code> 的值增加或减少 <code>1</code> ,同时可以选择将 <code>num</code> 的值增加或减少 <code>1</code> 。</li>
|
||||
</ul>
|
||||
|
||||
<p>返回所有可达成数字中的最大值。可以证明至少存在一个可达成数字。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>num = 4, t = 1
|
||||
<strong>输出:</strong>6
|
||||
<strong>解释:</strong>最大可达成数字是 x = 6 ,执行下述操作可以使其等于 num :
|
||||
- x 减少 1 ,同时 num 增加 1 。此时,x = 5 且 num = 5 。
|
||||
可以证明不存在大于 6 的可达成数字。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>num = 3, t = 2
|
||||
<strong>输出:</strong>7
|
||||
<strong>解释:</strong>最大的可达成数字是 x = 7 ,执行下述操作可以使其等于 num :
|
||||
- x 减少 1 ,同时 num 增加 1 。此时,x = 6 且 num = 4 。
|
||||
- x 减少 1 ,同时 num 增加 1 。此时,x = 5 且 num = 5 。
|
||||
可以证明不存在大于 7 的可达成数字。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= num, t <= 50</code></li>
|
||||
</ul>
|
@ -0,0 +1,48 @@
|
||||
<p>给你一个下标从 <strong>0</strong> 开始的整数数组 <code>nums</code> 和一个 <strong>非负</strong> 整数 <code>k</code> 。</p>
|
||||
|
||||
<p>在一步操作中,你可以执行下述指令:</p>
|
||||
|
||||
<ul>
|
||||
<li>在范围 <code>[0, nums.length - 1]</code> 中选择一个 <strong>此前没有选过</strong> 的下标 <code>i</code> 。</li>
|
||||
<li>将 <code>nums[i]</code> 替换为范围 <code>[nums[i] - k, nums[i] + k]</code> 内的任一整数。</li>
|
||||
</ul>
|
||||
|
||||
<p>数组的 <strong>美丽值</strong> 定义为数组中由相等元素组成的最长子序列的长度。</p>
|
||||
|
||||
<p>对数组 <code>nums</code> 执行上述操作任意次后,返回数组可能取得的 <strong>最大</strong> 美丽值。</p>
|
||||
|
||||
<p><strong>注意:</strong>你 <strong>只</strong> 能对每个下标执行 <strong>一次</strong> 此操作。</p>
|
||||
|
||||
<p>数组的 <strong>子序列</strong> 定义是:经由原数组删除一些元素(也可能不删除)得到的一个新数组,且在此过程中剩余元素的顺序不发生改变。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>nums = [4,6,1,2], k = 2
|
||||
<strong>输出:</strong>3
|
||||
<strong>解释:</strong>在这个示例中,我们执行下述操作:
|
||||
- 选择下标 1 ,将其替换为 4(从范围 [4,8] 中选出),此时 nums = [4,4,1,2] 。
|
||||
- 选择下标 3 ,将其替换为 4(从范围 [0,4] 中选出),此时 nums = [4,4,1,4] 。
|
||||
执行上述操作后,数组的美丽值是 3(子序列由下标 0 、1 、3 对应的元素组成)。
|
||||
可以证明 3 是我们可以得到的由相等元素组成的最长子序列长度。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>nums = [1,1,1,1], k = 10
|
||||
<strong>输出:</strong>4
|
||||
<strong>解释:</strong>在这个示例中,我们无需执行任何操作。
|
||||
数组 nums 的美丽值是 4(整个数组)。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>0 <= nums[i], k <= 10<sup>5</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,38 @@
|
||||
<p>给你一个下标从 <strong>0</strong> 开始的整数数组 <code>nums</code> 。如果 <code>nums</code> 中长度为 <code>m</code> 的子数组 <code>s</code> 满足以下条件,我们称它是一个 <strong>交替子序列</strong> :</p>
|
||||
|
||||
<ul>
|
||||
<li><code>m</code> 大于 <code>1</code> 。</li>
|
||||
<li><code>s<sub>1</sub> = s<sub>0</sub> + 1</code> 。</li>
|
||||
<li>下标从 <strong>0</strong> 开始的子数组 <code>s</code> 与数组 <code>[s<sub>0</sub>, s<sub>1</sub>, s<sub>0</sub>, s<sub>1</sub>,...,s<sub>(m-1) % 2</sub>]</code> 一样。也就是说,<code>s<sub>1</sub> - s<sub>0</sub> = 1</code> ,<code>s<sub>2</sub> - s<sub>1</sub> = -1</code> ,<code>s<sub>3</sub> - s<sub>2</sub> = 1</code> ,<code>s<sub>4</sub> - s<sub>3</sub> = -1</code> ,以此类推,直到 <code>s[m - 1] - s[m - 2] = (-1)<sup>m</sup></code> 。</li>
|
||||
</ul>
|
||||
|
||||
<p>请你返回 <code>nums</code> 中所有 <strong>交替</strong> 子数组中,最长的长度,如果不存在交替子数组,请你返回 <code>-1</code> 。</p>
|
||||
|
||||
<p>子数组是一个数组中一段连续 <strong>非空</strong> 的元素序列。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>nums = [2,3,4,3,4]
|
||||
<b>输出:</b>4
|
||||
<b>解释:</b>交替子数组有 [3,4] ,[3,4,3] 和 [3,4,3,4] 。最长的子数组为 [3,4,3,4] ,长度为4 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>nums = [4,5,6]
|
||||
<b>输出:</b>2
|
||||
<strong>解释:</strong>[4,5] 和 [5,6] 是仅有的两个交替子数组。它们长度都为 2 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= nums.length <= 100</code></li>
|
||||
<li><code>1 <= nums[i] <= 10<sup>4</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,36 @@
|
||||
<p>给你一个字符串 <code>word</code> 和一个字符串数组 <code>forbidden</code> 。</p>
|
||||
|
||||
<p>如果一个字符串不包含 <code>forbidden</code> 中的任何字符串,我们称这个字符串是 <strong>合法</strong> 的。</p>
|
||||
|
||||
<p>请你返回字符串 <code>word</code> 的一个 <strong>最长合法子字符串</strong> 的长度。</p>
|
||||
|
||||
<p><strong>子字符串</strong> 指的是一个字符串中一段连续的字符,它可以为空。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>word = "cbaaaabc", forbidden = ["aaa","cb"]
|
||||
<b>输出:</b>4
|
||||
<b>解释:</b>总共有 9 个合法子字符串:"c" ,"b" ,"a" ,"ba" ,"aa" ,"bc" ,"baa" ,"aab" 和 "aabc" 。最长合法子字符串的长度为 4 。
|
||||
其他子字符串都要么包含 "aaa" ,要么包含 "cb" 。</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>word = "leetcode", forbidden = ["de","le","e"]
|
||||
<strong>输出:</strong>4
|
||||
<b>解释:</b>总共有 11 个合法子字符串:"l" ,"t" ,"c" ,"o" ,"d" ,"tc" ,"co" ,"od" ,"tco" ,"cod" 和 "tcod" 。最长合法子字符串的长度为 4 。
|
||||
所有其他子字符串都至少包含 "de" ,"le" 和 "e" 之一。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= word.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>word</code> 只包含小写英文字母。</li>
|
||||
<li><code>1 <= forbidden.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= forbidden[i].length <= 10</code></li>
|
||||
<li><code>forbidden[i]</code> 只包含小写英文字母。</li>
|
||||
</ul>
|
@ -0,0 +1,47 @@
|
||||
<p>给你两个下标从 <strong>0</strong> 开始的整数数组 <code>nums1</code> 和 <code>nums2</code> ,长度均为 <code>n</code> 。</p>
|
||||
|
||||
<p>让我们定义另一个下标从 <strong>0</strong> 开始、长度为 <code>n</code> 的整数数组,<code>nums3</code> 。对于范围 <code>[0, n - 1]</code> 的每个下标 <code>i</code> ,你可以将 <code>nums1[i]</code> 或 <code>nums2[i]</code> 的值赋给 <code>nums3[i]</code> 。</p>
|
||||
|
||||
<p>你的任务是使用最优策略为 <code>nums3</code> 赋值,以最大化 <code>nums3</code> 中 <strong>最长非递减子数组</strong> 的长度。</p>
|
||||
|
||||
<p>以整数形式表示并返回 <code>nums3</code> 中 <strong>最长非递减</strong> 子数组的长度。</p>
|
||||
|
||||
<p><strong>注意:子数组</strong> 是数组中的一个连续非空元素序列。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>nums1 = [2,3,1], nums2 = [1,2,1]
|
||||
<strong>输出:</strong>2
|
||||
<strong>解释:</strong>构造 nums3 的方法之一是:
|
||||
nums3 = [nums1[0], nums2[1], nums2[2]] => [2,2,1]
|
||||
从下标 0 开始到下标 1 结束,形成了一个长度为 2 的非递减子数组 [2,2] 。
|
||||
可以证明 2 是可达到的最大长度。</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>nums1 = [1,3,2,1], nums2 = [2,2,3,4]
|
||||
<strong>输出:</strong>4
|
||||
<strong>解释:</strong>构造 nums3 的方法之一是:
|
||||
nums3 = [nums1[0], nums2[1], nums2[2], nums2[3]] => [1,2,3,4]
|
||||
整个数组形成了一个长度为 4 的非递减子数组,并且是可达到的最大长度。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>nums1 = [1,1], nums2 = [2,2]
|
||||
<strong>输出:</strong>2
|
||||
<strong>解释:</strong>构造 nums3 的方法之一是:
|
||||
nums3 = [nums1[0], nums1[1]] => [1,1]
|
||||
整个数组形成了一个长度为 2 的非递减子数组,并且是可达到的最大长度。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums1.length == nums2.length == n <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= nums1[i], nums2[i] <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,31 @@
|
||||
<p>给你一个下标从 <strong>1</strong> 开始、长度为 <code>n</code> 的整数数组 <code>nums</code> 。</p>
|
||||
|
||||
<p>对 <code>nums</code> 中的元素 <code>nums[i]</code> 而言,如果 <code>n</code> 能够被 <code>i</code> 整除,即 <code>n % i == 0</code> ,则认为 <code>num[i]</code> 是一个 <strong>特殊元素</strong> 。</p>
|
||||
|
||||
<p>返回 <code>nums</code> 中所有 <strong>特殊元素</strong> 的 <strong>平方和</strong> 。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>nums = [1,2,3,4]
|
||||
<strong>输出:</strong>21
|
||||
<strong>解释:</strong>nums 中共有 3 个特殊元素:nums[1] ,因为 4 被 1 整除;nums[2] ,因为 4 被 2 整除;以及 nums[4] ,因为 4 被 4 整除。
|
||||
因此,nums 中所有元素的平方和等于 nums[1] * nums[1] + nums[2] * nums[2] + nums[4] * nums[4] = 1 * 1 + 2 * 2 + 4 * 4 = 21 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>nums = [2,7,1,19,18,3]
|
||||
<strong>输出:</strong>63
|
||||
<strong>解释:</strong>nums 中共有 4 个特殊元素:nums[1] ,因为 6 被 1 整除;nums[2] ,因为 6 被 2 整除;nums[3] ,因为 6 被 3 整除;以及 nums[6] ,因为 6 被 6 整除。
|
||||
因此,nums 中所有元素的平方和等于 nums[1] * nums[1] + nums[2] * nums[2] + nums[3] * nums[3] + nums[6] * nums[6] = 2 * 2 + 7 * 7 + 1 * 1 + 3 * 3 = 63 。 </pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length == n <= 50</code></li>
|
||||
<li><code>1 <= nums[i] <= 50</code></li>
|
||||
</ul>
|
@ -0,0 +1,53 @@
|
||||
<p>给你一个下标从 <strong>0</strong> 开始、由 <code>n</code> 个整数组成的数组 <code>nums</code> 和一个整数 <code>target</code> 。</p>
|
||||
|
||||
<p>你的初始位置在下标 <code>0</code> 。在一步操作中,你可以从下标 <code>i</code> 跳跃到任意满足下述条件的下标 <code>j</code> :</p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= i < j < n</code></li>
|
||||
<li><code>-target <= nums[j] - nums[i] <= target</code></li>
|
||||
</ul>
|
||||
|
||||
<p>返回到达下标 <code>n - 1</code> 处所需的 <strong>最大跳跃次数</strong> 。</p>
|
||||
|
||||
<p>如果无法到达下标 <code>n - 1</code> ,返回 <code>-1</code> 。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>nums = [1,3,6,4,1,2], target = 2
|
||||
<strong>输出:</strong>3
|
||||
<strong>解释:</strong>要想以最大跳跃次数从下标 0 到下标 n - 1 ,可以按下述跳跃序列执行操作:
|
||||
- 从下标 0 跳跃到下标 1 。
|
||||
- 从下标 1 跳跃到下标 3 。
|
||||
- 从下标 3 跳跃到下标 5 。
|
||||
可以证明,从 0 到 n - 1 的所有方案中,不存在比 3 步更长的跳跃序列。因此,答案是 3 。 </pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>nums = [1,3,6,4,1,2], target = 3
|
||||
<strong>输出:</strong>5
|
||||
<strong>解释:</strong>要想以最大跳跃次数从下标 0 到下标 n - 1 ,可以按下述跳跃序列执行操作:
|
||||
- 从下标 0 跳跃到下标 1 。
|
||||
- 从下标 1 跳跃到下标 2 。
|
||||
- 从下标 2 跳跃到下标 3 。
|
||||
- 从下标 3 跳跃到下标 4 。
|
||||
- 从下标 4 跳跃到下标 5 。
|
||||
可以证明,从 0 到 n - 1 的所有方案中,不存在比 5 步更长的跳跃序列。因此,答案是 5 。 </pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>nums = [1,3,6,4,1,2], target = 0
|
||||
<strong>输出:</strong>-1
|
||||
<strong>解释:</strong>可以证明不存在从 0 到 n - 1 的跳跃序列。因此,答案是 -1 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= nums.length == n <= 1000</code></li>
|
||||
<li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li>
|
||||
<li><code>0 <= target <= 2 * 10<sup>9</sup></code></li>
|
||||
</ul>
|
48
leetcode-cn/problem (Chinese)/重新放置石块 [relocate-marbles].html
Normal file
48
leetcode-cn/problem (Chinese)/重新放置石块 [relocate-marbles].html
Normal file
@ -0,0 +1,48 @@
|
||||
<p>给你一个下标从 <strong>0</strong> 开始的整数数组 <code>nums</code> ,表示一些石块的初始位置。再给你两个长度<strong> 相等</strong> 下标从 <strong>0</strong> 开始的整数数组 <code>moveFrom</code> 和 <code>moveTo</code> 。</p>
|
||||
|
||||
<p>在 <code>moveFrom.length</code> 次操作内,你可以改变石块的位置。在第 <code>i</code> 次操作中,你将位置在 <code>moveFrom[i]</code> 的所有石块移到位置 <code>moveTo[i]</code> 。</p>
|
||||
|
||||
<p>完成这些操作后,请你按升序返回所有 <strong>有</strong> 石块的位置。</p>
|
||||
|
||||
<p><strong>注意:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>如果一个位置至少有一个石块,我们称这个位置 <strong>有</strong> 石块。</li>
|
||||
<li>一个位置可能会有多个石块。</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>nums = [1,6,7,8], moveFrom = [1,7,2], moveTo = [2,9,5]
|
||||
<b>输出:</b>[5,6,8,9]
|
||||
<b>解释:</b>一开始,石块在位置 1,6,7,8 。
|
||||
第 i = 0 步操作中,我们将位置 1 处的石块移到位置 2 处,位置 2,6,7,8 有石块。
|
||||
第 i = 1 步操作中,我们将位置 7 处的石块移到位置 9 处,位置 2,6,8,9 有石块。
|
||||
第 i = 2 步操作中,我们将位置 2 处的石块移到位置 5 处,位置 5,6,8,9 有石块。
|
||||
最后,至少有一个石块的位置为 [5,6,8,9] 。</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>nums = [1,1,3,3], moveFrom = [1,3], moveTo = [2,2]
|
||||
<b>输出:</b>[2]
|
||||
<b>解释:</b>一开始,石块在位置 [1,1,3,3] 。
|
||||
第 i = 0 步操作中,我们将位置 1 处的石块移到位置 2 处,有石块的位置为 [2,2,3,3] 。
|
||||
第 i = 1 步操作中,我们将位置 3 处的石块移到位置 2 处,有石块的位置为 [2,2,2,2] 。
|
||||
由于 2 是唯一有石块的位置,我们返回 [2] 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= moveFrom.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>moveFrom.length == moveTo.length</code></li>
|
||||
<li><code>1 <= nums[i], moveFrom[i], moveTo[i] <= 10<sup>9</sup></code></li>
|
||||
<li>测试数据保证在进行第 <code>i</code> 步操作时,<code>moveFrom[i]</code> 处至少有一个石块。</li>
|
||||
</ul>
|
@ -0,0 +1,47 @@
|
||||
<p>给你两个整数 <code>m</code> 和 <code>n</code> ,表示一个下标从 <strong>0</strong> 开始的 <code>m x n</code> 的网格图。</p>
|
||||
|
||||
<p>给你一个下标从 <strong>0</strong> 开始的二维整数矩阵 <code>coordinates</code> ,其中 <code>coordinates[i] = [x, y]</code> 表示坐标为 <code>[x, y]</code> 的格子是 <strong>黑色的</strong> ,所有没出现在 <code>coordinates</code> 中的格子都是 <strong>白色的</strong>。</p>
|
||||
|
||||
<p>一个块定义为网格图中 <code>2 x 2</code> 的一个子矩阵。更正式的,对于左上角格子为 <code>[x, y]</code> 的块,其中 <code>0 <= x < m - 1</code> 且 <code>0 <= y < n - 1</code> ,包含坐标为 <code>[x, y]</code> ,<code>[x + 1, y]</code> ,<code>[x, y + 1]</code> 和 <code>[x + 1, y + 1]</code> 的格子。</p>
|
||||
|
||||
<p>请你返回一个下标从 <strong>0</strong> 开始长度为 <code>5</code> 的整数数组 <code>arr</code> ,<code>arr[i]</code> 表示恰好包含 <code>i</code> 个 <strong>黑色</strong> 格子的块的数目。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>m = 3, n = 3, coordinates = [[0,0]]
|
||||
<b>输出:</b>[3,1,0,0,0]
|
||||
<b>解释:</b>网格图如下:
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2023/06/18/screen-shot-2023-06-18-at-44656-am.png" style="width: 150px; height: 128px;" />
|
||||
只有 1 个块有一个黑色格子,这个块是左上角为 [0,0] 的块。
|
||||
其他 3 个左上角分别为 [0,1] ,[1,0] 和 [1,1] 的块都有 0 个黑格子。
|
||||
所以我们返回 [3,1,0,0,0] 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>m = 3, n = 3, coordinates = [[0,0],[1,1],[0,2]]
|
||||
<b>输出:</b>[0,2,2,0,0]
|
||||
<b>解释:</b>网格图如下:
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2023/06/18/screen-shot-2023-06-18-at-45018-am.png" style="width: 150px; height: 128px;" />
|
||||
有 2 个块有 2 个黑色格子(左上角格子分别为 [0,0] 和 [0,1])。
|
||||
左上角为 [1,0] 和 [1,1] 的两个块,都有 1 个黑格子。
|
||||
所以我们返回 [0,2,2,0,0] 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= m <= 10<sup>5</sup></code></li>
|
||||
<li><code>2 <= n <= 10<sup>5</sup></code></li>
|
||||
<li><code>0 <= coordinates.length <= 10<sup>4</sup></code></li>
|
||||
<li><code>coordinates[i].length == 2</code></li>
|
||||
<li><code>0 <= coordinates[i][0] < m</code></li>
|
||||
<li><code>0 <= coordinates[i][1] < n</code></li>
|
||||
<li><code>coordinates</code> 中的坐标对两两互不相同。</li>
|
||||
</ul>
|
@ -0,0 +1,39 @@
|
||||
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> and a positive integer <code>k</code>.</p>
|
||||
|
||||
<p>You can apply the following operation on the array <strong>any</strong> number of times:</p>
|
||||
|
||||
<ul>
|
||||
<li>Choose <strong>any</strong> subarray of size <code>k</code> from the array and <strong>decrease</strong> all its elements by <code>1</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return <code>true</code><em> if you can make all the array elements equal to </em><code>0</code><em>, or </em><code>false</code><em> otherwise</em>.</p>
|
||||
|
||||
<p>A <strong>subarray</strong> is a contiguous non-empty part of an array.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [2,2,3,1,1,0], k = 3
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong> We can do the following operations:
|
||||
- Choose the subarray [2,2,3]. The resulting array will be nums = [<strong><u>1</u></strong>,<strong><u>1</u></strong>,<strong><u>2</u></strong>,1,1,0].
|
||||
- Choose the subarray [2,1,1]. The resulting array will be nums = [1,1,<strong><u>1</u></strong>,<strong><u>0</u></strong>,<strong><u>0</u></strong>,0].
|
||||
- Choose the subarray [1,1,1]. The resulting array will be nums = [<u><strong>0</strong></u>,<u><strong>0</strong></u>,<u><strong>0</strong></u>,0,0,0].
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,3,1,1], k = 2
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation:</strong> It is not possible to make all the array elements equal to 0.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= k <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>0 <= nums[i] <= 10<sup>6</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,54 @@
|
||||
<p>An element <code>x</code> of an integer array <code>arr</code> of length <code>m</code> is <strong>dominant</strong> if <code>freq(x) * 2 > m</code>, where <code>freq(x)</code> is the number of occurrences of <code>x</code> in <code>arr</code>. Note that this definition implies that <code>arr</code> can have <strong>at most one</strong> dominant element.</p>
|
||||
|
||||
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code> with one dominant element.</p>
|
||||
|
||||
<p>You can split <code>nums</code> at an index <code>i</code> into two arrays <code>nums[0, ..., i]</code> and <code>nums[i + 1, ..., n - 1]</code>, but the split is only <strong>valid</strong> if:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= i < n - 1</code></li>
|
||||
<li><code>nums[0, ..., i]</code>, and <code>nums[i + 1, ..., n - 1]</code> have the same dominant element.</li>
|
||||
</ul>
|
||||
|
||||
<p>Here, <code>nums[i, ..., j]</code> denotes the subarray of <code>nums</code> starting at index <code>i</code> and ending at index <code>j</code>, both ends being inclusive. Particularly, if <code>j < i</code> then <code>nums[i, ..., j]</code> denotes an empty subarray.</p>
|
||||
|
||||
<p>Return <em>the <strong>minimum</strong> index of a <strong>valid split</strong></em>. If no valid split exists, return <code>-1</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,2,2,2]
|
||||
<strong>Output:</strong> 2
|
||||
<strong>Explanation:</strong> We can split the array at index 2 to obtain arrays [1,2,2] and [2].
|
||||
In array [1,2,2], element 2 is dominant since it occurs twice in the array and 2 * 2 > 3.
|
||||
In array [2], element 2 is dominant since it occurs once in the array and 1 * 2 > 1.
|
||||
Both [1,2,2] and [2] have the same dominant element as nums, so this is a valid split.
|
||||
It can be shown that index 2 is the minimum index of a valid split. </pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [2,1,3,1,1,1,7,1,2,1]
|
||||
<strong>Output:</strong> 4
|
||||
<strong>Explanation:</strong> We can split the array at index 4 to obtain arrays [2,1,3,1,1] and [1,7,1,2,1].
|
||||
In array [2,1,3,1,1], element 1 is dominant since it occurs thrice in the array and 3 * 2 > 5.
|
||||
In array [1,7,1,2,1], element 1 is dominant since it occurs thrice in the array and 3 * 2 > 5.
|
||||
Both [2,1,3,1,1] and [1,7,1,2,1] have the same dominant element as nums, so this is a valid split.
|
||||
It can be shown that index 4 is the minimum index of a valid split.</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [3,3,3,3,7,2,2]
|
||||
<strong>Output:</strong> -1
|
||||
<strong>Explanation:</strong> It can be shown that there is no valid split.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>
|
||||
<li><code>nums</code> has exactly one dominant element.</li>
|
||||
</ul>
|
@ -0,0 +1,50 @@
|
||||
<p>Given a binary string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that each substring is <strong>beautiful</strong>.</p>
|
||||
|
||||
<p>A string is <strong>beautiful</strong> if:</p>
|
||||
|
||||
<ul>
|
||||
<li>It doesn't contain leading zeros.</li>
|
||||
<li>It's the <strong>binary</strong> representation of a number that is a power of <code>5</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the <strong>minimum</strong> number of substrings in such partition. </em>If it is impossible to partition the string <code>s</code> into beautiful substrings, return <code>-1</code>.</p>
|
||||
|
||||
<p>A <strong>substring</strong> is a contiguous sequence of characters in a string.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "1011"
|
||||
<strong>Output:</strong> 2
|
||||
<strong>Explanation:</strong> We can paritition the given string into ["101", "1"].
|
||||
- The string "101" does not contain leading zeros and is the binary representation of integer 5<sup>1</sup> = 5.
|
||||
- The string "1" does not contain leading zeros and is the binary representation of integer 5<sup>0</sup> = 1.
|
||||
It can be shown that 2 is the minimum number of beautiful substrings that s can be partitioned into.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "111"
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> We can paritition the given string into ["1", "1", "1"].
|
||||
- The string "1" does not contain leading zeros and is the binary representation of integer 5<sup>0</sup> = 1.
|
||||
It can be shown that 3 is the minimum number of beautiful substrings that s can be partitioned into.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "0"
|
||||
<strong>Output:</strong> -1
|
||||
<strong>Explanation:</strong> We can not partition the given string into beautiful substrings.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= s.length <= 15</code></li>
|
||||
<li><code>s[i]</code> is either <code>'0'</code> or <code>'1'</code>.</li>
|
||||
</ul>
|
@ -0,0 +1,39 @@
|
||||
<p>You are given two integers, <code>num</code> and <code>t</code>.</p>
|
||||
|
||||
<p>An integer <code>x</code> is called <b>achievable</b> if it can become equal to <code>num</code> after applying the following operation no more than <code>t</code> times:</p>
|
||||
|
||||
<ul>
|
||||
<li>Increase or decrease <code>x</code> by <code>1</code>, and simultaneously increase or decrease <code>num</code> by <code>1</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the maximum possible achievable number</em>. It can be proven that there exists at least one achievable number.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> num = 4, t = 1
|
||||
<strong>Output:</strong> 6
|
||||
<strong>Explanation:</strong> The maximum achievable number is x = 6; it can become equal to num after performing this operation:
|
||||
1- Decrease x by 1, and increase num by 1. Now, x = 5 and num = 5.
|
||||
It can be proven that there is no achievable number larger than 6.
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> num = 3, t = 2
|
||||
<strong>Output:</strong> 7
|
||||
<strong>Explanation:</strong> The maximum achievable number is x = 7; after performing these operations, x will equal num:
|
||||
1- Decrease x by 1, and increase num by 1. Now, x = 6 and num = 4.
|
||||
2- Decrease x by 1, and increase num by 1. Now, x = 5 and num = 5.
|
||||
It can be proven that there is no achievable number larger than 7.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= num, t <= 50</code></li>
|
||||
</ul>
|
@ -0,0 +1,46 @@
|
||||
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>.</p>
|
||||
|
||||
<p>In one operation, you can do the following:</p>
|
||||
|
||||
<ul>
|
||||
<li>Choose an index <code>i</code> that <strong>hasn't been chosen before</strong> from the range <code>[0, nums.length - 1]</code>.</li>
|
||||
<li>Replace <code>nums[i]</code> with any integer from the range <code>[nums[i] - k, nums[i] + k]</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>The <strong>beauty</strong> of the array is the length of the longest subsequence consisting of equal elements.</p>
|
||||
|
||||
<p>Return <em>the <strong>maximum</strong> possible beauty of the array </em><code>nums</code><em> after applying the operation any number of times.</em></p>
|
||||
|
||||
<p><strong>Note</strong> that you can apply the operation to each index <strong>only once</strong>.</p>
|
||||
|
||||
<p>A <strong>subsequence</strong> of an array is a new array generated from the original array by deleting some elements (possibly none) without changing the order of the remaining elements.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [4,6,1,2], k = 2
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> In this example, we apply the following operations:
|
||||
- Choose index 1, replace it with 4 (from range [4,8]), nums = [4,4,1,2].
|
||||
- Choose index 3, replace it with 4 (from range [0,4]), nums = [4,4,1,4].
|
||||
After the applied operations, the beauty of the array nums is 3 (subsequence consisting of indices 0, 1, and 3).
|
||||
It can be proven that 3 is the maximum possible length we can achieve.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,1,1,1], k = 10
|
||||
<strong>Output:</strong> 4
|
||||
<strong>Explanation:</strong> In this example we don't have to apply any operations.
|
||||
The beauty of the array nums is 4 (whole array).
|
||||
</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], k <= 10<sup>5</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,36 @@
|
||||
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A subarray <code>s</code> of length <code>m</code> is called <strong>alternating</strong> if:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>m</code> is greater than <code>1</code>.</li>
|
||||
<li><code>s<sub>1</sub> = s<sub>0</sub> + 1</code>.</li>
|
||||
<li>The <strong>0-indexed</strong> subarray <code>s</code> looks like <code>[s<sub>0</sub>, s<sub>1</sub>, s<sub>0</sub>, s<sub>1</sub>,...,s<sub>(m-1) % 2</sub>]</code>. In other words, <code>s<sub>1</sub> - s<sub>0</sub> = 1</code>, <code>s<sub>2</sub> - s<sub>1</sub> = -1</code>, <code>s<sub>3</sub> - s<sub>2</sub> = 1</code>, <code>s<sub>4</sub> - s<sub>3</sub> = -1</code>, and so on up to <code>s[m - 1] - s[m - 2] = (-1)<sup>m</sup></code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the maximum length of all <strong>alternating</strong> subarrays present in </em><code>nums</code> <em>or </em><code>-1</code><em> if no such subarray exists</em><em>.</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 = [2,3,4,3,4]
|
||||
<strong>Output:</strong> 4
|
||||
<strong>Explanation:</strong> The alternating subarrays are [3,4], [3,4,3], and [3,4,3,4]. The longest of these is [3,4,3,4], which is of length 4.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [4,5,6]
|
||||
<strong>Output:</strong> 2
|
||||
<strong>Explanation:</strong> [4,5] and [5,6] are the only two alternating subarrays. They are both of length 2.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= nums.length <= 100</code></li>
|
||||
<li><code>1 <= nums[i] <= 10<sup>4</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,36 @@
|
||||
<p>You are given a string <code>word</code> and an array of strings <code>forbidden</code>.</p>
|
||||
|
||||
<p>A string is called <strong>valid</strong> if none of its substrings are present in <code>forbidden</code>.</p>
|
||||
|
||||
<p>Return <em>the length of the <strong>longest valid substring</strong> of the string </em><code>word</code>.</p>
|
||||
|
||||
<p>A <strong>substring</strong> is a contiguous sequence of characters in a string, possibly empty.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> word = "cbaaaabc", forbidden = ["aaa","cb"]
|
||||
<strong>Output:</strong> 4
|
||||
<strong>Explanation:</strong> There are 9 valid substrings in word: "c", "b", "a", "ba", "aa", "bc", "baa", "aab", and "aabc". The length of the longest valid substring is 4.
|
||||
It can be shown that all other substrings contain either "aaa" or "cb" as a substring. </pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> word = "leetcode", forbidden = ["de","le","e"]
|
||||
<strong>Output:</strong> 4
|
||||
<strong>Explanation:</strong> There are 11 valid substrings in word: "l", "t", "c", "o", "d", "tc", "co", "od", "tco", "cod", and "tcod". The length of the longest valid substring is 4.
|
||||
It can be shown that all other substrings contain either "de", "le", or "e" as a substring.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= word.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>word</code> consists only of lowercase English letters.</li>
|
||||
<li><code>1 <= forbidden.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= forbidden[i].length <= 10</code></li>
|
||||
<li><code>forbidden[i]</code> consists only of lowercase English letters.</li>
|
||||
</ul>
|
@ -0,0 +1,48 @@
|
||||
<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of length <code>n</code>.</p>
|
||||
|
||||
<p>Let's define another <strong>0-indexed</strong> integer array, <code>nums3</code>, of length <code>n</code>. For each index <code>i</code> in the range <code>[0, n - 1]</code>, you can assign either <code>nums1[i]</code> or <code>nums2[i]</code> to <code>nums3[i]</code>.</p>
|
||||
|
||||
<p>Your task is to maximize the length of the <strong>longest non-decreasing subarray</strong> in <code>nums3</code> by choosing its values optimally.</p>
|
||||
|
||||
<p>Return <em>an integer representing the length of the <strong>longest non-decreasing</strong> subarray in</em> <code>nums3</code>.</p>
|
||||
|
||||
<p><strong>Note: </strong>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> nums1 = [2,3,1], nums2 = [1,2,1]
|
||||
<strong>Output:</strong> 2
|
||||
<strong>Explanation: </strong>One way to construct nums3 is:
|
||||
nums3 = [nums1[0], nums2[1], nums2[2]] => [2,2,1].
|
||||
The subarray starting from index 0 and ending at index 1, [2,2], forms a non-decreasing subarray of length 2.
|
||||
We can show that 2 is the maximum achievable length.</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums1 = [1,3,2,1], nums2 = [2,2,3,4]
|
||||
<strong>Output:</strong> 4
|
||||
<strong>Explanation:</strong> One way to construct nums3 is:
|
||||
nums3 = [nums1[0], nums2[1], nums2[2], nums2[3]] => [1,2,3,4].
|
||||
The entire array forms a non-decreasing subarray of length 4, making it the maximum achievable length.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums1 = [1,1], nums2 = [2,2]
|
||||
<strong>Output:</strong> 2
|
||||
<strong>Explanation:</strong> One way to construct nums3 is:
|
||||
nums3 = [nums1[0], nums1[1]] => [1,1].
|
||||
The entire array forms a non-decreasing subarray of length 2, making it the maximum achievable length.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums1.length == nums2.length == n <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= nums1[i], nums2[i] <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,32 @@
|
||||
<p>You are given a <strong>1-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p>
|
||||
|
||||
<p>An element <code>nums[i]</code> of <code>nums</code> is called <strong>special</strong> if <code>i</code> divides <code>n</code>, i.e. <code>n % i == 0</code>.</p>
|
||||
|
||||
<p>Return <em>the <strong>sum of the squares</strong> of all <strong>special</strong> elements of </em><code>nums</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,2,3,4]
|
||||
<strong>Output:</strong> 21
|
||||
<strong>Explanation:</strong> There are exactly 3 special elements in nums: nums[1] since 1 divides 4, nums[2] since 2 divides 4, and nums[4] since 4 divides 4.
|
||||
Hence, the sum of the squares of all special elements of nums is nums[1] * nums[1] + nums[2] * nums[2] + nums[4] * nums[4] = 1 * 1 + 2 * 2 + 4 * 4 = 21.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [2,7,1,19,18,3]
|
||||
<strong>Output:</strong> 63
|
||||
<strong>Explanation:</strong> There are exactly 4 special elements in nums: nums[1] since 1 divides 6, nums[2] since 2 divides 6, nums[3] since 3 divides 6, and nums[6] since 6 divides 6.
|
||||
Hence, the sum of the squares of all special elements of nums is nums[1] * nums[1] + nums[2] * nums[2] + nums[3] * nums[3] + nums[6] * nums[6] = 2 * 2 + 7 * 7 + 1 * 1 + 3 * 3 = 63.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length == n <= 50</code></li>
|
||||
<li><code>1 <= nums[i] <= 50</code></li>
|
||||
</ul>
|
@ -0,0 +1,54 @@
|
||||
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers and an integer <code>target</code>.</p>
|
||||
|
||||
<p>You are initially positioned at index <code>0</code>. In one step, you can jump from index <code>i</code> to any index <code>j</code> such that:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= i < j < n</code></li>
|
||||
<li><code>-target <= nums[j] - nums[i] <= target</code></li>
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the <strong>maximum number of jumps</strong> you can make to reach index</em> <code>n - 1</code>.</p>
|
||||
|
||||
<p>If there is no way to reach index <code>n - 1</code>, return <code>-1</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,3,6,4,1,2], target = 2
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> To go from index 0 to index n - 1 with the maximum number of jumps, you can perform the following jumping sequence:
|
||||
- Jump from index 0 to index 1.
|
||||
- Jump from index 1 to index 3.
|
||||
- Jump from index 3 to index 5.
|
||||
It can be proven that there is no other jumping sequence that goes from 0 to n - 1 with more than 3 jumps. Hence, the answer is 3. </pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,3,6,4,1,2], target = 3
|
||||
<strong>Output:</strong> 5
|
||||
<strong>Explanation:</strong> To go from index 0 to index n - 1 with the maximum number of jumps, you can perform the following jumping sequence:
|
||||
- Jump from index 0 to index 1.
|
||||
- Jump from index 1 to index 2.
|
||||
- Jump from index 2 to index 3.
|
||||
- Jump from index 3 to index 4.
|
||||
- Jump from index 4 to index 5.
|
||||
It can be proven that there is no other jumping sequence that goes from 0 to n - 1 with more than 5 jumps. Hence, the answer is 5. </pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,3,6,4,1,2], target = 0
|
||||
<strong>Output:</strong> -1
|
||||
<strong>Explanation:</strong> It can be proven that there is no jumping sequence that goes from 0 to n - 1. Hence, the answer is -1.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= nums.length == n <= 1000</code></li>
|
||||
<li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li>
|
||||
<li><code>0 <= target <= 2 * 10<sup>9</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,46 @@
|
||||
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> representing the initial positions of some marbles. You are also given two <strong>0-indexed </strong>integer arrays <code>moveFrom</code> and <code>moveTo</code> of <strong>equal</strong> length.</p>
|
||||
|
||||
<p>Throughout <code>moveFrom.length</code> steps, you will change the positions of the marbles. On the <code>i<sup>th</sup></code> step, you will move <strong>all</strong> marbles at position <code>moveFrom[i]</code> to position <code>moveTo[i]</code>.</p>
|
||||
|
||||
<p>After completing all the steps, return <em>the sorted list of <strong>occupied</strong> positions</em>.</p>
|
||||
|
||||
<p><strong>Notes:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>We call a position <strong>occupied</strong> if there is at least one marble in that position.</li>
|
||||
<li>There may be multiple marbles in a single position.</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,6,7,8], moveFrom = [1,7,2], moveTo = [2,9,5]
|
||||
<strong>Output:</strong> [5,6,8,9]
|
||||
<strong>Explanation:</strong> Initially, the marbles are at positions 1,6,7,8.
|
||||
At the i = 0th step, we move the marbles at position 1 to position 2. Then, positions 2,6,7,8 are occupied.
|
||||
At the i = 1st step, we move the marbles at position 7 to position 9. Then, positions 2,6,8,9 are occupied.
|
||||
At the i = 2nd step, we move the marbles at position 2 to position 5. Then, positions 5,6,8,9 are occupied.
|
||||
At the end, the final positions containing at least one marbles are [5,6,8,9].</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,1,3,3], moveFrom = [1,3], moveTo = [2,2]
|
||||
<strong>Output:</strong> [2]
|
||||
<strong>Explanation:</strong> Initially, the marbles are at positions [1,1,3,3].
|
||||
At the i = 0th step, we move all the marbles at position 1 to position 2. Then, the marbles are at positions [2,2,3,3].
|
||||
At the i = 1st step, we move all the marbles at position 3 to position 2. Then, the marbles are at positions [2,2,2,2].
|
||||
Since 2 is the only occupied position, we return [2].
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= moveFrom.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>moveFrom.length == moveTo.length</code></li>
|
||||
<li><code>1 <= nums[i], moveFrom[i], moveTo[i] <= 10<sup>9</sup></code></li>
|
||||
<li>The test cases are generated such that there is at least a marble in <code>moveFrom[i]</code> at the moment we want to apply the <code>i<sup>th</sup></code> move.</li>
|
||||
</ul>
|
@ -0,0 +1,45 @@
|
||||
<p>You are given two integers <code>m</code> and <code>n</code> representing the dimensions of a <strong>0-indexed</strong> <code>m x n</code> grid.</p>
|
||||
|
||||
<p>You are also given a <strong>0-indexed</strong> 2D integer matrix <code>coordinates</code>, where <code>coordinates[i] = [x, y]</code> indicates that the cell with coordinates <code>[x, y]</code> is colored <strong>black</strong>. All cells in the grid that do not appear in <code>coordinates</code> are <strong>white</strong>.</p>
|
||||
|
||||
<p>A block is defined as a <code>2 x 2</code> submatrix of the grid. More formally, a block with cell <code>[x, y]</code> as its top-left corner where <code>0 <= x < m - 1</code> and <code>0 <= y < n - 1</code> contains the coordinates <code>[x, y]</code>, <code>[x + 1, y]</code>, <code>[x, y + 1]</code>, and <code>[x + 1, y + 1]</code>.</p>
|
||||
|
||||
<p>Return <em>a <strong>0-indexed</strong> integer array</em> <code>arr</code> <em>of size</em> <code>5</code> <em>such that</em> <code>arr[i]</code> <em>is the number of blocks that contains exactly</em> <code>i</code> <em><strong>black</strong> cells</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> m = 3, n = 3, coordinates = [[0,0]]
|
||||
<strong>Output:</strong> [3,1,0,0,0]
|
||||
<strong>Explanation:</strong> The grid looks like this:
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2023/06/18/screen-shot-2023-06-18-at-44656-am.png" style="width: 150px; height: 128px;" />
|
||||
There is only 1 block with one black cell, and it is the block starting with cell [0,0].
|
||||
The other 3 blocks start with cells [0,1], [1,0] and [1,1]. They all have zero black cells.
|
||||
Thus, we return [3,1,0,0,0].
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> m = 3, n = 3, coordinates = [[0,0],[1,1],[0,2]]
|
||||
<strong>Output:</strong> [0,2,2,0,0]
|
||||
<strong>Explanation:</strong> The grid looks like this:
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2023/06/18/screen-shot-2023-06-18-at-45018-am.png" style="width: 150px; height: 128px;" />
|
||||
There are 2 blocks with two black cells (the ones starting with cell coordinates [0,0] and [0,1]).
|
||||
The other 2 blocks have starting cell coordinates of [1,0] and [1,1]. They both have 1 black cell.
|
||||
Therefore, we return [0,2,2,0,0].
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= m <= 10<sup>5</sup></code></li>
|
||||
<li><code>2 <= n <= 10<sup>5</sup></code></li>
|
||||
<li><code>0 <= coordinates.length <= 10<sup>4</sup></code></li>
|
||||
<li><code>coordinates[i].length == 2</code></li>
|
||||
<li><code>0 <= coordinates[i][0] < m</code></li>
|
||||
<li><code>0 <= coordinates[i][1] < n</code></li>
|
||||
<li>It is guaranteed that <code>coordinates</code> contains pairwise distinct coordinates.</li>
|
||||
</ul>
|
File diff suppressed because it is too large
Load Diff
47
leetcode/originData/[no content]array-upper-bound.json
Normal file
47
leetcode/originData/[no content]array-upper-bound.json
Normal file
@ -0,0 +1,47 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2768",
|
||||
"questionFrontendId": "2774",
|
||||
"boundTopicId": null,
|
||||
"title": "Array Upper Bound",
|
||||
"titleSlug": "array-upper-bound",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Easy",
|
||||
"likes": 7,
|
||||
"dislikes": 1,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[{\"title\": \"Array Prototype Last\", \"titleSlug\": \"array-prototype-last\", \"difficulty\": \"Easy\", \"translatedTitle\": null}, {\"title\": \"Group By\", \"titleSlug\": \"group-by\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Snail Traversal\", \"titleSlug\": \"snail-traversal\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
|
||||
"exampleTestcases": "[3,4,5]\n5\n[1,4,5]\n2\n[3,4,6,6,6,6,7]\n6",
|
||||
"categoryTitle": "JavaScript",
|
||||
"contributors": [],
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"86\", \"totalSubmission\": \"100\", \"totalAcceptedRaw\": 86, \"totalSubmissionRaw\": 100, \"acRate\": \"86.0%\"}",
|
||||
"hints": [
|
||||
"Inside the Array.prototype.upperBound function you have access to the \"this\" keyword. You can access array elements, values, and methods. For example \"this[0]\", \"this[1]\", \"this.length\", \"this.map()\", etc.",
|
||||
"The most efficient way to solve this problem is with binary search.",
|
||||
"Choose the middle element and check if it's less than or equal to the goal value. If so, you can rule out the left side of the array."
|
||||
],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "[3,4,5]\n5",
|
||||
"metaData": "{\n \"name\": \"upperBound\",\n \"params\": [\n {\n \"name\": \"nums\",\n \"type\": \"integer[]\"\n },\n {\n \"type\": \"integer\",\n \"name\": \"target\"\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 5.1.6, 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 ES2022 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": "2782",
|
||||
"questionFrontendId": "2776",
|
||||
"boundTopicId": null,
|
||||
"title": "Convert Callback Based Function to Promise Based Function",
|
||||
"titleSlug": "convert-callback-based-function-to-promise-based-function",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Medium",
|
||||
"likes": 5,
|
||||
"dislikes": 2,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"exampleTestcases": "(callback, a, b, c) => callback(a * b * c)\n[1, 2, 3]\n(callback, a, b, c) => callback(a * b * c, \"Promise Rejected\")\n[4, 5, 6]",
|
||||
"categoryTitle": "JavaScript",
|
||||
"contributors": [],
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"43\", \"totalSubmission\": \"44\", \"totalAcceptedRaw\": 43, \"totalSubmissionRaw\": 44, \"acRate\": \"97.7%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "(callback, a, b, c) => callback(a * b * c)\n[1, 2, 3]",
|
||||
"metaData": "{\n \"name\": \"foobar\",\n \"params\": [\n {\n \"name\": \"fn\",\n \"type\": \"string\"\n },\n {\n \"type\": \"integer[][]\",\n \"name\": \"args\"\n }\n ],\n \"return\": {\n \"type\": \"integer\"\n },\n \"manual\": true,\n \"languages\": [\n \"javascript\",\n \"typescript\"\n ]\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 5.1.6, 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 ES2022 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]date-range-generator.json
Normal file
43
leetcode/originData/[no content]date-range-generator.json
Normal file
@ -0,0 +1,43 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2799",
|
||||
"questionFrontendId": "2777",
|
||||
"boundTopicId": null,
|
||||
"title": "Date Range Generator",
|
||||
"titleSlug": "date-range-generator",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Medium",
|
||||
"likes": 3,
|
||||
"dislikes": 1,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"exampleTestcases": "\"2023-04-01\"\n\"2023-04-04\"\n1\n\"2023-04-10\"\n\"2023-04-20\"\n3\n\"2023-04-10\"\n\"2023-04-10\"\n1",
|
||||
"categoryTitle": "JavaScript",
|
||||
"contributors": [],
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"49\", \"totalSubmission\": \"53\", \"totalAcceptedRaw\": 49, \"totalSubmissionRaw\": 53, \"acRate\": \"92.5%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "\"2023-04-01\"\n\"2023-04-04\"\n1",
|
||||
"metaData": "{\n \"name\": \"dateRangeGenerator\",\n \"params\": [\n {\n \"name\": \"start\",\n \"type\": \"integer\"\n },\n {\n \"type\": \"integer\",\n \"name\": \"end\"\n },\n {\n \"type\": \"integer\",\n \"name\": \"step\"\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 5.1.6, 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 ES2022 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
File diff suppressed because one or more lines are too long
43
leetcode/originData/[no content]undefined-to-null.json
Normal file
43
leetcode/originData/[no content]undefined-to-null.json
Normal file
@ -0,0 +1,43 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2781",
|
||||
"questionFrontendId": "2775",
|
||||
"boundTopicId": null,
|
||||
"title": "Undefined to Null",
|
||||
"titleSlug": "undefined-to-null",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Medium",
|
||||
"likes": 4,
|
||||
"dislikes": 1,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"exampleTestcases": "{\"a\": undefined, \"b\":3}\n{\"a\": undefined, \"b\":[\"a\", undefined]}",
|
||||
"categoryTitle": "JavaScript",
|
||||
"contributors": [],
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"47\", \"totalSubmission\": \"65\", \"totalAcceptedRaw\": 47, \"totalSubmissionRaw\": 65, \"acRate\": \"72.3%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"a\": undefined, \"b\":3}",
|
||||
"metaData": "{\n \"name\": \"undefinedToNull\",\n \"params\": [\n {\n \"name\": \"obj\",\n \"type\": \"string\"\n }\n ],\n \"return\": {\n \"type\": \"string\"\n },\n \"languages\": [\n \"javascript\",\n \"typescript\"\n ],\n \"manual\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [],
|
||||
"enableRunCode": true,
|
||||
"enableTestMode": false,
|
||||
"enableDebugger": false,
|
||||
"envInfo": "{\"javascript\": [\"JavaScript\", \"<p><code>Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES6 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\\r\\n\\r\\n<p>For Priority Queue / Queue data structures, you may use 5.3.0 version of <a href=\\\"https://github.com/datastructures-js/priority-queue/tree/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\">datastructures-js/priority-queue</a> and 4.2.1 version of <a href=\\\"https://github.com/datastructures-js/queue/tree/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\">datastructures-js/queue</a>.</p>\"], \"typescript\": [\"Typescript\", \"<p><code>TypeScript 5.1.6, 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 ES2022 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
167
leetcode/originData/find-the-maximum-achievable-number.json
Normal file
167
leetcode/originData/find-the-maximum-achievable-number.json
Normal file
File diff suppressed because one or more lines are too long
158
leetcode/originData/length-of-the-longest-valid-substring.json
Normal file
158
leetcode/originData/length-of-the-longest-valid-substring.json
Normal file
File diff suppressed because one or more lines are too long
173
leetcode/originData/longest-alternating-subarray.json
Normal file
173
leetcode/originData/longest-alternating-subarray.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
File diff suppressed because one or more lines are too long
161
leetcode/originData/minimum-index-of-a-valid-split.json
Normal file
161
leetcode/originData/minimum-index-of-a-valid-split.json
Normal file
File diff suppressed because one or more lines are too long
182
leetcode/originData/number-of-black-blocks.json
Normal file
182
leetcode/originData/number-of-black-blocks.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
186
leetcode/originData/relocate-marbles.json
Normal file
186
leetcode/originData/relocate-marbles.json
Normal file
File diff suppressed because one or more lines are too long
161
leetcode/originData/sum-of-squares-of-special-elements.json
Normal file
161
leetcode/originData/sum-of-squares-of-special-elements.json
Normal file
File diff suppressed because one or more lines are too long
@ -0,0 +1,39 @@
|
||||
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> and a positive integer <code>k</code>.</p>
|
||||
|
||||
<p>You can apply the following operation on the array <strong>any</strong> number of times:</p>
|
||||
|
||||
<ul>
|
||||
<li>Choose <strong>any</strong> subarray of size <code>k</code> from the array and <strong>decrease</strong> all its elements by <code>1</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return <code>true</code><em> if you can make all the array elements equal to </em><code>0</code><em>, or </em><code>false</code><em> otherwise</em>.</p>
|
||||
|
||||
<p>A <strong>subarray</strong> is a contiguous non-empty part of an array.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [2,2,3,1,1,0], k = 3
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong> We can do the following operations:
|
||||
- Choose the subarray [2,2,3]. The resulting array will be nums = [<strong><u>1</u></strong>,<strong><u>1</u></strong>,<strong><u>2</u></strong>,1,1,0].
|
||||
- Choose the subarray [2,1,1]. The resulting array will be nums = [1,1,<strong><u>1</u></strong>,<strong><u>0</u></strong>,<strong><u>0</u></strong>,0].
|
||||
- Choose the subarray [1,1,1]. The resulting array will be nums = [<u><strong>0</strong></u>,<u><strong>0</strong></u>,<u><strong>0</strong></u>,0,0,0].
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,3,1,1], k = 2
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation:</strong> It is not possible to make all the array elements equal to 0.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= k <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>0 <= nums[i] <= 10<sup>6</sup></code></li>
|
||||
</ul>
|
39
leetcode/problem/find-the-maximum-achievable-number.html
Normal file
39
leetcode/problem/find-the-maximum-achievable-number.html
Normal file
@ -0,0 +1,39 @@
|
||||
<p>You are given two integers, <code>num</code> and <code>t</code>.</p>
|
||||
|
||||
<p>An integer <code>x</code> is called <b>achievable</b> if it can become equal to <code>num</code> after applying the following operation no more than <code>t</code> times:</p>
|
||||
|
||||
<ul>
|
||||
<li>Increase or decrease <code>x</code> by <code>1</code>, and simultaneously increase or decrease <code>num</code> by <code>1</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the maximum possible achievable number</em>. It can be proven that there exists at least one achievable number.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> num = 4, t = 1
|
||||
<strong>Output:</strong> 6
|
||||
<strong>Explanation:</strong> The maximum achievable number is x = 6; it can become equal to num after performing this operation:
|
||||
1- Decrease x by 1, and increase num by 1. Now, x = 5 and num = 5.
|
||||
It can be proven that there is no achievable number larger than 6.
|
||||
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> num = 3, t = 2
|
||||
<strong>Output:</strong> 7
|
||||
<strong>Explanation:</strong> The maximum achievable number is x = 7; after performing these operations, x will equal num:
|
||||
1- Decrease x by 1, and increase num by 1. Now, x = 6 and num = 4.
|
||||
2- Decrease x by 1, and increase num by 1. Now, x = 5 and num = 5.
|
||||
It can be proven that there is no achievable number larger than 7.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= num, t <= 50</code></li>
|
||||
</ul>
|
36
leetcode/problem/length-of-the-longest-valid-substring.html
Normal file
36
leetcode/problem/length-of-the-longest-valid-substring.html
Normal file
@ -0,0 +1,36 @@
|
||||
<p>You are given a string <code>word</code> and an array of strings <code>forbidden</code>.</p>
|
||||
|
||||
<p>A string is called <strong>valid</strong> if none of its substrings are present in <code>forbidden</code>.</p>
|
||||
|
||||
<p>Return <em>the length of the <strong>longest valid substring</strong> of the string </em><code>word</code>.</p>
|
||||
|
||||
<p>A <strong>substring</strong> is a contiguous sequence of characters in a string, possibly empty.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> word = "cbaaaabc", forbidden = ["aaa","cb"]
|
||||
<strong>Output:</strong> 4
|
||||
<strong>Explanation:</strong> There are 9 valid substrings in word: "c", "b", "a", "ba", "aa", "bc", "baa", "aab", and "aabc". The length of the longest valid substring is 4.
|
||||
It can be shown that all other substrings contain either "aaa" or "cb" as a substring. </pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> word = "leetcode", forbidden = ["de","le","e"]
|
||||
<strong>Output:</strong> 4
|
||||
<strong>Explanation:</strong> There are 11 valid substrings in word: "l", "t", "c", "o", "d", "tc", "co", "od", "tco", "cod", and "tcod". The length of the longest valid substring is 4.
|
||||
It can be shown that all other substrings contain either "de", "le", or "e" as a substring.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= word.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>word</code> consists only of lowercase English letters.</li>
|
||||
<li><code>1 <= forbidden.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= forbidden[i].length <= 10</code></li>
|
||||
<li><code>forbidden[i]</code> consists only of lowercase English letters.</li>
|
||||
</ul>
|
36
leetcode/problem/longest-alternating-subarray.html
Normal file
36
leetcode/problem/longest-alternating-subarray.html
Normal file
@ -0,0 +1,36 @@
|
||||
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A subarray <code>s</code> of length <code>m</code> is called <strong>alternating</strong> if:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>m</code> is greater than <code>1</code>.</li>
|
||||
<li><code>s<sub>1</sub> = s<sub>0</sub> + 1</code>.</li>
|
||||
<li>The <strong>0-indexed</strong> subarray <code>s</code> looks like <code>[s<sub>0</sub>, s<sub>1</sub>, s<sub>0</sub>, s<sub>1</sub>,...,s<sub>(m-1) % 2</sub>]</code>. In other words, <code>s<sub>1</sub> - s<sub>0</sub> = 1</code>, <code>s<sub>2</sub> - s<sub>1</sub> = -1</code>, <code>s<sub>3</sub> - s<sub>2</sub> = 1</code>, <code>s<sub>4</sub> - s<sub>3</sub> = -1</code>, and so on up to <code>s[m - 1] - s[m - 2] = (-1)<sup>m</sup></code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the maximum length of all <strong>alternating</strong> subarrays present in </em><code>nums</code> <em>or </em><code>-1</code><em> if no such subarray exists</em><em>.</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 = [2,3,4,3,4]
|
||||
<strong>Output:</strong> 4
|
||||
<strong>Explanation:</strong> The alternating subarrays are [3,4], [3,4,3], and [3,4,3,4]. The longest of these is [3,4,3,4], which is of length 4.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [4,5,6]
|
||||
<strong>Output:</strong> 2
|
||||
<strong>Explanation:</strong> [4,5] and [5,6] are the only two alternating subarrays. They are both of length 2.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= nums.length <= 100</code></li>
|
||||
<li><code>1 <= nums[i] <= 10<sup>4</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,48 @@
|
||||
<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of length <code>n</code>.</p>
|
||||
|
||||
<p>Let's define another <strong>0-indexed</strong> integer array, <code>nums3</code>, of length <code>n</code>. For each index <code>i</code> in the range <code>[0, n - 1]</code>, you can assign either <code>nums1[i]</code> or <code>nums2[i]</code> to <code>nums3[i]</code>.</p>
|
||||
|
||||
<p>Your task is to maximize the length of the <strong>longest non-decreasing subarray</strong> in <code>nums3</code> by choosing its values optimally.</p>
|
||||
|
||||
<p>Return <em>an integer representing the length of the <strong>longest non-decreasing</strong> subarray in</em> <code>nums3</code>.</p>
|
||||
|
||||
<p><strong>Note: </strong>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> nums1 = [2,3,1], nums2 = [1,2,1]
|
||||
<strong>Output:</strong> 2
|
||||
<strong>Explanation: </strong>One way to construct nums3 is:
|
||||
nums3 = [nums1[0], nums2[1], nums2[2]] => [2,2,1].
|
||||
The subarray starting from index 0 and ending at index 1, [2,2], forms a non-decreasing subarray of length 2.
|
||||
We can show that 2 is the maximum achievable length.</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums1 = [1,3,2,1], nums2 = [2,2,3,4]
|
||||
<strong>Output:</strong> 4
|
||||
<strong>Explanation:</strong> One way to construct nums3 is:
|
||||
nums3 = [nums1[0], nums2[1], nums2[2], nums2[3]] => [1,2,3,4].
|
||||
The entire array forms a non-decreasing subarray of length 4, making it the maximum achievable length.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums1 = [1,1], nums2 = [2,2]
|
||||
<strong>Output:</strong> 2
|
||||
<strong>Explanation:</strong> One way to construct nums3 is:
|
||||
nums3 = [nums1[0], nums1[1]] => [1,1].
|
||||
The entire array forms a non-decreasing subarray of length 2, making it the maximum achievable length.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums1.length == nums2.length == n <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= nums1[i], nums2[i] <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,46 @@
|
||||
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>.</p>
|
||||
|
||||
<p>In one operation, you can do the following:</p>
|
||||
|
||||
<ul>
|
||||
<li>Choose an index <code>i</code> that <strong>hasn't been chosen before</strong> from the range <code>[0, nums.length - 1]</code>.</li>
|
||||
<li>Replace <code>nums[i]</code> with any integer from the range <code>[nums[i] - k, nums[i] + k]</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>The <strong>beauty</strong> of the array is the length of the longest subsequence consisting of equal elements.</p>
|
||||
|
||||
<p>Return <em>the <strong>maximum</strong> possible beauty of the array </em><code>nums</code><em> after applying the operation any number of times.</em></p>
|
||||
|
||||
<p><strong>Note</strong> that you can apply the operation to each index <strong>only once</strong>.</p>
|
||||
|
||||
<p>A <strong>subsequence</strong> of an array is a new array generated from the original array by deleting some elements (possibly none) without changing the order of the remaining elements.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [4,6,1,2], k = 2
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> In this example, we apply the following operations:
|
||||
- Choose index 1, replace it with 4 (from range [4,8]), nums = [4,4,1,2].
|
||||
- Choose index 3, replace it with 4 (from range [0,4]), nums = [4,4,1,4].
|
||||
After the applied operations, the beauty of the array nums is 3 (subsequence consisting of indices 0, 1, and 3).
|
||||
It can be proven that 3 is the maximum possible length we can achieve.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,1,1,1], k = 10
|
||||
<strong>Output:</strong> 4
|
||||
<strong>Explanation:</strong> In this example we don't have to apply any operations.
|
||||
The beauty of the array nums is 4 (whole array).
|
||||
</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], k <= 10<sup>5</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,54 @@
|
||||
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers and an integer <code>target</code>.</p>
|
||||
|
||||
<p>You are initially positioned at index <code>0</code>. In one step, you can jump from index <code>i</code> to any index <code>j</code> such that:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= i < j < n</code></li>
|
||||
<li><code>-target <= nums[j] - nums[i] <= target</code></li>
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the <strong>maximum number of jumps</strong> you can make to reach index</em> <code>n - 1</code>.</p>
|
||||
|
||||
<p>If there is no way to reach index <code>n - 1</code>, return <code>-1</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,3,6,4,1,2], target = 2
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> To go from index 0 to index n - 1 with the maximum number of jumps, you can perform the following jumping sequence:
|
||||
- Jump from index 0 to index 1.
|
||||
- Jump from index 1 to index 3.
|
||||
- Jump from index 3 to index 5.
|
||||
It can be proven that there is no other jumping sequence that goes from 0 to n - 1 with more than 3 jumps. Hence, the answer is 3. </pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,3,6,4,1,2], target = 3
|
||||
<strong>Output:</strong> 5
|
||||
<strong>Explanation:</strong> To go from index 0 to index n - 1 with the maximum number of jumps, you can perform the following jumping sequence:
|
||||
- Jump from index 0 to index 1.
|
||||
- Jump from index 1 to index 2.
|
||||
- Jump from index 2 to index 3.
|
||||
- Jump from index 3 to index 4.
|
||||
- Jump from index 4 to index 5.
|
||||
It can be proven that there is no other jumping sequence that goes from 0 to n - 1 with more than 5 jumps. Hence, the answer is 5. </pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,3,6,4,1,2], target = 0
|
||||
<strong>Output:</strong> -1
|
||||
<strong>Explanation:</strong> It can be proven that there is no jumping sequence that goes from 0 to n - 1. Hence, the answer is -1.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= nums.length == n <= 1000</code></li>
|
||||
<li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li>
|
||||
<li><code>0 <= target <= 2 * 10<sup>9</sup></code></li>
|
||||
</ul>
|
54
leetcode/problem/minimum-index-of-a-valid-split.html
Normal file
54
leetcode/problem/minimum-index-of-a-valid-split.html
Normal file
@ -0,0 +1,54 @@
|
||||
<p>An element <code>x</code> of an integer array <code>arr</code> of length <code>m</code> is <strong>dominant</strong> if <code>freq(x) * 2 > m</code>, where <code>freq(x)</code> is the number of occurrences of <code>x</code> in <code>arr</code>. Note that this definition implies that <code>arr</code> can have <strong>at most one</strong> dominant element.</p>
|
||||
|
||||
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code> with one dominant element.</p>
|
||||
|
||||
<p>You can split <code>nums</code> at an index <code>i</code> into two arrays <code>nums[0, ..., i]</code> and <code>nums[i + 1, ..., n - 1]</code>, but the split is only <strong>valid</strong> if:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= i < n - 1</code></li>
|
||||
<li><code>nums[0, ..., i]</code>, and <code>nums[i + 1, ..., n - 1]</code> have the same dominant element.</li>
|
||||
</ul>
|
||||
|
||||
<p>Here, <code>nums[i, ..., j]</code> denotes the subarray of <code>nums</code> starting at index <code>i</code> and ending at index <code>j</code>, both ends being inclusive. Particularly, if <code>j < i</code> then <code>nums[i, ..., j]</code> denotes an empty subarray.</p>
|
||||
|
||||
<p>Return <em>the <strong>minimum</strong> index of a <strong>valid split</strong></em>. If no valid split exists, return <code>-1</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,2,2,2]
|
||||
<strong>Output:</strong> 2
|
||||
<strong>Explanation:</strong> We can split the array at index 2 to obtain arrays [1,2,2] and [2].
|
||||
In array [1,2,2], element 2 is dominant since it occurs twice in the array and 2 * 2 > 3.
|
||||
In array [2], element 2 is dominant since it occurs once in the array and 1 * 2 > 1.
|
||||
Both [1,2,2] and [2] have the same dominant element as nums, so this is a valid split.
|
||||
It can be shown that index 2 is the minimum index of a valid split. </pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [2,1,3,1,1,1,7,1,2,1]
|
||||
<strong>Output:</strong> 4
|
||||
<strong>Explanation:</strong> We can split the array at index 4 to obtain arrays [2,1,3,1,1] and [1,7,1,2,1].
|
||||
In array [2,1,3,1,1], element 1 is dominant since it occurs thrice in the array and 3 * 2 > 5.
|
||||
In array [1,7,1,2,1], element 1 is dominant since it occurs thrice in the array and 3 * 2 > 5.
|
||||
Both [2,1,3,1,1] and [1,7,1,2,1] have the same dominant element as nums, so this is a valid split.
|
||||
It can be shown that index 4 is the minimum index of a valid split.</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [3,3,3,3,7,2,2]
|
||||
<strong>Output:</strong> -1
|
||||
<strong>Explanation:</strong> It can be shown that there is no valid split.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>
|
||||
<li><code>nums</code> has exactly one dominant element.</li>
|
||||
</ul>
|
45
leetcode/problem/number-of-black-blocks.html
Normal file
45
leetcode/problem/number-of-black-blocks.html
Normal file
@ -0,0 +1,45 @@
|
||||
<p>You are given two integers <code>m</code> and <code>n</code> representing the dimensions of a <strong>0-indexed</strong> <code>m x n</code> grid.</p>
|
||||
|
||||
<p>You are also given a <strong>0-indexed</strong> 2D integer matrix <code>coordinates</code>, where <code>coordinates[i] = [x, y]</code> indicates that the cell with coordinates <code>[x, y]</code> is colored <strong>black</strong>. All cells in the grid that do not appear in <code>coordinates</code> are <strong>white</strong>.</p>
|
||||
|
||||
<p>A block is defined as a <code>2 x 2</code> submatrix of the grid. More formally, a block with cell <code>[x, y]</code> as its top-left corner where <code>0 <= x < m - 1</code> and <code>0 <= y < n - 1</code> contains the coordinates <code>[x, y]</code>, <code>[x + 1, y]</code>, <code>[x, y + 1]</code>, and <code>[x + 1, y + 1]</code>.</p>
|
||||
|
||||
<p>Return <em>a <strong>0-indexed</strong> integer array</em> <code>arr</code> <em>of size</em> <code>5</code> <em>such that</em> <code>arr[i]</code> <em>is the number of blocks that contains exactly</em> <code>i</code> <em><strong>black</strong> cells</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> m = 3, n = 3, coordinates = [[0,0]]
|
||||
<strong>Output:</strong> [3,1,0,0,0]
|
||||
<strong>Explanation:</strong> The grid looks like this:
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2023/06/18/screen-shot-2023-06-18-at-44656-am.png" style="width: 150px; height: 128px;" />
|
||||
There is only 1 block with one black cell, and it is the block starting with cell [0,0].
|
||||
The other 3 blocks start with cells [0,1], [1,0] and [1,1]. They all have zero black cells.
|
||||
Thus, we return [3,1,0,0,0].
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> m = 3, n = 3, coordinates = [[0,0],[1,1],[0,2]]
|
||||
<strong>Output:</strong> [0,2,2,0,0]
|
||||
<strong>Explanation:</strong> The grid looks like this:
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2023/06/18/screen-shot-2023-06-18-at-45018-am.png" style="width: 150px; height: 128px;" />
|
||||
There are 2 blocks with two black cells (the ones starting with cell coordinates [0,0] and [0,1]).
|
||||
The other 2 blocks have starting cell coordinates of [1,0] and [1,1]. They both have 1 black cell.
|
||||
Therefore, we return [0,2,2,0,0].
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= m <= 10<sup>5</sup></code></li>
|
||||
<li><code>2 <= n <= 10<sup>5</sup></code></li>
|
||||
<li><code>0 <= coordinates.length <= 10<sup>4</sup></code></li>
|
||||
<li><code>coordinates[i].length == 2</code></li>
|
||||
<li><code>0 <= coordinates[i][0] < m</code></li>
|
||||
<li><code>0 <= coordinates[i][1] < n</code></li>
|
||||
<li>It is guaranteed that <code>coordinates</code> contains pairwise distinct coordinates.</li>
|
||||
</ul>
|
@ -0,0 +1,50 @@
|
||||
<p>Given a binary string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that each substring is <strong>beautiful</strong>.</p>
|
||||
|
||||
<p>A string is <strong>beautiful</strong> if:</p>
|
||||
|
||||
<ul>
|
||||
<li>It doesn't contain leading zeros.</li>
|
||||
<li>It's the <strong>binary</strong> representation of a number that is a power of <code>5</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the <strong>minimum</strong> number of substrings in such partition. </em>If it is impossible to partition the string <code>s</code> into beautiful substrings, return <code>-1</code>.</p>
|
||||
|
||||
<p>A <strong>substring</strong> is a contiguous sequence of characters in a string.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "1011"
|
||||
<strong>Output:</strong> 2
|
||||
<strong>Explanation:</strong> We can paritition the given string into ["101", "1"].
|
||||
- The string "101" does not contain leading zeros and is the binary representation of integer 5<sup>1</sup> = 5.
|
||||
- The string "1" does not contain leading zeros and is the binary representation of integer 5<sup>0</sup> = 1.
|
||||
It can be shown that 2 is the minimum number of beautiful substrings that s can be partitioned into.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "111"
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> We can paritition the given string into ["1", "1", "1"].
|
||||
- The string "1" does not contain leading zeros and is the binary representation of integer 5<sup>0</sup> = 1.
|
||||
It can be shown that 3 is the minimum number of beautiful substrings that s can be partitioned into.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "0"
|
||||
<strong>Output:</strong> -1
|
||||
<strong>Explanation:</strong> We can not partition the given string into beautiful substrings.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= s.length <= 15</code></li>
|
||||
<li><code>s[i]</code> is either <code>'0'</code> or <code>'1'</code>.</li>
|
||||
</ul>
|
46
leetcode/problem/relocate-marbles.html
Normal file
46
leetcode/problem/relocate-marbles.html
Normal file
@ -0,0 +1,46 @@
|
||||
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> representing the initial positions of some marbles. You are also given two <strong>0-indexed </strong>integer arrays <code>moveFrom</code> and <code>moveTo</code> of <strong>equal</strong> length.</p>
|
||||
|
||||
<p>Throughout <code>moveFrom.length</code> steps, you will change the positions of the marbles. On the <code>i<sup>th</sup></code> step, you will move <strong>all</strong> marbles at position <code>moveFrom[i]</code> to position <code>moveTo[i]</code>.</p>
|
||||
|
||||
<p>After completing all the steps, return <em>the sorted list of <strong>occupied</strong> positions</em>.</p>
|
||||
|
||||
<p><strong>Notes:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>We call a position <strong>occupied</strong> if there is at least one marble in that position.</li>
|
||||
<li>There may be multiple marbles in a single position.</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,6,7,8], moveFrom = [1,7,2], moveTo = [2,9,5]
|
||||
<strong>Output:</strong> [5,6,8,9]
|
||||
<strong>Explanation:</strong> Initially, the marbles are at positions 1,6,7,8.
|
||||
At the i = 0th step, we move the marbles at position 1 to position 2. Then, positions 2,6,7,8 are occupied.
|
||||
At the i = 1st step, we move the marbles at position 7 to position 9. Then, positions 2,6,8,9 are occupied.
|
||||
At the i = 2nd step, we move the marbles at position 2 to position 5. Then, positions 5,6,8,9 are occupied.
|
||||
At the end, the final positions containing at least one marbles are [5,6,8,9].</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,1,3,3], moveFrom = [1,3], moveTo = [2,2]
|
||||
<strong>Output:</strong> [2]
|
||||
<strong>Explanation:</strong> Initially, the marbles are at positions [1,1,3,3].
|
||||
At the i = 0th step, we move all the marbles at position 1 to position 2. Then, the marbles are at positions [2,2,3,3].
|
||||
At the i = 1st step, we move all the marbles at position 3 to position 2. Then, the marbles are at positions [2,2,2,2].
|
||||
Since 2 is the only occupied position, we return [2].
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= moveFrom.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>moveFrom.length == moveTo.length</code></li>
|
||||
<li><code>1 <= nums[i], moveFrom[i], moveTo[i] <= 10<sup>9</sup></code></li>
|
||||
<li>The test cases are generated such that there is at least a marble in <code>moveFrom[i]</code> at the moment we want to apply the <code>i<sup>th</sup></code> move.</li>
|
||||
</ul>
|
32
leetcode/problem/sum-of-squares-of-special-elements.html
Normal file
32
leetcode/problem/sum-of-squares-of-special-elements.html
Normal file
@ -0,0 +1,32 @@
|
||||
<p>You are given a <strong>1-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p>
|
||||
|
||||
<p>An element <code>nums[i]</code> of <code>nums</code> is called <strong>special</strong> if <code>i</code> divides <code>n</code>, i.e. <code>n % i == 0</code>.</p>
|
||||
|
||||
<p>Return <em>the <strong>sum of the squares</strong> of all <strong>special</strong> elements of </em><code>nums</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,2,3,4]
|
||||
<strong>Output:</strong> 21
|
||||
<strong>Explanation:</strong> There are exactly 3 special elements in nums: nums[1] since 1 divides 4, nums[2] since 2 divides 4, and nums[4] since 4 divides 4.
|
||||
Hence, the sum of the squares of all special elements of nums is nums[1] * nums[1] + nums[2] * nums[2] + nums[4] * nums[4] = 1 * 1 + 2 * 2 + 4 * 4 = 21.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [2,7,1,19,18,3]
|
||||
<strong>Output:</strong> 63
|
||||
<strong>Explanation:</strong> There are exactly 4 special elements in nums: nums[1] since 1 divides 6, nums[2] since 2 divides 6, nums[3] since 3 divides 6, and nums[6] since 6 divides 6.
|
||||
Hence, the sum of the squares of all special elements of nums is nums[1] * nums[1] + nums[2] * nums[2] + nums[3] * nums[3] + nums[6] * nums[6] = 2 * 2 + 7 * 7 + 1 * 1 + 3 * 3 = 63.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length == n <= 50</code></li>
|
||||
<li><code>1 <= nums[i] <= 50</code></li>
|
||||
</ul>
|
Loading…
Reference in New Issue
Block a user