mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
Compare commits
2 Commits
e171f2875e
...
9eb643f137
Author | SHA1 | Date | |
---|---|---|---|
9eb643f137 | |||
3a7fe98f11 |
@ -1,6 +1,6 @@
|
||||
# 力扣题库(完整版)
|
||||
|
||||
> 最后更新日期: **2023.08.11**
|
||||
> 最后更新日期: **2023.08.20**
|
||||
>
|
||||
> 使用脚本前请务必仔细完整阅读本 `README.md` 文件
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
46
leetcode-cn/originData/[no content]deep-object-filter.json
Normal file
46
leetcode-cn/originData/[no content]deep-object-filter.json
Normal file
@ -0,0 +1,46 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2912",
|
||||
"questionFrontendId": "2823",
|
||||
"categoryTitle": "JavaScript",
|
||||
"boundTopicId": 2393590,
|
||||
"title": "Deep Object Filter",
|
||||
"titleSlug": "deep-object-filter",
|
||||
"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\": \"15\", \"totalSubmission\": \"42\", \"totalAcceptedRaw\": 15, \"totalSubmissionRaw\": 42, \"acRate\": \"35.7%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "[-5,-4,-3,-2,-1,0,1]\n(x) => x > 0",
|
||||
"metaData": "{\n \"name\": \"deepFilter\",\n \"params\": [\n {\n \"name\": \"obj\",\n \"type\": \"string\"\n },\n {\n \"type\": \"string\",\n \"name\": \"fn\"\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": "[-5,-4,-3,-2,-1,0,1]\n(x) => x > 0\n{\"a\":1,\"b\":\"2\",\"c\":3,\"d\":\"4\",\"e\":5,\"f\":6,\"g\":{\"a\":1}}\n(x) => typeof x === \"string\"\n[-1,[-1,-1,5,-1,10],-1,[-1],[-5]]\n(x) => x > 0\n[[[[5]]]]\n(x) => Array.isArray(x)",
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2909",
|
||||
"questionFrontendId": "2821",
|
||||
"categoryTitle": "JavaScript",
|
||||
"boundTopicId": 2393591,
|
||||
"title": "Delay the Resolution of Each Promise",
|
||||
"titleSlug": "delay-the-resolution-of-each-promise",
|
||||
"content": null,
|
||||
"translatedTitle": "延迟每个 Promise 对象的解析",
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Easy",
|
||||
"likes": 0,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"contributors": [],
|
||||
"langToValidPlayground": null,
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"23\", \"totalSubmission\": \"33\", \"totalAcceptedRaw\": 23, \"totalSubmissionRaw\": 33, \"acRate\": \"69.7%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "[() => new Promise((resolve) => setTimeout(resolve, 30))]\n50",
|
||||
"metaData": "{\n \"name\": \"delayAll\",\n \"params\": [\n {\n \"name\": \"functions\",\n \"type\": \"string\"\n },\n {\n \"type\": \"integer\",\n \"name\": \"ms\"\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": "[() => new Promise((resolve) => setTimeout(resolve, 30))]\n50\n[() => new Promise((resolve) => setTimeout(resolve, 50)),() => new Promise((resolve) => setTimeout(resolve, 80))]\n70",
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
59
leetcode-cn/originData/[no content]election-results.json
Normal file
59
leetcode-cn/originData/[no content]election-results.json
Normal file
@ -0,0 +1,59 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "3078",
|
||||
"questionFrontendId": "2820",
|
||||
"categoryTitle": "Database",
|
||||
"boundTopicId": 2392746,
|
||||
"title": "Election Results",
|
||||
"titleSlug": "election-results",
|
||||
"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\": \"28\", \"totalSubmission\": \"36\", \"totalAcceptedRaw\": 28, \"totalSubmissionRaw\": 36, \"acRate\": \"77.8%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\":{\"Votes\":[\"voter\",\"candidate\"]},\"rows\":{\"Votes\":[[\"Kathy\",null],[\"Charles\",\"Ryan\"],[\"Charles\",\"Christine\"],[\"Charles\",\"Kathy\"],[\"Benjamin\",\"Christine\"],[\"Anthony\",\"Ryan\"],[\"Edward\",\"Ryan\"],[\"Terry\",null],[\"Evelyn\",\"Kathy\"],[\"Arthur\",\"Christine\"]]}}",
|
||||
"metaData": "{\"mysql\":[\"Create table if not exists Votes(voter varchar(30), candidate varchar(30))\"],\"mssql\":[\"Create table Votes(voter varchar(30),candidate varchar(30))\"],\"oraclesql\":[\"Create table Votes(voter varchar(30),candidate varchar(30))\"],\"database\":true,\"languages\":[\"mysql\",\"mssql\",\"oraclesql\"],\"database_schema\":{\"Votes\":{\"voter\":\"VARCHAR(30)\",\"candidate\":\"VARCHAR(30)\"}}}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Create table if not exists Votes(voter varchar(30), candidate varchar(30))",
|
||||
"Truncate table Votes",
|
||||
"insert into Votes (voter, candidate) values ('Kathy', 'None')",
|
||||
"insert into Votes (voter, candidate) values ('Charles', 'Ryan')",
|
||||
"insert into Votes (voter, candidate) values ('Charles', 'Christine')",
|
||||
"insert into Votes (voter, candidate) values ('Charles', 'Kathy')",
|
||||
"insert into Votes (voter, candidate) values ('Benjamin', 'Christine')",
|
||||
"insert into Votes (voter, candidate) values ('Anthony', 'Ryan')",
|
||||
"insert into Votes (voter, candidate) values ('Edward', 'Ryan')",
|
||||
"insert into Votes (voter, candidate) values ('Terry', 'None')",
|
||||
"insert into Votes (voter, candidate) values ('Evelyn', 'Kathy')",
|
||||
"insert into Votes (voter, candidate) values ('Arthur', 'Christine')"
|
||||
],
|
||||
"enableRunCode": true,
|
||||
"envInfo": "{\"mysql\":[\"MySQL\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"]}",
|
||||
"book": null,
|
||||
"isSubscribed": false,
|
||||
"isDailyQuestion": false,
|
||||
"dailyRecordStatus": null,
|
||||
"editorType": "CKEDITOR",
|
||||
"ugcQuestionId": null,
|
||||
"style": "LEETCODE",
|
||||
"exampleTestcases": "{\"headers\":{\"Votes\":[\"voter\",\"candidate\"]},\"rows\":{\"Votes\":[[\"Kathy\",null],[\"Charles\",\"Ryan\"],[\"Charles\",\"Christine\"],[\"Charles\",\"Kathy\"],[\"Benjamin\",\"Christine\"],[\"Anthony\",\"Ryan\"],[\"Edward\",\"Ryan\"],[\"Terry\",null],[\"Evelyn\",\"Kathy\"],[\"Arthur\",\"Christine\"]]}}",
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
46
leetcode-cn/originData/[no content]inversion-of-object.json
Normal file
46
leetcode-cn/originData/[no content]inversion-of-object.json
Normal file
@ -0,0 +1,46 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2925",
|
||||
"questionFrontendId": "2822",
|
||||
"categoryTitle": "JavaScript",
|
||||
"boundTopicId": 2393589,
|
||||
"title": "Inversion of Object",
|
||||
"titleSlug": "inversion-of-object",
|
||||
"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\": \"23\", \"totalSubmission\": \"33\", \"totalAcceptedRaw\": 23, \"totalSubmissionRaw\": 33, \"acRate\": \"69.7%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"a\": \"1\",\"b\": \"2\",\"c\": \"3\",\"d\": \"4\" }",
|
||||
"metaData": "{\n \"name\": \"invertObject\",\n \"params\": [\n {\n \"name\": \"obj\",\n \"type\": \"string\"\n }\n ],\n \"return\": {\n \"type\": \"integer\"\n },\n \"languages\": [\n \"typescript\",\n \"javascript\"\n ],\n \"manual\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [],
|
||||
"enableRunCode": true,
|
||||
"envInfo": "{\"javascript\":[\"JavaScript\",\"<p>\\u7248\\u672c\\uff1a<code>Node.js 16.13.2<\\/code><\\/p>\\r\\n\\r\\n<p>\\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a <code>--harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f <a href=\\\"http:\\/\\/node.green\\/\\\" target=\\\"_blank\\\">\\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"],\"typescript\":[\"TypeScript\",\"<p>TypeScript 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\": \"1\",\"b\": \"2\",\"c\": \"3\",\"d\": \"4\" }\n{\"a\": \"1\",\"b\": \"2\",\"c\": \"2\",\"d\": \"4\" }\n[\"1\",\"2\",\"3\",\"4\"]",
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,70 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "3097",
|
||||
"questionFrontendId": "2837",
|
||||
"categoryTitle": "Database",
|
||||
"boundTopicId": 2415741,
|
||||
"title": "Total Traveled Distance",
|
||||
"titleSlug": "total-traveled-distance",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Easy",
|
||||
"likes": 0,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"contributors": [],
|
||||
"langToValidPlayground": null,
|
||||
"topicTags": [
|
||||
{
|
||||
"name": "Database",
|
||||
"slug": "database",
|
||||
"translatedName": "数据库",
|
||||
"__typename": "TopicTagNode"
|
||||
}
|
||||
],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"32\", \"totalSubmission\": \"42\", \"totalAcceptedRaw\": 32, \"totalSubmissionRaw\": 42, \"acRate\": \"76.2%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\":{\"Users\":[\"user_id\",\"name\"],\"Rides\":[\"ride_id\",\"user_id\",\"distance\"]},\"rows\":{\"Users\":[[17,\"Addison\"],[14,\"Ethan\"],[4,\"Michael\"],[2,\"Avery\"],[10,\"Eleanor\"]],\"Rides\":[[72,17,160],[42,14,161],[45,4,59],[32,2,197],[15,4,357],[56,2,196],[10,14,25]]}}",
|
||||
"metaData": "{\"mysql\":[\"Create table if not exists Users(user_id int, name varchar(30))\",\"Create table if not exists Rides(ride_id int,user_id int, distance int)\"],\"mssql\":[\"Create table Users(user_id int, name varchar(30))\",\"Create table Rides(ride_id int,user_id int, distance int)\"],\"oraclesql\":[\"Create table Users(user_id int, name varchar(30))\",\"Create table Rides(ride_id int,user_id int, distance int)\"],\"database\":true,\"name\":\"get_total_distance\",\"pythondata\":[\"Users = pd.DataFrame([], columns=['user_id', 'name']).astype({'user_id':'Int64', 'name':'object'})\",\"Rides = pd.DataFrame([], columns=['ride_id', 'user_id', 'distance']).astype({'ride_id':'Int64', 'user_id':'Int64', 'distance':'Int64'})\"],\"database_schema\":{\"Users\":{\"user_id\":\"INT\",\"name\":\"VARCHAR(30)\"},\"Rides\":{\"ride_id\":\"INT\",\"user_id\":\"INT\",\"distance\":\"INT\"}}}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Create table if not exists Users(user_id int, name varchar(30))",
|
||||
"Create table if not exists Rides(ride_id int,user_id int, distance int)",
|
||||
"Truncate table Users",
|
||||
"insert into Users (user_id, name) values ('17', 'Addison')",
|
||||
"insert into Users (user_id, name) values ('14', 'Ethan')",
|
||||
"insert into Users (user_id, name) values ('4', 'Michael')",
|
||||
"insert into Users (user_id, name) values ('2', 'Avery')",
|
||||
"insert into Users (user_id, name) values ('10', 'Eleanor')",
|
||||
"Truncate table Rides",
|
||||
"insert into Rides (ride_id, user_id, distance) values ('72', '17', '160')",
|
||||
"insert into Rides (ride_id, user_id, distance) values ('42', '14', '161')",
|
||||
"insert into Rides (ride_id, user_id, distance) values ('45', '4', '59')",
|
||||
"insert into Rides (ride_id, user_id, distance) values ('32', '2', '197')",
|
||||
"insert into Rides (ride_id, user_id, distance) values ('15', '4', '357')",
|
||||
"insert into Rides (ride_id, user_id, distance) values ('56', '2', '196')",
|
||||
"insert into Rides (ride_id, user_id, distance) values ('10', '14', '25')"
|
||||
],
|
||||
"enableRunCode": true,
|
||||
"envInfo": "{\"mysql\":[\"MySQL\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"]}",
|
||||
"book": null,
|
||||
"isSubscribed": false,
|
||||
"isDailyQuestion": false,
|
||||
"dailyRecordStatus": null,
|
||||
"editorType": "CKEDITOR",
|
||||
"ugcQuestionId": null,
|
||||
"style": "LEETCODE",
|
||||
"exampleTestcases": "{\"headers\":{\"Users\":[\"user_id\",\"name\"],\"Rides\":[\"ride_id\",\"user_id\",\"distance\"]},\"rows\":{\"Users\":[[17,\"Addison\"],[14,\"Ethan\"],[4,\"Michael\"],[2,\"Avery\"],[10,\"Eleanor\"]],\"Rides\":[[72,17,160],[42,14,161],[45,4,59],[32,2,197],[15,4,357],[56,2,196],[10,14,25]]}}",
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
205
leetcode-cn/originData/apply-operations-to-maximize-score.json
Normal file
205
leetcode-cn/originData/apply-operations-to-maximize-score.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
File diff suppressed because one or more lines are too long
166
leetcode-cn/originData/find-the-longest-equal-subarray.json
Normal file
166
leetcode-cn/originData/find-the-longest-equal-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
177
leetcode-cn/originData/furthest-point-from-origin.json
Normal file
177
leetcode-cn/originData/furthest-point-from-origin.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/max-pair-sum-in-an-array.json
Normal file
176
leetcode-cn/originData/max-pair-sum-in-an-array.json
Normal file
File diff suppressed because one or more lines are too long
165
leetcode-cn/originData/maximize-the-profit-as-the-salesman.json
Normal file
165
leetcode-cn/originData/maximize-the-profit-as-the-salesman.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
File diff suppressed because one or more lines are too long
165
leetcode-cn/originData/sorting-three-groups.json
Normal file
165
leetcode-cn/originData/sorting-three-groups.json
Normal file
File diff suppressed because one or more lines are too long
@ -0,0 +1,33 @@
|
||||
<p>给你两个整数 <code>n</code> 和 <code>k</code> 。</p>
|
||||
|
||||
<p>对于一个由 <strong>不同</strong> 正整数组成的数组,如果其中不存在任何求和等于 k 的不同元素对,则称其为 <strong>k-avoiding</strong> 数组。</p>
|
||||
|
||||
<p>返回长度为 <code>n</code> 的 <strong>k-avoiding</strong> 数组的可能的最小总和。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>n = 5, k = 4
|
||||
<strong>输出:</strong>18
|
||||
<strong>解释:</strong>设若 k-avoiding 数组为 [1,2,4,5,6] ,其元素总和为 18 。
|
||||
可以证明不存在总和小于 18 的 k-avoiding 数组。
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>n = 2, k = 6
|
||||
<strong>输出:</strong>3
|
||||
<strong>解释:</strong>可以构造数组 [1,2] ,其元素总和为 3 。
|
||||
可以证明不存在总和小于 3 的 k-avoiding 数组。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n, k <= 50</code></li>
|
||||
</ul>
|
@ -0,0 +1,54 @@
|
||||
<p>给你一个下标从 <strong>0</strong> 开始的数组 <code>nums</code> ,它包含 <strong>非负</strong> 整数,且全部为 <code>2</code> 的幂,同时给你一个整数 <code>target</code> 。</p>
|
||||
|
||||
<p>一次操作中,你必须对数组做以下修改:</p>
|
||||
|
||||
<ul>
|
||||
<li>选择数组中一个元素 <code>nums[i]</code> ,满足 <code>nums[i] > 1</code> 。</li>
|
||||
<li>将 <code>nums[i]</code> 从数组中删除。</li>
|
||||
<li>在 <code>nums</code> 的 <strong>末尾</strong> 添加 <strong>两个</strong> 数,值都为 <code>nums[i] / 2</code> 。</li>
|
||||
</ul>
|
||||
|
||||
<p>你的目标是让 <code>nums</code> 的一个 <strong>子序列</strong> 的元素和等于 <code>target</code> ,请你返回达成这一目标的 <strong>最少操作次数</strong> 。如果无法得到这样的子序列,请你返回 <code>-1</code> 。</p>
|
||||
|
||||
<p>数组中一个 <strong>子序列</strong> 是通过删除原数组中一些元素,并且不改变剩余元素顺序得到的剩余数组。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>nums = [1,2,8], target = 7
|
||||
<b>输出:</b>1
|
||||
<b>解释:</b>第一次操作中,我们选择元素 nums[2] 。数组变为 nums = [1,2,4,4] 。
|
||||
这时候,nums 包含子序列 [1,2,4] ,和为 7 。
|
||||
无法通过更少的操作得到和为 7 的子序列。
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>nums = [1,32,1,2], target = 12
|
||||
<b>输出:</b>2
|
||||
<b>解释:</b>第一次操作中,我们选择元素 nums[1] 。数组变为 nums = [1,1,2,16,16] 。
|
||||
第二次操作中,我们选择元素 nums[3] 。数组变为 nums = [1,1,2,16,8,8] 。
|
||||
这时候,nums 包含子序列 [1,1,2,8] ,和为 12 。
|
||||
无法通过更少的操作得到和为 12 的子序列。</pre>
|
||||
|
||||
<p><strong class="example">示例 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>nums = [1,32,1], target = 35
|
||||
<b>输出:</b>-1
|
||||
<b>解释:</b>无法得到和为 35 的子序列。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 1000</code></li>
|
||||
<li><code>1 <= nums[i] <= 2<sup>30</sup></code></li>
|
||||
<li><code>nums</code> 只包含非负整数,且均为 2 的幂。</li>
|
||||
<li><code>1 <= target < 2<sup>31</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,45 @@
|
||||
<p>给你一个字符串数组 <code>words</code> 和一个字符串 <code>s</code> ,请你判断 <code>s</code> 是不是 <code>words</code> 的 <strong>首字母缩略词</strong> 。</p>
|
||||
|
||||
<p>如果可以按顺序串联 <code>words</code> 中每个字符串的第一个字符形成字符串 <code>s</code> ,则认为 <code>s</code> 是 <code>words</code> 的首字母缩略词。例如,<code>"ab"</code> 可以由 <code>["apple", "banana"]</code> 形成,但是无法从 <code>["bear", "aardvark"]</code> 形成。</p>
|
||||
|
||||
<p>如果 <code>s</code> 是 <code>words</code> 的首字母缩略词,返回 <code>true</code><em> </em>;否则,返回<em> </em><code>false</code> 。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>words = ["alice","bob","charlie"], s = "abc"
|
||||
<strong>输出:</strong>true
|
||||
<strong>解释:</strong>words 中 "alice"、"bob" 和 "charlie" 的第一个字符分别是 'a'、'b' 和 'c'。因此,s = "abc" 是首字母缩略词。
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>words = ["an","apple"], s = "a"
|
||||
<strong>输出:</strong>false
|
||||
<strong>解释:</strong>words 中 "an" 和 "apple" 的第一个字符分别是 'a' 和 'a'。
|
||||
串联这些字符形成的首字母缩略词是 "aa" 。
|
||||
因此,s = "a" 不是首字母缩略词。
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">示例 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>words = ["never","gonna","give","up","on","you"], s = "ngguoy"
|
||||
<strong>输出:</strong>true
|
||||
<strong>解释:</strong>串联数组 words 中每个字符串的第一个字符,得到字符串 "ngguoy" 。
|
||||
因此,s = "ngguoy" 是首字母缩略词。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= words.length <= 100</code></li>
|
||||
<li><code>1 <= words[i].length <= 10</code></li>
|
||||
<li><code>1 <= s.length <= 100</code></li>
|
||||
<li><code>words[i]</code> 和 <code>s</code> 由小写英文字母组成</li>
|
||||
</ul>
|
@ -0,0 +1,127 @@
|
||||
<p>给你一个长度为 <code>n</code> 下标从 <strong>0</strong> 开始的整数数组 <code>receiver</code> 和一个整数 <code>k</code> 。</p>
|
||||
|
||||
<p>总共有 <code>n</code> 名玩家,玩家 <strong>编号</strong> 互不相同,且为 <code>[0, n - 1]</code> 中的整数。这些玩家玩一个传球游戏,<code>receiver[i]</code> 表示编号为 <code>i</code> 的玩家会传球给编号为 <code>receiver[i]</code> 的玩家。玩家可以传球给自己,也就是说 <code>receiver[i]</code> 可能等于 <code>i</code> 。</p>
|
||||
|
||||
<p>你需要从 <code>n</code> 名玩家中选择一名玩家作为游戏开始时唯一手中有球的玩家,球会被传 <strong>恰好</strong> <code>k</code> 次。</p>
|
||||
|
||||
<p>如果选择编号为 <code>x</code> 的玩家作为开始玩家,定义函数 <code>f(x)</code> 表示从编号为 <code>x</code> 的玩家开始,<code>k</code> 次传球内所有接触过球玩家的编号之 <strong>和</strong> ,如果有玩家多次触球,则 <strong>累加多次</strong> 。换句话说, <code>f(x) = x + receiver[x] + receiver[receiver[x]] + ... + receiver<sup>(k)</sup>[x]</code> 。</p>
|
||||
|
||||
<p>你的任务时选择开始玩家 <code>x</code> ,目的是<strong> 最大化</strong> <code>f(x)</code> 。</p>
|
||||
|
||||
<p>请你返回函数的 <strong>最大值</strong> 。</p>
|
||||
|
||||
<p><strong>注意:</strong><code>receiver</code> 可能含有重复元素。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<table border="1" cellspacing="3" style="border-collapse: separate; text-align: center;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th style="padding: 5px; border: 1px solid black;">传递次数</th>
|
||||
<th style="padding: 5px; border: 1px solid black;">传球者编号</th>
|
||||
<th style="padding: 5px; border: 1px solid black;">接球者编号</th>
|
||||
<th style="padding: 5px; border: 1px solid black;">x + 所有接球者编号</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 5px; border: 1px solid black;"> </td>
|
||||
<td style="padding: 5px; border: 1px solid black;"> </td>
|
||||
<td style="padding: 5px; border: 1px solid black;"> </td>
|
||||
<td style="padding: 5px; border: 1px solid black;">2</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 5px; border: 1px solid black;">1</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">2</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">1</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">3</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 5px; border: 1px solid black;">2</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">1</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">0</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">3</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 5px; border: 1px solid black;">3</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">0</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">2</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">5</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 5px; border: 1px solid black;">4</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">2</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">1</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">6</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>receiver = [2,0,1], k = 4
|
||||
<b>输出:</b>6
|
||||
<b>解释:</b>上表展示了从编号为 x = 2 开始的游戏过程。
|
||||
从表中可知,f(2) 等于 6 。
|
||||
6 是能得到最大的函数值。
|
||||
所以输出为 6 。
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<table border="1" cellspacing="3" style="border-collapse: separate; text-align: center;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th style="padding: 5px; border: 1px solid black;">传递次数</th>
|
||||
<th style="padding: 5px; border: 1px solid black;">传球者编号</th>
|
||||
<th style="padding: 5px; border: 1px solid black;">接球者编号</th>
|
||||
<th style="padding: 5px; border: 1px solid black;">x + 所有接球者编号</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 5px; border: 1px solid black;"> </td>
|
||||
<td style="padding: 5px; border: 1px solid black;"> </td>
|
||||
<td style="padding: 5px; border: 1px solid black;"> </td>
|
||||
<td style="padding: 5px; border: 1px solid black;">4</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 5px; border: 1px solid black;">1</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">4</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">3</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">7</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 5px; border: 1px solid black;">2</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">3</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">2</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">9</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 5px; border: 1px solid black;">3</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">2</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">1</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">10</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>receiver = [1,1,1,2,3], k = 3
|
||||
<b>输出:</b>10
|
||||
<b>解释:</b>上表展示了从编号为 x = 4 开始的游戏过程。
|
||||
从表中可知,f(4) 等于 10 。
|
||||
10 是能得到最大的函数值。
|
||||
所以输出为 10 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= receiver.length == n <= 10<sup>5</sup></code></li>
|
||||
<li><code>0 <= receiver[i] <= n - 1</code></li>
|
||||
<li><code>1 <= k <= 10<sup>10</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,65 @@
|
||||
<p>给你一个下标从 <strong>0</strong> 开始长度为 <code>n</code> 的整数数组 <code>nums</code> 。<br />
|
||||
<br />
|
||||
从 <code>0</code> 到 <code>n - 1</code> 的数字被分为编号从 <code>1</code> 到 <code>3</code> 的三个组,数字 <code>i</code> 属于组 <code>nums[i]</code> 。注意,有的组可能是 <strong>空的</strong> 。<br />
|
||||
<br />
|
||||
你可以执行以下操作任意次:</p>
|
||||
|
||||
<ul>
|
||||
<li>选择数字 <code>x</code> 并改变它的组。更正式的,你可以将 <code>nums[x]</code> 改为数字 <code>1</code> 到 <code>3</code> 中的任意一个。</li>
|
||||
</ul>
|
||||
|
||||
<p>你将按照以下过程构建一个新的数组 <code>res</code> :</p>
|
||||
|
||||
<ol>
|
||||
<li>将每个组中的数字分别排序。</li>
|
||||
<li>将组 <code>1</code> ,<code>2</code> 和 <code>3</code> 中的元素 <strong>依次</strong> 连接以得到 <code>res</code> 。</li>
|
||||
</ol>
|
||||
|
||||
<p>如果得到的 <code>res</code> 是 <strong>非递减</strong>顺序的,那么我们称数组 <code>nums</code> 是 <strong>美丽数组</strong> 。</p>
|
||||
|
||||
<p>请你返回将<em> </em><code>nums</code> 变为 <strong>美丽数组</strong> 需要的最少步数。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>nums = [2,1,3,2,1]
|
||||
<b>输出:</b>3
|
||||
<b>解释:</b>以下三步操作是最优方案:
|
||||
1. 将 nums[0] 变为 1 。
|
||||
2. 将 nums[2] 变为 1 。
|
||||
3. 将 nums[3] 变为 1 。
|
||||
执行以上操作后,将每组中的数字排序,组 1 为 [0,1,2,3,4] ,组 2 和组 3 都为空。所以 res 等于 [0,1,2,3,4] ,它是非递减顺序的。
|
||||
三步操作是最少需要的步数。
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>nums = [1,3,2,1,3,3]
|
||||
<b>输出:</b>2
|
||||
<b>解释:</b>以下两步操作是最优方案:
|
||||
1. 将 nums[1] 变为 1 。
|
||||
2. 将 nums[2] 变为 1 。
|
||||
执行以上操作后,将每组中的数字排序,组 1 为 [0,1,2,3] ,组 2 为空,组 3 为 [4,5] 。所以 res 等于 [0,1,2,3,4,5] ,它是非递减顺序的。
|
||||
两步操作是最少需要的步数。
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">示例 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>nums = [2,2,2,2,3,3]
|
||||
<b>输出:</b>0
|
||||
<b>解释:</b>不需要执行任何操作。
|
||||
组 1 为空,组 2 为 [0,1,2,3] ,组 3 为 [4,5] 。所以 res 等于 [0,1,2,3,4,5] ,它是非递减顺序的。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 100</code></li>
|
||||
<li><code>1 <= nums[i] <= 3</code></li>
|
||||
</ul>
|
@ -0,0 +1,46 @@
|
||||
<p>给你一个下标从 <strong>0</strong> 开始的字符串 <code>str1</code> 和 <code>str2</code> 。</p>
|
||||
|
||||
<p>一次操作中,你选择 <code>str1</code> 中的若干下标。对于选中的每一个下标 <code>i</code> ,你将 <code>str1[i]</code> <strong>循环</strong> 递增,变成下一个字符。也就是说 <code>'a'</code> 变成 <code>'b'</code> ,<code>'b'</code> 变成 <code>'c'</code> ,以此类推,<code>'z'</code> 变成 <code>'a'</code> 。</p>
|
||||
|
||||
<p>如果执行以上操作 <strong>至多一次</strong> ,可以让 <code>str2</code> 成为 <code>str1</code> 的子序列,请你返回 <code>true</code> ,否则返回 <code>false</code> 。</p>
|
||||
|
||||
<p><b>注意:</b>一个字符串的子序列指的是从原字符串中删除一些(可以一个字符也不删)字符后,剩下字符按照原本先后顺序组成的新字符串。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>str1 = "abc", str2 = "ad"
|
||||
<b>输出:</b>true
|
||||
<b>解释:</b>选择 str1 中的下标 2 。
|
||||
将 str1[2] 循环递增,得到 'd' 。
|
||||
因此,str1 变成 "abd" 且 str2 现在是一个子序列。所以返回 true 。</pre>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>str1 = "zc", str2 = "ad"
|
||||
<b>输出:</b>true
|
||||
<b>解释:</b>选择 str1 中的下标 0 和 1 。
|
||||
将 str1[0] 循环递增得到 'a' 。
|
||||
将 str1[1] 循环递增得到 'd' 。
|
||||
因此,str1 变成 "ad" 且 str2 现在是一个子序列。所以返回 true 。</pre>
|
||||
|
||||
<p><strong class="example">示例 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>str1 = "ab", str2 = "d"
|
||||
<b>输出:</b>false
|
||||
<b>解释:</b>这个例子中,没法在执行一次操作的前提下,将 str2 变为 str1 的子序列。
|
||||
所以返回 false 。</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= str1.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= str2.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>str1</code> 和 <code>str2</code> 只包含小写英文字母。</li>
|
||||
</ul>
|
@ -0,0 +1,41 @@
|
||||
<p>给你一个下标从 <strong>0</strong> 开始的整数数组 <code>nums</code> 和一个整数 <code>k</code> 。</p>
|
||||
|
||||
<p>如果子数组中所有元素都相等,则认为子数组是一个 <strong>等值子数组</strong> 。注意,空数组是 <strong>等值子数组</strong> 。</p>
|
||||
|
||||
<p>从 <code>nums</code> 中删除最多 <code>k</code> 个元素后,返回可能的最长等值子数组的长度。</p>
|
||||
|
||||
<p><strong>子数组</strong> 是数组中一个连续且可能为空的元素序列。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>nums = [1,3,2,3,1,3], k = 3
|
||||
<strong>输出:</strong>3
|
||||
<strong>解释:</strong>最优的方案是删除下标 2 和下标 4 的元素。
|
||||
删除后,nums 等于 [1, 3, 3, 3] 。
|
||||
最长等值子数组从 i = 1 开始到 j = 3 结束,长度等于 3 。
|
||||
可以证明无法创建更长的等值子数组。
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>nums = [1,1,2,2,1,1], k = 2
|
||||
<strong>输出:</strong>4
|
||||
<strong>解释:</strong>最优的方案是删除下标 2 和下标 3 的元素。
|
||||
删除后,nums 等于 [1, 1, 1, 1] 。
|
||||
数组自身就是等值子数组,长度等于 4 。
|
||||
可以证明无法创建更长的等值子数组。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= nums[i] <= nums.length</code></li>
|
||||
<li><code>0 <= k <= nums.length</code></li>
|
||||
</ul>
|
@ -0,0 +1,53 @@
|
||||
<p>给你两个正整数:<code>n</code> 和 <code>target</code> 。</p>
|
||||
|
||||
<p>如果数组 <code>nums</code> 满足下述条件,则称其为 <strong>美丽数组</strong> 。</p>
|
||||
|
||||
<ul>
|
||||
<li><code>nums.length == n</code>.</li>
|
||||
<li><code>nums</code> 由两两互不相同的正整数组成。</li>
|
||||
<li>在范围 <code>[0, n-1]</code> 内,<strong>不存在 </strong>两个 <strong>不同</strong> 下标 <code>i</code> 和 <code>j</code> ,使得 <code>nums[i] + nums[j] == target</code> 。</li>
|
||||
</ul>
|
||||
|
||||
<p>返回符合条件的美丽数组所可能具备的 <strong>最小</strong> 和。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>n = 2, target = 3
|
||||
<strong>输出:</strong>4
|
||||
<strong>解释:</strong>nums = [1,3] 是美丽数组。
|
||||
- nums 的长度为 n = 2 。
|
||||
- nums 由两两互不相同的正整数组成。
|
||||
- 不存在两个不同下标 i 和 j ,使得 nums[i] + nums[j] == 3 。
|
||||
可以证明 4 是符合条件的美丽数组所可能具备的最小和。</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>n = 3, target = 3
|
||||
<strong>输出:</strong>8
|
||||
<strong>解释:</strong>
|
||||
nums = [1,3,4] 是美丽数组。
|
||||
- nums 的长度为 n = 3 。
|
||||
- nums 由两两互不相同的正整数组成。
|
||||
- 不存在两个不同下标 i 和 j ,使得 nums[i] + nums[j] == 3 。
|
||||
可以证明 8 是符合条件的美丽数组所可能具备的最小和。</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>n = 1, target = 1
|
||||
<strong>输出:</strong>1
|
||||
<strong>解释:</strong>nums = [1] 是美丽数组。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= target <= 10<sup>5</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,51 @@
|
||||
<p>给你一个长度为 <code>n</code> 的正整数数组 <code>nums</code> 和一个整数 <code>k</code> 。</p>
|
||||
|
||||
<p>一开始,你的分数为 <code>1</code> 。你可以进行以下操作至多 <code>k</code> 次,目标是使你的分数最大:</p>
|
||||
|
||||
<ul>
|
||||
<li>选择一个之前没有选过的 <strong>非空</strong> 子数组 <code>nums[l, ..., r]</code> 。</li>
|
||||
<li>从 <code>nums[l, ..., r]</code> 里面选择一个 <strong>质数分数</strong> 最高的元素 <code>x</code> 。如果多个元素质数分数相同且最高,选择下标最小的一个。</li>
|
||||
<li>将你的分数乘以 <code>x</code> 。</li>
|
||||
</ul>
|
||||
|
||||
<p><code>nums[l, ..., r]</code> 表示 <code>nums</code> 中起始下标为 <code>l</code> ,结束下标为 <code>r</code> 的子数组,两个端点都包含。</p>
|
||||
|
||||
<p>一个整数的 <strong>质数分数</strong> 等于 <code>x</code> 不同质因子的数目。比方说, <code>300</code> 的质数分数为 <code>3</code> ,因为 <code>300 = 2 * 2 * 3 * 5 * 5</code> 。</p>
|
||||
|
||||
<p>请你返回进行至多 <code>k</code> 次操作后,可以得到的 <strong>最大分数</strong> 。</p>
|
||||
|
||||
<p>由于答案可能很大,请你将结果对 <code>10<sup>9 </sup>+ 7</code> 取余后返回。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>nums = [8,3,9,3,8], k = 2
|
||||
<b>输出:</b>81
|
||||
<b>解释:</b>进行以下操作可以得到分数 81 :
|
||||
- 选择子数组 nums[2, ..., 2] 。nums[2] 是子数组中唯一的元素。所以我们将分数乘以 nums[2] ,分数变为 1 * 9 = 9 。
|
||||
- 选择子数组 nums[2, ..., 3] 。nums[2] 和 nums[3] 质数分数都为 1 ,但是 nums[2] 下标更小。所以我们将分数乘以 nums[2] ,分数变为 9 * 9 = 81 。
|
||||
81 是可以得到的最高得分。</pre>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>nums = [19,12,14,6,10,18], k = 3
|
||||
<b>输出:</b>4788
|
||||
<b>解释:</b>进行以下操作可以得到分数 4788 :
|
||||
- 选择子数组 nums[0, ..., 0] 。nums[0] 是子数组中唯一的元素。所以我们将分数乘以 nums[0] ,分数变为 1 * 19 = 19 。
|
||||
- 选择子数组 nums[5, ..., 5] 。nums[5] 是子数组中唯一的元素。所以我们将分数乘以 nums[5] ,分数变为 19 * 18 = 342 。
|
||||
- 选择子数组 nums[2, ..., 3] 。nums[2] 和 nums[3] 质数分数都为 2,但是 nums[2] 下标更小。所以我们将分数乘以 nums[2] ,分数变为 342 * 14 = 4788 。
|
||||
4788 是可以得到的最高的分。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length == n <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= nums[i] <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= k <= min(n * (n + 1) / 2, 10<sup>9</sup>)</code></li>
|
||||
</ul>
|
@ -0,0 +1,30 @@
|
||||
<p>给你一个下标从 <strong>0</strong> 开始的整数数组 <code>nums</code> 。请你从 <code>nums</code> 中找出和 <strong>最大</strong> 的一对数,且这两个数数位上最大的数字相等。</p>
|
||||
|
||||
<p>返回最大和,如果不存在满足题意的数字对,返回 <code>-1</code><em> 。</em></p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>nums = [51,71,17,24,42]
|
||||
<strong>输出:</strong>88
|
||||
<strong>解释:</strong>
|
||||
i = 1 和 j = 2 ,nums[i] 和 nums[j] 数位上最大的数字相等,且这一对的总和 71 + 17 = 88 。
|
||||
i = 3 和 j = 4 ,nums[i] 和 nums[j] 数位上最大的数字相等,且这一对的总和 24 + 42 = 66 。
|
||||
可以证明不存在其他数对满足数位上最大的数字相等,所以答案是 88 。</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>nums = [1,2,3,4]
|
||||
<strong>输出:</strong>-1
|
||||
<strong>解释:</strong>不存在数对满足数位上最大的数字相等。
|
||||
</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,41 @@
|
||||
给你一个下标从 <strong>0</strong> 开始长度为 <code>n</code> 的整数数组 <code>nums</code> 和一个整数 <code>target</code> ,请你返回满足 <code>0 <= i < j < n</code> 且 <code>nums[i] + nums[j] < target</code> 的下标对 <code>(i, j)</code> 的数目。
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>nums = [-1,1,2,3,1], target = 2
|
||||
<b>输出:</b>3
|
||||
<b>解释:</b>总共有 3 个下标对满足题目描述:
|
||||
- (0, 1) ,0 < 1 且 nums[0] + nums[1] = 0 < target
|
||||
- (0, 2) ,0 < 2 且 nums[0] + nums[2] = 1 < target
|
||||
- (0, 4) ,0 < 4 且 nums[0] + nums[4] = 0 < target
|
||||
注意 (0, 3) 不计入答案因为 nums[0] + nums[3] 不是严格小于 target 。
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>nums = [-6,2,5,-2,-7,-1,3], target = -2
|
||||
<b>输出:</b>10
|
||||
<b>解释:</b>总共有 10 个下标对满足题目描述:
|
||||
- (0, 1) ,0 < 1 且 nums[0] + nums[1] = -4 < target
|
||||
- (0, 3) ,0 < 3 且 nums[0] + nums[3] = -8 < target
|
||||
- (0, 4) ,0 < 4 且 nums[0] + nums[4] = -13 < target
|
||||
- (0, 5) ,0 < 5 且 nums[0] + nums[5] = -7 < target
|
||||
- (0, 6) ,0 < 6 且 nums[0] + nums[6] = -3 < target
|
||||
- (1, 4) ,1 < 4 且 nums[1] + nums[4] = -5 < target
|
||||
- (3, 4) ,3 < 4 且 nums[3] + nums[4] = -9 < target
|
||||
- (3, 5) ,3 < 5 且 nums[3] + nums[5] = -3 < target
|
||||
- (4, 5) ,4 < 5 且 nums[4] + nums[5] = -8 < target
|
||||
- (4, 6) ,4 < 6 且 nums[4] + nums[6] = -4 < target
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length == n <= 50</code></li>
|
||||
<li><code>-50 <= nums[i], target <= 50</code></li>
|
||||
</ul>
|
@ -0,0 +1,30 @@
|
||||
<p>给你一个 <strong>非空</strong> 链表的头节点 <code>head</code> ,表示一个不含前导零的非负数整数。</p>
|
||||
|
||||
<p>将链表 <strong>翻倍</strong> 后,返回头节点<em> </em><code>head</code><em> </em>。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2023/05/28/example.png" style="width: 401px; height: 81px;" />
|
||||
<pre>
|
||||
<strong>输入:</strong>head = [1,8,9]
|
||||
<strong>输出:</strong>[3,7,8]
|
||||
<strong>解释:</strong>上图中给出的链表,表示数字 189 。返回的链表表示数字 189 * 2 = 378 。</pre>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2023/05/28/example2.png" style="width: 401px; height: 81px;" />
|
||||
<pre>
|
||||
<strong>输入:</strong>head = [9,9,9]
|
||||
<strong>输出:</strong>[1,9,9,8]
|
||||
<strong>解释:</strong>上图中给出的链表,表示数字 999 。返回的链表表示数字 999 * 2 = 1998 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>链表中节点的数目在范围 <code>[1, 10<sup>4</sup>]</code> 内</li>
|
||||
<li><font face="monospace"><code>0 <= Node.val <= 9</code></font></li>
|
||||
<li>生成的输入满足:链表表示一个不含前导零的数字,除了数字 <code>0</code> 本身。</li>
|
||||
</ul>
|
@ -0,0 +1,54 @@
|
||||
<p>给你正整数 <code>low</code> ,<code>high</code> 和 <code>k</code> 。</p>
|
||||
|
||||
<p>如果一个数满足以下两个条件,那么它是 <strong>美丽的</strong> :</p>
|
||||
|
||||
<ul>
|
||||
<li>偶数数位的数目与奇数数位的数目相同。</li>
|
||||
<li>这个整数可以被 <code>k</code> 整除。</li>
|
||||
</ul>
|
||||
|
||||
<p>请你返回范围 <code>[low, high]</code> 中美丽整数的数目。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>low = 10, high = 20, k = 3
|
||||
<b>输出:</b>2
|
||||
<b>解释:</b>给定范围中有 2 个美丽数字:[12,18]
|
||||
- 12 是美丽整数,因为它有 1 个奇数数位和 1 个偶数数位,而且可以被 k = 3 整除。
|
||||
- 18 是美丽整数,因为它有 1 个奇数数位和 1 个偶数数位,而且可以被 k = 3 整除。
|
||||
以下是一些不是美丽整数的例子:
|
||||
- 16 不是美丽整数,因为它不能被 k = 3 整除。
|
||||
- 15 不是美丽整数,因为它的奇数数位和偶数数位的数目不相等。
|
||||
给定范围内总共有 2 个美丽整数。
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>low = 1, high = 10, k = 1
|
||||
<b>输出:</b>1
|
||||
<b>解释:</b>给定范围中有 1 个美丽数字:[10]
|
||||
- 10 是美丽整数,因为它有 1 个奇数数位和 1 个偶数数位,而且可以被 k = 1 整除。
|
||||
给定范围内总共有 1 个美丽整数。
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">示例 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>low = 5, high = 5, k = 2
|
||||
<b>输出:</b>0
|
||||
<b>解释:</b>给定范围中有 0 个美丽数字。
|
||||
- 5 不是美丽整数,因为它的奇数数位和偶数数位的数目不相等。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 < low <= high <= 10<sup>9</sup></code></li>
|
||||
<li><code>0 < k <= 20</code></li>
|
||||
</ul>
|
@ -0,0 +1,45 @@
|
||||
<p>给你一个长度为 <code>n</code> 的字符串 <code>moves</code> ,该字符串仅由字符 <code>'L'</code>、<code>'R'</code> 和 <code>'_'</code> 组成。字符串表示你在一条原点为 <code>0</code> 的数轴上的若干次移动。</p>
|
||||
|
||||
<p>你的初始位置就在原点(<code>0</code>),第 <code>i</code> 次移动过程中,你可以根据对应字符选择移动方向:</p>
|
||||
|
||||
<ul>
|
||||
<li>如果 <code>moves[i] = 'L'</code> 或 <code>moves[i] = '_'</code> ,可以选择向左移动一个单位距离</li>
|
||||
<li>如果 <code>moves[i] = 'R'</code> 或 <code>moves[i] = '_'</code> ,可以选择向右移动一个单位距离</li>
|
||||
</ul>
|
||||
|
||||
<p>移动 <code>n</code> 次之后,请你找出可以到达的距离原点 <strong>最远</strong> 的点,并返回 <strong>从原点到这一点的距离</strong> 。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>moves = "L_RL__R"
|
||||
<strong>输出:</strong>3
|
||||
<strong>解释:</strong>可以到达的距离原点 0 最远的点是 -3 ,移动的序列为 "LLRLLLR" 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>moves = "_R__LL_"
|
||||
<strong>输出:</strong>5
|
||||
<strong>解释:</strong>可以到达的距离原点 0 最远的点是 -5 ,移动的序列为 "LRLLLLL" 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>moves = "_______"
|
||||
<strong>输出:</strong>7
|
||||
<strong>解释:</strong>可以到达的距离原点 0 最远的点是 7 ,移动的序列为 "RRRRRRR" 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= moves.length == n <= 50</code></li>
|
||||
<li><code>moves</code> 仅由字符 <code>'L'</code>、<code>'R'</code> 和 <code>'_'</code> 组成</li>
|
||||
</ul>
|
@ -0,0 +1,42 @@
|
||||
<p>给你一个整数 <code>n</code> 表示数轴上的房屋数量,编号从 <code>0</code> 到 <code>n - 1</code> 。</p>
|
||||
|
||||
<p>另给你一个二维整数数组 <code>offers</code> ,其中 <code>offers[i] = [start<sub>i</sub>, end<sub>i</sub>, gold<sub>i</sub>]</code> 表示第 <code>i</code> 个买家想要以 <code>gold<sub>i</sub></code> 枚金币的价格购买从 <code>start<sub>i</sub></code> 到 <code>end<sub>i</sub></code> 的所有房屋。</p>
|
||||
|
||||
<p>作为一名销售,你需要有策略地选择并销售房屋使自己的收入最大化。</p>
|
||||
|
||||
<p>返回你可以赚取的金币的最大数目。</p>
|
||||
|
||||
<p><strong>注意</strong> 同一所房屋不能卖给不同的买家,并且允许保留一些房屋不进行出售。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>n = 5, offers = [[0,0,1],[0,2,2],[1,3,2]]
|
||||
<strong>输出:</strong>3
|
||||
<strong>解释:</strong>
|
||||
有 5 所房屋,编号从 0 到 4 ,共有 3 个购买要约。
|
||||
将位于 [0,0] 范围内的房屋以 1 金币的价格出售给第 1 位买家,并将位于 [1,3] 范围内的房屋以 2 金币的价格出售给第 3 位买家。
|
||||
可以证明我们最多只能获得 3 枚金币。</pre>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>n = 5, offers = [[0,0,1],[0,2,10],[1,3,2]]
|
||||
<strong>输出:</strong>10
|
||||
<strong>解释:</strong>有 5 所房屋,编号从 0 到 4 ,共有 3 个购买要约。
|
||||
将位于 [0,2] 范围内的房屋以 10 金币的价格出售给第 2 位买家。
|
||||
可以证明我们最多只能获得 10 枚金币。</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= offers.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>offers[i].length == 3</code></li>
|
||||
<li><code>0 <= start<sub>i</sub> <= end<sub>i</sub> <= n - 1</code></li>
|
||||
<li><code>1 <= gold<sub>i</sub> <= 10<sup>3</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,49 @@
|
||||
<p>给你一个下标从 <strong>0</strong> 开始的整数数组 <code>nums</code> 和一个整数 <code>x</code> 。</p>
|
||||
|
||||
<p>请你找到数组中下标距离至少为 <code>x</code> 的两个元素的 <strong>差值绝对值</strong> 的 <strong>最小值</strong> 。</p>
|
||||
|
||||
<p>换言之,请你找到两个下标 <code>i</code> 和 <code>j</code> ,满足 <code>abs(i - j) >= x</code> 且 <code>abs(nums[i] - nums[j])</code> 的值最小。</p>
|
||||
|
||||
<p>请你返回一个整数,表示下标距离至少为 <code>x</code> 的两个元素之间的差值绝对值的 <strong>最小值</strong> 。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><b>示例 1:</b></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>nums = [4,3,2,4], x = 2
|
||||
<b>输出:</b>0
|
||||
<b>解释:</b>我们选择 nums[0] = 4 和 nums[3] = 4 。
|
||||
它们下标距离满足至少为 2 ,差值绝对值为最小值 0 。
|
||||
0 是最优解。
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>nums = [5,3,2,10,15], x = 1
|
||||
<b>输出:</b>1
|
||||
<b>解释:</b>我们选择 nums[1] = 3 和 nums[2] = 2 。
|
||||
它们下标距离满足至少为 1 ,差值绝对值为最小值 1 。
|
||||
1 是最优解。
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">示例 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>nums = [1,2,3,4], x = 3
|
||||
<b>输出:</b>3
|
||||
<strong>解释:</strong>我们选择 nums[0] = 1 和 nums[3] = 4 。
|
||||
它们下标距离满足至少为 3 ,差值绝对值为最小值 3 。
|
||||
3 是最优解。
|
||||
</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>0 <= x < nums.length</code></li>
|
||||
</ul>
|
@ -0,0 +1,31 @@
|
||||
<p>You are given two integers, <code>n</code> and <code>k</code>.</p>
|
||||
|
||||
<p>An array of <strong>distinct</strong> positive integers is called a <b>k-avoiding</b> array if there does not exist any pair of distinct elements that sum to <code>k</code>.</p>
|
||||
|
||||
<p>Return <em>the <strong>minimum</strong> possible sum of a k-avoiding array of length </em><code>n</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 5, k = 4
|
||||
<strong>Output:</strong> 18
|
||||
<strong>Explanation:</strong> Consider the k-avoiding array [1,2,4,5,6], which has a sum of 18.
|
||||
It can be proven that there is no k-avoiding array with a sum less than 18.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 2, k = 6
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> We can construct the array [1,2], which has a sum of 3.
|
||||
It can be proven that there is no k-avoiding array with a sum less than 3.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n, k <= 50</code></li>
|
||||
</ul>
|
@ -0,0 +1,52 @@
|
||||
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of <strong>non-negative</strong> powers of <code>2</code>, and an integer <code>target</code>.</p>
|
||||
|
||||
<p>In one operation, you must apply the following changes to the array:</p>
|
||||
|
||||
<ul>
|
||||
<li>Choose any element of the array <code>nums[i]</code> such that <code>nums[i] > 1</code>.</li>
|
||||
<li>Remove <code>nums[i]</code> from the array.</li>
|
||||
<li>Add <strong>two</strong> occurrences of <code>nums[i] / 2</code> to the <strong>end</strong> of <code>nums</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return the <em><strong>minimum number of operations</strong> you need to perform so that </em><code>nums</code><em> contains a <strong>subsequence</strong> whose elements sum to</em> <code>target</code>. If it is impossible to obtain such a subsequence, return <code>-1</code>.</p>
|
||||
|
||||
<p>A <strong>subsequence</strong> is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,2,8], target = 7
|
||||
<strong>Output:</strong> 1
|
||||
<strong>Explanation:</strong> In the first operation, we choose element nums[2]. The array becomes equal to nums = [1,2,4,4].
|
||||
At this stage, nums contains the subsequence [1,2,4] which sums up to 7.
|
||||
It can be shown that there is no shorter sequence of operations that results in a subsequnce that sums up to 7.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,32,1,2], target = 12
|
||||
<strong>Output:</strong> 2
|
||||
<strong>Explanation:</strong> In the first operation, we choose element nums[1]. The array becomes equal to nums = [1,1,2,16,16].
|
||||
In the second operation, we choose element nums[3]. The array becomes equal to nums = [1,1,2,16,8,8]
|
||||
At this stage, nums contains the subsequence [1,1,2,8] which sums up to 12.
|
||||
It can be shown that there is no shorter sequence of operations that results in a subsequence that sums up to 12.</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,32,1], target = 35
|
||||
<strong>Output:</strong> -1
|
||||
<strong>Explanation:</strong> It can be shown that no sequence of operations results in a subsequence that sums up to 35.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 1000</code></li>
|
||||
<li><code>1 <= nums[i] <= 2<sup>30</sup></code></li>
|
||||
<li><code>nums</code> consists only of non-negative powers of two.</li>
|
||||
<li><code>1 <= target < 2<sup>31</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,43 @@
|
||||
<p>Given an array of strings <code>words</code> and a string <code>s</code>, determine if <code>s</code> is an <strong>acronym</strong> of words.</p>
|
||||
|
||||
<p>The string <code>s</code> is considered an acronym of <code>words</code> if it can be formed by concatenating the <strong>first</strong> character of each string in <code>words</code> <strong>in order</strong>. For example, <code>"ab"</code> can be formed from <code>["apple", "banana"]</code>, but it can't be formed from <code>["bear", "aardvark"]</code>.</p>
|
||||
|
||||
<p>Return <code>true</code><em> if </em><code>s</code><em> is an acronym of </em><code>words</code><em>, and </em><code>false</code><em> otherwise. </em></p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> words = ["alice","bob","charlie"], s = "abc"
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong> The first character in the words "alice", "bob", and "charlie" are 'a', 'b', and 'c', respectively. Hence, s = "abc" is the acronym.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> words = ["an","apple"], s = "a"
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation:</strong> The first character in the words "an" and "apple" are 'a' and 'a', respectively.
|
||||
The acronym formed by concatenating these characters is "aa".
|
||||
Hence, s = "a" is not the acronym.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> words = ["never","gonna","give","up","on","you"], s = "ngguoy"
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation: </strong>By concatenating the first character of the words in the array, we get the string "ngguoy".
|
||||
Hence, s = "ngguoy" is the acronym.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= words.length <= 100</code></li>
|
||||
<li><code>1 <= words[i].length <= 10</code></li>
|
||||
<li><code>1 <= s.length <= 100</code></li>
|
||||
<li><code>words[i]</code> and <code>s</code> consist of lowercase English letters.</li>
|
||||
</ul>
|
@ -0,0 +1,121 @@
|
||||
<p>You are given a <strong>0-indexed</strong> integer array <code>receiver</code> of length <code>n</code> and an integer <code>k</code>.</p>
|
||||
|
||||
<p>There are <code>n</code> players having a <strong>unique id</strong> in the range <code>[0, n - 1]</code> who will play a ball passing game, and <code>receiver[i]</code> is the id of the player who receives passes from the player with id <code>i</code>. Players can pass to themselves, <strong>i.e.</strong> <code>receiver[i]</code> may be equal to <code>i</code>.</p>
|
||||
|
||||
<p>You must choose one of the <code>n</code> players as the starting player for the game, and the ball will be passed <strong>exactly</strong> <code>k</code> times starting from the chosen player.</p>
|
||||
|
||||
<p>For a chosen starting player having id <code>x</code>, we define a function <code>f(x)</code> that denotes the <strong>sum</strong> of <code>x</code> and the <strong>ids</strong> of all players who receive the ball during the <code>k</code> passes, <strong>including repetitions</strong>. In other words, <code>f(x) = x + receiver[x] + receiver[receiver[x]] + ... + receiver<sup>(k)</sup>[x]</code>.</p>
|
||||
|
||||
<p>Your task is to choose a starting player having id <code>x</code> that <strong>maximizes</strong> the value of <code>f(x)</code>.</p>
|
||||
|
||||
<p>Return <em>an integer denoting the <strong>maximum</strong> value of the function.</em></p>
|
||||
|
||||
<p><strong>Note:</strong> <code>receiver</code> may contain duplicates.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<table border="1" cellspacing="3" style="border-collapse: separate; text-align: center;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th style="padding: 5px; border: 1px solid black;">Pass Number</th>
|
||||
<th style="padding: 5px; border: 1px solid black;">Sender ID</th>
|
||||
<th style="padding: 5px; border: 1px solid black;">Receiver ID</th>
|
||||
<th style="padding: 5px; border: 1px solid black;">x + Receiver IDs</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 5px; border: 1px solid black;"> </td>
|
||||
<td style="padding: 5px; border: 1px solid black;"> </td>
|
||||
<td style="padding: 5px; border: 1px solid black;"> </td>
|
||||
<td style="padding: 5px; border: 1px solid black;">2</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 5px; border: 1px solid black;">1</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">2</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">1</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">3</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 5px; border: 1px solid black;">2</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">1</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">0</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">3</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 5px; border: 1px solid black;">3</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">0</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">2</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">5</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 5px; border: 1px solid black;">4</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">2</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">1</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">6</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> receiver = [2,0,1], k = 4
|
||||
<strong>Output:</strong> 6
|
||||
<strong>Explanation:</strong> The table above shows a simulation of the game starting with the player having id x = 2.
|
||||
From the table, f(2) is equal to 6.
|
||||
It can be shown that 6 is the maximum achievable value of the function.
|
||||
Hence, the output is 6.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<table border="1" cellspacing="3" style="border-collapse: separate; text-align: center;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th style="padding: 5px; border: 1px solid black;">Pass Number</th>
|
||||
<th style="padding: 5px; border: 1px solid black;">Sender ID</th>
|
||||
<th style="padding: 5px; border: 1px solid black;">Receiver ID</th>
|
||||
<th style="padding: 5px; border: 1px solid black;">x + Receiver IDs</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 5px; border: 1px solid black;"> </td>
|
||||
<td style="padding: 5px; border: 1px solid black;"> </td>
|
||||
<td style="padding: 5px; border: 1px solid black;"> </td>
|
||||
<td style="padding: 5px; border: 1px solid black;">4</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 5px; border: 1px solid black;">1</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">4</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">3</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">7</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 5px; border: 1px solid black;">2</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">3</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">2</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">9</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 5px; border: 1px solid black;">3</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">2</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">1</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">10</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> receiver = [1,1,1,2,3], k = 3
|
||||
<strong>Output:</strong> 10
|
||||
<strong>Explanation:</strong> The table above shows a simulation of the game starting with the player having id x = 4.
|
||||
From the table, f(4) is equal to 10.
|
||||
It can be shown that 10 is the maximum achievable value of the function.
|
||||
Hence, the output is 10.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= receiver.length == n <= 10<sup>5</sup></code></li>
|
||||
<li><code>0 <= receiver[i] <= n - 1</code></li>
|
||||
<li><code>1 <= k <= 10<sup>10</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,63 @@
|
||||
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.<br />
|
||||
<br />
|
||||
The numbers from <code>0</code> to <code>n - 1</code> are divided into three groups numbered from <code>1</code> to <code>3</code>, where number <code>i</code> belongs to group <code>nums[i]</code>. Notice that some groups may be <strong>empty</strong>.<br />
|
||||
<br />
|
||||
You are allowed to perform this operation any number of times:</p>
|
||||
|
||||
<ul>
|
||||
<li>Pick number <code>x</code> and change its group. More formally, change <code>nums[x]</code> to any number from <code>1</code> to <code>3</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>A new array <code>res</code> is constructed using the following procedure:</p>
|
||||
|
||||
<ol>
|
||||
<li>Sort the numbers in each group independently.</li>
|
||||
<li>Append the elements of groups <code>1</code>, <code>2</code>, and <code>3</code> to <code>res</code> <strong>in this order</strong>.</li>
|
||||
</ol>
|
||||
|
||||
<p>Array <code>nums</code> is called a <strong>beautiful array</strong> if the constructed array <code>res</code> is sorted in <strong>non-decreasing</strong> order.</p>
|
||||
|
||||
<p>Return <em>the <strong>minimum</strong> number of operations to make </em><code>nums</code><em> a <strong>beautiful array</strong></em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [2,1,3,2,1]
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> It's optimal to perform three operations:
|
||||
1. change nums[0] to 1.
|
||||
2. change nums[2] to 1.
|
||||
3. change nums[3] to 1.
|
||||
After performing the operations and sorting the numbers in each group, group 1 becomes equal to [0,1,2,3,4] and group 2 and group 3 become empty. Hence, res is equal to [0,1,2,3,4] which is sorted in non-decreasing order.
|
||||
It can be proven that there is no valid sequence of less than three operations.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,3,2,1,3,3]
|
||||
<strong>Output:</strong> 2
|
||||
<strong>Explanation:</strong> It's optimal to perform two operations:
|
||||
1. change nums[1] to 1.
|
||||
2. change nums[2] to 1.
|
||||
After performing the operations and sorting the numbers in each group, group 1 becomes equal to [0,1,2,3], group 2 becomes empty, and group 3 becomes equal to [4,5]. Hence, res is equal to [0,1,2,3,4,5] which is sorted in non-decreasing order.
|
||||
It can be proven that there is no valid sequence of less than two operations.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [2,2,2,2,3,3]
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong> It's optimal to not perform operations.
|
||||
After sorting the numbers in each group, group 1 becomes empty, group 2 becomes equal to [0,1,2,3] and group 3 becomes equal to [4,5]. Hence, res is equal to [0,1,2,3,4,5] which is sorted in non-decreasing order.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 100</code></li>
|
||||
<li><code>1 <= nums[i] <= 3</code></li>
|
||||
</ul>
|
@ -0,0 +1,44 @@
|
||||
<p>You are given two <strong>0-indexed</strong> strings <code>str1</code> and <code>str2</code>.</p>
|
||||
|
||||
<p>In an operation, you select a <strong>set</strong> of indices in <code>str1</code>, and for each index <code>i</code> in the set, increment <code>str1[i]</code> to the next character <strong>cyclically</strong>. That is <code>'a'</code> becomes <code>'b'</code>, <code>'b'</code> becomes <code>'c'</code>, and so on, and <code>'z'</code> becomes <code>'a'</code>.</p>
|
||||
|
||||
<p>Return <code>true</code> <em>if it is possible to make </em><code>str2</code> <em>a subsequence of </em><code>str1</code> <em>by performing the operation <strong>at most once</strong></em>, <em>and</em> <code>false</code> <em>otherwise</em>.</p>
|
||||
|
||||
<p><strong>Note:</strong> A subsequence of a string is a new string that is formed from the original string by deleting some (possibly none) of the characters without disturbing the relative positions of the remaining characters.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> str1 = "abc", str2 = "ad"
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong> Select index 2 in str1.
|
||||
Increment str1[2] to become 'd'.
|
||||
Hence, str1 becomes "abd" and str2 is now a subsequence. Therefore, true is returned.</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> str1 = "zc", str2 = "ad"
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong> Select indices 0 and 1 in str1.
|
||||
Increment str1[0] to become 'a'.
|
||||
Increment str1[1] to become 'd'.
|
||||
Hence, str1 becomes "ad" and str2 is now a subsequence. Therefore, true is returned.</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> str1 = "ab", str2 = "d"
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation:</strong> In this example, it can be shown that it is impossible to make str2 a subsequence of str1 using the operation at most once.
|
||||
Therefore, false is returned.</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= str1.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= str2.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>str1</code> and <code>str2</code> consist of only lowercase English letters.</li>
|
||||
</ul>
|
@ -0,0 +1,39 @@
|
||||
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> and an integer <code>k</code>.</p>
|
||||
|
||||
<p>A subarray is called <strong>equal</strong> if all of its elements are equal. Note that the empty subarray is an <strong>equal</strong> subarray.</p>
|
||||
|
||||
<p>Return <em>the length of the <strong>longest</strong> possible equal subarray after deleting <strong>at most</strong> </em><code>k</code><em> elements from </em><code>nums</code>.</p>
|
||||
|
||||
<p>A <b>subarray</b> is a contiguous, possibly empty sequence of elements within an array.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,3,2,3,1,3], k = 3
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> It's optimal to delete the elements at index 2 and index 4.
|
||||
After deleting them, nums becomes equal to [1, 3, 3, 3].
|
||||
The longest equal subarray starts at i = 1 and ends at j = 3 with length equal to 3.
|
||||
It can be proven that no longer equal subarrays can be created.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,1,2,2,1,1], k = 2
|
||||
<strong>Output:</strong> 4
|
||||
<strong>Explanation:</strong> It's optimal to delete the elements at index 2 and index 3.
|
||||
After deleting them, nums becomes equal to [1, 1, 1, 1].
|
||||
The array itself is an equal subarray, so the answer is 4.
|
||||
It can be proven that no longer equal subarrays can be created.
|
||||
</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] <= nums.length</code></li>
|
||||
<li><code>0 <= k <= nums.length</code></li>
|
||||
</ul>
|
@ -0,0 +1,52 @@
|
||||
<p>You are given positive integers <code>n</code> and <code>target</code>.</p>
|
||||
|
||||
<p>An array <code>nums</code> is <strong>beautiful</strong> if it meets the following conditions:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>nums.length == n</code>.</li>
|
||||
<li><code>nums</code> consists of pairwise <strong>distinct</strong> <strong>positive</strong> integers.</li>
|
||||
<li>There doesn't exist two <strong>distinct</strong> indices, <code>i</code> and <code>j</code>, in the range <code>[0, n - 1]</code>, such that <code>nums[i] + nums[j] == target</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the <strong>minimum</strong> possible sum that a beautiful array could have</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 2, target = 3
|
||||
<strong>Output:</strong> 4
|
||||
<strong>Explanation:</strong> We can see that nums = [1,3] is beautiful.
|
||||
- The array nums has length n = 2.
|
||||
- The array nums consists of pairwise distinct positive integers.
|
||||
- There doesn't exist two distinct indices, i and j, with nums[i] + nums[j] == 3.
|
||||
It can be proven that 4 is the minimum possible sum that a beautiful array could have.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 3, target = 3
|
||||
<strong>Output:</strong> 8
|
||||
<strong>Explanation:</strong> We can see that nums = [1,3,4] is beautiful.
|
||||
- The array nums has length n = 3.
|
||||
- The array nums consists of pairwise distinct positive integers.
|
||||
- There doesn't exist two distinct indices, i and j, with nums[i] + nums[j] == 3.
|
||||
It can be proven that 8 is the minimum possible sum that a beautiful array could have.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 1, target = 1
|
||||
<strong>Output:</strong> 1
|
||||
<strong>Explanation:</strong> We can see, that nums = [1] is beautiful.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= target <= 10<sup>5</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,49 @@
|
||||
<p>You are given an array <code>nums</code> of <code>n</code> positive integers and an integer <code>k</code>.</p>
|
||||
|
||||
<p>Initially, you start with a score of <code>1</code>. You have to maximize your score by applying the following operation at most <code>k</code> times:</p>
|
||||
|
||||
<ul>
|
||||
<li>Choose any <strong>non-empty</strong> subarray <code>nums[l, ..., r]</code> that you haven't chosen previously.</li>
|
||||
<li>Choose an element <code>x</code> of <code>nums[l, ..., r]</code> with the highest <strong>prime score</strong>. If multiple such elements exist, choose the one with the smallest index.</li>
|
||||
<li>Multiply your score by <code>x</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Here, <code>nums[l, ..., r]</code> denotes the subarray of <code>nums</code> starting at index <code>l</code> and ending at the index <code>r</code>, both ends being inclusive.</p>
|
||||
|
||||
<p>The <strong>prime score</strong> of an integer <code>x</code> is equal to the number of distinct prime factors of <code>x</code>. For example, the prime score of <code>300</code> is <code>3</code> since <code>300 = 2 * 2 * 3 * 5 * 5</code>.</p>
|
||||
|
||||
<p>Return <em>the <strong>maximum possible score</strong> after applying at most </em><code>k</code><em> operations</em>.</p>
|
||||
|
||||
<p>Since the answer may be large, return it modulo <code>10<sup>9 </sup>+ 7</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [8,3,9,3,8], k = 2
|
||||
<strong>Output:</strong> 81
|
||||
<strong>Explanation:</strong> To get a score of 81, we can apply the following operations:
|
||||
- Choose subarray nums[2, ..., 2]. nums[2] is the only element in this subarray. Hence, we multiply the score by nums[2]. The score becomes 1 * 9 = 9.
|
||||
- Choose subarray nums[2, ..., 3]. Both nums[2] and nums[3] have a prime score of 1, but nums[2] has the smaller index. Hence, we multiply the score by nums[2]. The score becomes 9 * 9 = 81.
|
||||
It can be proven that 81 is the highest score one can obtain.</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [19,12,14,6,10,18], k = 3
|
||||
<strong>Output:</strong> 4788
|
||||
<strong>Explanation:</strong> To get a score of 4788, we can apply the following operations:
|
||||
- Choose subarray nums[0, ..., 0]. nums[0] is the only element in this subarray. Hence, we multiply the score by nums[0]. The score becomes 1 * 19 = 19.
|
||||
- Choose subarray nums[5, ..., 5]. nums[5] is the only element in this subarray. Hence, we multiply the score by nums[5]. The score becomes 19 * 18 = 342.
|
||||
- Choose subarray nums[2, ..., 3]. Both nums[2] and nums[3] have a prime score of 2, but nums[2] has the smaller index. Hence, we multipy the score by nums[2]. The score becomes 342 * 14 = 4788.
|
||||
It can be proven that 4788 is the highest score one can obtain.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length == n <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= nums[i] <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= k <= min(n * (n + 1) / 2, 10<sup>9</sup>)</code></li>
|
||||
</ul>
|
@ -0,0 +1,30 @@
|
||||
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to find the <strong>maximum</strong> sum of a pair of numbers from <code>nums</code> such that the maximum <strong>digit </strong>in both numbers are equal.</p>
|
||||
|
||||
<p>Return <em>the maximum sum or</em> <code>-1</code><em> if no such pair exists</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [51,71,17,24,42]
|
||||
<strong>Output:</strong> 88
|
||||
<strong>Explanation:</strong>
|
||||
For i = 1 and j = 2, nums[i] and nums[j] have equal maximum digits with a pair sum of 71 + 17 = 88.
|
||||
For i = 3 and j = 4, nums[i] and nums[j] have equal maximum digits with a pair sum of 24 + 42 = 66.
|
||||
It can be shown that there are no other pairs with equal maximum digits, so the answer is 88.</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,2,3,4]
|
||||
<strong>Output:</strong> -1
|
||||
<strong>Explanation:</strong> No pair exists in nums with equal maximum digits.
|
||||
</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,39 @@
|
||||
Given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code> and an integer <code>target</code>, return <em>the number of pairs</em> <code>(i, j)</code> <em>where</em> <code>0 <= i < j < n</code> <em>and</em> <code>nums[i] + nums[j] < target</code>.
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [-1,1,2,3,1], target = 2
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> There are 3 pairs of indices that satisfy the conditions in the statement:
|
||||
- (0, 1) since 0 < 1 and nums[0] + nums[1] = 0 < target
|
||||
- (0, 2) since 0 < 2 and nums[0] + nums[2] = 1 < target
|
||||
- (0, 4) since 0 < 4 and nums[0] + nums[4] = 0 < target
|
||||
Note that (0, 3) is not counted since nums[0] + nums[3] is not strictly less than the target.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [-6,2,5,-2,-7,-1,3], target = -2
|
||||
<strong>Output:</strong> 10
|
||||
<strong>Explanation:</strong> There are 10 pairs of indices that satisfy the conditions in the statement:
|
||||
- (0, 1) since 0 < 1 and nums[0] + nums[1] = -4 < target
|
||||
- (0, 3) since 0 < 3 and nums[0] + nums[3] = -8 < target
|
||||
- (0, 4) since 0 < 4 and nums[0] + nums[4] = -13 < target
|
||||
- (0, 5) since 0 < 5 and nums[0] + nums[5] = -7 < target
|
||||
- (0, 6) since 0 < 6 and nums[0] + nums[6] = -3 < target
|
||||
- (1, 4) since 1 < 4 and nums[1] + nums[4] = -5 < target
|
||||
- (3, 4) since 3 < 4 and nums[3] + nums[4] = -9 < target
|
||||
- (3, 5) since 3 < 5 and nums[3] + nums[5] = -3 < target
|
||||
- (4, 5) since 4 < 5 and nums[4] + nums[5] = -8 < target
|
||||
- (4, 6) since 4 < 6 and nums[4] + nums[6] = -4 < target
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length == n <= 50</code></li>
|
||||
<li><code>-50 <= nums[i], target <= 50</code></li>
|
||||
</ul>
|
@ -0,0 +1,29 @@
|
||||
<p>You are given the <code>head</code> of a <strong>non-empty</strong> linked list representing a non-negative integer without leading zeroes.</p>
|
||||
|
||||
<p>Return <em>the </em><code>head</code><em> of the linked list after <strong>doubling</strong> it</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2023/05/28/example.png" style="width: 401px; height: 81px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> head = [1,8,9]
|
||||
<strong>Output:</strong> [3,7,8]
|
||||
<strong>Explanation:</strong> The figure above corresponds to the given linked list which represents the number 189. Hence, the returned linked list represents the number 189 * 2 = 378.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2023/05/28/example2.png" style="width: 401px; height: 81px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> head = [9,9,9]
|
||||
<strong>Output:</strong> [1,9,9,8]
|
||||
<strong>Explanation:</strong> The figure above corresponds to the given linked list which represents the number 999. Hence, the returned linked list reprersents the number 999 * 2 = 1998.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>The number of nodes in the list is in the range <code>[1, 10<sup>4</sup>]</code></li>
|
||||
<li><font face="monospace"><code>0 <= Node.val <= 9</code></font></li>
|
||||
<li>The input is generated such that the list represents a number that does not have leading zeros, except the number <code>0</code> itself.</li>
|
||||
</ul>
|
@ -0,0 +1,52 @@
|
||||
<p>You are given positive integers <code>low</code>, <code>high</code>, and <code>k</code>.</p>
|
||||
|
||||
<p>A number is <strong>beautiful</strong> if it meets both of the following conditions:</p>
|
||||
|
||||
<ul>
|
||||
<li>The count of even digits in the number is equal to the count of odd digits.</li>
|
||||
<li>The number is divisible by <code>k</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the number of beautiful integers in the range</em> <code>[low, high]</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> low = 10, high = 20, k = 3
|
||||
<strong>Output:</strong> 2
|
||||
<strong>Explanation:</strong> There are 2 beautiful integers in the given range: [12,18].
|
||||
- 12 is beautiful because it contains 1 odd digit and 1 even digit, and is divisible by k = 3.
|
||||
- 18 is beautiful because it contains 1 odd digit and 1 even digit, and is divisible by k = 3.
|
||||
Additionally we can see that:
|
||||
- 16 is not beautiful because it is not divisible by k = 3.
|
||||
- 15 is not beautiful because it does not contain equal counts even and odd digits.
|
||||
It can be shown that there are only 2 beautiful integers in the given range.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> low = 1, high = 10, k = 1
|
||||
<strong>Output:</strong> 1
|
||||
<strong>Explanation:</strong> There is 1 beautiful integer in the given range: [10].
|
||||
- 10 is beautiful because it contains 1 odd digit and 1 even digit, and is divisible by k = 1.
|
||||
It can be shown that there is only 1 beautiful integer in the given range.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> low = 5, high = 5, k = 2
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong> There are 0 beautiful integers in the given range.
|
||||
- 5 is not beautiful because it is not divisible by k = 2 and it does not contain equal even and odd digits.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 < low <= high <= 10<sup>9</sup></code></li>
|
||||
<li><code>0 < k <= 20</code></li>
|
||||
</ul>
|
@ -0,0 +1,43 @@
|
||||
<p>You are given a string <code>moves</code> of length <code>n</code> consisting only of characters <code>'L'</code>, <code>'R'</code>, and <code>'_'</code>. The string represents your movement on a number line starting from the origin <code>0</code>.</p>
|
||||
|
||||
<p>In the <code>i<sup>th</sup></code> move, you can choose one of the following directions:</p>
|
||||
|
||||
<ul>
|
||||
<li>move to the left if <code>moves[i] = 'L'</code> or <code>moves[i] = '_'</code></li>
|
||||
<li>move to the right if <code>moves[i] = 'R'</code> or <code>moves[i] = '_'</code></li>
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the <strong>distance from the origin</strong> of the <strong>furthest</strong> point you can get to after </em><code>n</code><em> moves</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> moves = "L_RL__R"
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> The furthest point we can reach from the origin 0 is point -3 through the following sequence of moves "LLRLLLR".
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> moves = "_R__LL_"
|
||||
<strong>Output:</strong> 5
|
||||
<strong>Explanation:</strong> The furthest point we can reach from the origin 0 is point -5 through the following sequence of moves "LRLLLLL".
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> moves = "_______"
|
||||
<strong>Output:</strong> 7
|
||||
<strong>Explanation:</strong> The furthest point we can reach from the origin 0 is point 7 through the following sequence of moves "RRRRRRR".
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= moves.length == n <= 50</code></li>
|
||||
<li><code>moves</code> consists only of characters <code>'L'</code>, <code>'R'</code> and <code>'_'</code>.</li>
|
||||
</ul>
|
@ -0,0 +1,41 @@
|
||||
<p>You are given an integer <code>n</code> representing the number of houses on a number line, numbered from <code>0</code> to <code>n - 1</code>.</p>
|
||||
|
||||
<p>Additionally, you are given a 2D integer array <code>offers</code> where <code>offers[i] = [start<sub>i</sub>, end<sub>i</sub>, gold<sub>i</sub>]</code>, indicating that <code>i<sup>th</sup></code> buyer wants to buy all the houses from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> for <code>gold<sub>i</sub></code> amount of gold.</p>
|
||||
|
||||
<p>As a salesman, your goal is to <strong>maximize</strong> your earnings by strategically selecting and selling houses to buyers.</p>
|
||||
|
||||
<p>Return <em>the maximum amount of gold you can earn</em>.</p>
|
||||
|
||||
<p><strong>Note</strong> that different buyers can't buy the same house, and some houses may remain unsold.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 5, offers = [[0,0,1],[0,2,2],[1,3,2]]
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> There are 5 houses numbered from 0 to 4 and there are 3 purchase offers.
|
||||
We sell houses in the range [0,0] to 1<sup>st</sup> buyer for 1 gold and houses in the range [1,3] to 3<sup>rd</sup> buyer for 2 golds.
|
||||
It can be proven that 3 is the maximum amount of gold we can achieve.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 5, offers = [[0,0,1],[0,2,10],[1,3,2]]
|
||||
<strong>Output:</strong> 10
|
||||
<strong>Explanation:</strong> There are 5 houses numbered from 0 to 4 and there are 3 purchase offers.
|
||||
We sell houses in the range [0,2] to 2<sup>nd</sup> buyer for 10 golds.
|
||||
It can be proven that 10 is the maximum amount of gold we can achieve.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= offers.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>offers[i].length == 3</code></li>
|
||||
<li><code>0 <= start<sub>i</sub> <= end<sub>i</sub> <= n - 1</code></li>
|
||||
<li><code>1 <= gold<sub>i</sub> <= 10<sup>3</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,47 @@
|
||||
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> and an integer <code>x</code>.</p>
|
||||
|
||||
<p>Find the <strong>minimum absolute difference</strong> between two elements in the array that are at least <code>x</code> indices apart.</p>
|
||||
|
||||
<p>In other words, find two indices <code>i</code> and <code>j</code> such that <code>abs(i - j) >= x</code> and <code>abs(nums[i] - nums[j])</code> is minimized.</p>
|
||||
|
||||
<p>Return<em> an integer denoting the <strong>minimum</strong> absolute difference between two elements that are at least</em> <code>x</code> <em>indices apart</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [4,3,2,4], x = 2
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong> We can select nums[0] = 4 and nums[3] = 4.
|
||||
They are at least 2 indices apart, and their absolute difference is the minimum, 0.
|
||||
It can be shown that 0 is the optimal answer.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [5,3,2,10,15], x = 1
|
||||
<strong>Output:</strong> 1
|
||||
<strong>Explanation:</strong> We can select nums[1] = 3 and nums[2] = 2.
|
||||
They are at least 1 index apart, and their absolute difference is the minimum, 1.
|
||||
It can be shown that 1 is the optimal answer.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,2,3,4], x = 3
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> We can select nums[0] = 1 and nums[3] = 4.
|
||||
They are at least 3 indices apart, and their absolute difference is the minimum, 3.
|
||||
It can be shown that 3 is the optimal answer.
|
||||
</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>0 <= x < nums.length</code></li>
|
||||
</ul>
|
File diff suppressed because it is too large
Load Diff
43
leetcode/originData/[no content]deep-object-filter.json
Normal file
43
leetcode/originData/[no content]deep-object-filter.json
Normal file
@ -0,0 +1,43 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2912",
|
||||
"questionFrontendId": "2823",
|
||||
"boundTopicId": null,
|
||||
"title": "Deep Object Filter",
|
||||
"titleSlug": "deep-object-filter",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Medium",
|
||||
"likes": 5,
|
||||
"dislikes": 1,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"exampleTestcases": "[-5,-4,-3,-2,-1,0,1]\n(x) => x > 0\n{\"a\":1,\"b\":\"2\",\"c\":3,\"d\":\"4\",\"e\":5,\"f\":6,\"g\":{\"a\":1}}\n(x) => typeof x === \"string\"\n[-1,[-1,-1,5,-1,10],-1,[-1],[-5]]\n(x) => x > 0\n[[[[5]]]]\n(x) => Array.isArray(x)",
|
||||
"categoryTitle": "JavaScript",
|
||||
"contributors": [],
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"40\", \"totalSubmission\": \"67\", \"totalAcceptedRaw\": 40, \"totalSubmissionRaw\": 67, \"acRate\": \"59.7%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "[-5,-4,-3,-2,-1,0,1]\n(x) => x > 0",
|
||||
"metaData": "{\n \"name\": \"deepFilter\",\n \"params\": [\n {\n \"name\": \"obj\",\n \"type\": \"string\"\n },\n {\n \"type\": \"string\",\n \"name\": \"fn\"\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": "2909",
|
||||
"questionFrontendId": "2821",
|
||||
"boundTopicId": null,
|
||||
"title": "Delay the Resolution of Each Promise",
|
||||
"titleSlug": "delay-the-resolution-of-each-promise",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Easy",
|
||||
"likes": 8,
|
||||
"dislikes": 1,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"exampleTestcases": "[() => new Promise((resolve) => setTimeout(resolve, 30))]\n50\n[() => new Promise((resolve) => setTimeout(resolve, 50)),() => new Promise((resolve) => setTimeout(resolve, 80))]\n70",
|
||||
"categoryTitle": "JavaScript",
|
||||
"contributors": [],
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"78\", \"totalSubmission\": \"86\", \"totalAcceptedRaw\": 78, \"totalSubmissionRaw\": 86, \"acRate\": \"90.7%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "[() => new Promise((resolve) => setTimeout(resolve, 30))]\n50",
|
||||
"metaData": "{\n \"name\": \"delayAll\",\n \"params\": [\n {\n \"name\": \"functions\",\n \"type\": \"string\"\n },\n {\n \"type\": \"integer\",\n \"name\": \"ms\"\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"
|
||||
}
|
||||
}
|
||||
}
|
56
leetcode/originData/[no content]election-results.json
Normal file
56
leetcode/originData/[no content]election-results.json
Normal file
@ -0,0 +1,56 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "3078",
|
||||
"questionFrontendId": "2820",
|
||||
"boundTopicId": null,
|
||||
"title": "Election Results",
|
||||
"titleSlug": "election-results",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Medium",
|
||||
"likes": 9,
|
||||
"dislikes": 3,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"exampleTestcases": "{\"headers\":{\"Votes\":[\"voter\",\"candidate\"]},\"rows\":{\"Votes\":[[\"Kathy\",null],[\"Charles\",\"Ryan\"],[\"Charles\",\"Christine\"],[\"Charles\",\"Kathy\"],[\"Benjamin\",\"Christine\"],[\"Anthony\",\"Ryan\"],[\"Edward\",\"Ryan\"],[\"Terry\",null],[\"Evelyn\",\"Kathy\"],[\"Arthur\",\"Christine\"]]}}",
|
||||
"categoryTitle": "Database",
|
||||
"contributors": [],
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"116\", \"totalSubmission\": \"154\", \"totalAcceptedRaw\": 116, \"totalSubmissionRaw\": 154, \"acRate\": \"75.3%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\":{\"Votes\":[\"voter\",\"candidate\"]},\"rows\":{\"Votes\":[[\"Kathy\",null],[\"Charles\",\"Ryan\"],[\"Charles\",\"Christine\"],[\"Charles\",\"Kathy\"],[\"Benjamin\",\"Christine\"],[\"Anthony\",\"Ryan\"],[\"Edward\",\"Ryan\"],[\"Terry\",null],[\"Evelyn\",\"Kathy\"],[\"Arthur\",\"Christine\"]]}}",
|
||||
"metaData": "{\"mysql\": [\"Create table if not exists Votes(voter varchar(30), candidate varchar(30))\"], \"mssql\": [\"Create table Votes(voter varchar(30),candidate varchar(30))\"], \"oraclesql\": [\"Create table Votes(voter varchar(30),candidate varchar(30))\"], \"database\": true, \"languages\": [\"mysql\", \"mssql\", \"oraclesql\"], \"database_schema\": {\"Votes\": {\"voter\": \"VARCHAR(30)\", \"candidate\": \"VARCHAR(30)\"}}}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Create table if not exists Votes(voter varchar(30), candidate varchar(30))",
|
||||
"Truncate table Votes",
|
||||
"insert into Votes (voter, candidate) values ('Kathy', 'None')",
|
||||
"insert into Votes (voter, candidate) values ('Charles', 'Ryan')",
|
||||
"insert into Votes (voter, candidate) values ('Charles', 'Christine')",
|
||||
"insert into Votes (voter, candidate) values ('Charles', 'Kathy')",
|
||||
"insert into Votes (voter, candidate) values ('Benjamin', 'Christine')",
|
||||
"insert into Votes (voter, candidate) values ('Anthony', 'Ryan')",
|
||||
"insert into Votes (voter, candidate) values ('Edward', 'Ryan')",
|
||||
"insert into Votes (voter, candidate) values ('Terry', 'None')",
|
||||
"insert into Votes (voter, candidate) values ('Evelyn', 'Kathy')",
|
||||
"insert into Votes (voter, candidate) values ('Arthur', 'Christine')"
|
||||
],
|
||||
"enableRunCode": true,
|
||||
"enableTestMode": false,
|
||||
"enableDebugger": false,
|
||||
"envInfo": "{\"mysql\": [\"MySQL\", \"<p><code>MySQL 8.0</code>.</p>\"], \"mssql\": [\"MS SQL Server\", \"<p><code>mssql server 2019</code>.</p>\"], \"oraclesql\": [\"Oracle\", \"<p><code>Oracle Sql 11.2</code>.</p>\"]}",
|
||||
"libraryUrl": null,
|
||||
"adminUrl": null,
|
||||
"challengeQuestion": null,
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
43
leetcode/originData/[no content]inversion-of-object.json
Normal file
43
leetcode/originData/[no content]inversion-of-object.json
Normal file
@ -0,0 +1,43 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2925",
|
||||
"questionFrontendId": "2822",
|
||||
"boundTopicId": null,
|
||||
"title": "Inversion of Object",
|
||||
"titleSlug": "inversion-of-object",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Easy",
|
||||
"likes": 7,
|
||||
"dislikes": 1,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"exampleTestcases": "{\"a\": \"1\",\"b\": \"2\",\"c\": \"3\",\"d\": \"4\" }\n{\"a\": \"1\",\"b\": \"2\",\"c\": \"2\",\"d\": \"4\" }\n[\"1\",\"2\",\"3\",\"4\"]",
|
||||
"categoryTitle": "JavaScript",
|
||||
"contributors": [],
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"82\", \"totalSubmission\": \"103\", \"totalAcceptedRaw\": 82, \"totalSubmissionRaw\": 103, \"acRate\": \"79.6%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"a\": \"1\",\"b\": \"2\",\"c\": \"3\",\"d\": \"4\" }",
|
||||
"metaData": "{\n \"name\": \"invertObject\",\n \"params\": [\n {\n \"name\": \"obj\",\n \"type\": \"string\"\n }\n ],\n \"return\": {\n \"type\": \"integer\"\n },\n \"languages\": [\n \"typescript\",\n \"javascript\"\n ],\n \"manual\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [],
|
||||
"enableRunCode": true,
|
||||
"enableTestMode": false,
|
||||
"enableDebugger": false,
|
||||
"envInfo": "{\"javascript\": [\"JavaScript\", \"<p><code>Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES6 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\\r\\n\\r\\n<p>For Priority Queue / Queue data structures, you may use 5.3.0 version of <a href=\\\"https://github.com/datastructures-js/priority-queue/tree/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\">datastructures-js/priority-queue</a> and 4.2.1 version of <a href=\\\"https://github.com/datastructures-js/queue/tree/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\">datastructures-js/queue</a>.</p>\"], \"typescript\": [\"Typescript\", \"<p><code>TypeScript 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
File diff suppressed because one or more lines are too long
67
leetcode/originData/[no content]total-traveled-distance.json
Normal file
67
leetcode/originData/[no content]total-traveled-distance.json
Normal file
@ -0,0 +1,67 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "3097",
|
||||
"questionFrontendId": "2837",
|
||||
"boundTopicId": null,
|
||||
"title": "Total Traveled Distance",
|
||||
"titleSlug": "total-traveled-distance",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Easy",
|
||||
"likes": 6,
|
||||
"dislikes": 2,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"exampleTestcases": "{\"headers\":{\"Users\":[\"user_id\",\"name\"],\"Rides\":[\"ride_id\",\"user_id\",\"distance\"]},\"rows\":{\"Users\":[[17,\"Addison\"],[14,\"Ethan\"],[4,\"Michael\"],[2,\"Avery\"],[10,\"Eleanor\"]],\"Rides\":[[72,17,160],[42,14,161],[45,4,59],[32,2,197],[15,4,357],[56,2,196],[10,14,25]]}}",
|
||||
"categoryTitle": "Database",
|
||||
"contributors": [],
|
||||
"topicTags": [
|
||||
{
|
||||
"name": "Database",
|
||||
"slug": "database",
|
||||
"translatedName": null,
|
||||
"__typename": "TopicTagNode"
|
||||
}
|
||||
],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"215\", \"totalSubmission\": \"270\", \"totalAcceptedRaw\": 215, \"totalSubmissionRaw\": 270, \"acRate\": \"79.6%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\":{\"Users\":[\"user_id\",\"name\"],\"Rides\":[\"ride_id\",\"user_id\",\"distance\"]},\"rows\":{\"Users\":[[17,\"Addison\"],[14,\"Ethan\"],[4,\"Michael\"],[2,\"Avery\"],[10,\"Eleanor\"]],\"Rides\":[[72,17,160],[42,14,161],[45,4,59],[32,2,197],[15,4,357],[56,2,196],[10,14,25]]}}",
|
||||
"metaData": "{\"mysql\": [\"Create table if not exists Users(user_id int, name varchar(30))\", \"Create table if not exists Rides(ride_id int,user_id int, distance int)\"], \"mssql\": [\"Create table Users(user_id int, name varchar(30))\", \"Create table Rides(ride_id int,user_id int, distance int)\"], \"oraclesql\": [\"Create table Users(user_id int, name varchar(30))\", \"Create table Rides(ride_id int,user_id int, distance int)\"], \"database\": true, \"name\": \"get_total_distance\", \"pythondata\": [\"Users = pd.DataFrame([], columns=['user_id', 'name']).astype({'user_id':'Int64', 'name':'object'})\", \"Rides = pd.DataFrame([], columns=['ride_id', 'user_id', 'distance']).astype({'ride_id':'Int64', 'user_id':'Int64', 'distance':'Int64'})\"], \"database_schema\": {\"Users\": {\"user_id\": \"INT\", \"name\": \"VARCHAR(30)\"}, \"Rides\": {\"ride_id\": \"INT\", \"user_id\": \"INT\", \"distance\": \"INT\"}}}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Create table if not exists Users(user_id int, name varchar(30))",
|
||||
"Create table if not exists Rides(ride_id int,user_id int, distance int)",
|
||||
"Truncate table Users",
|
||||
"insert into Users (user_id, name) values ('17', 'Addison')",
|
||||
"insert into Users (user_id, name) values ('14', 'Ethan')",
|
||||
"insert into Users (user_id, name) values ('4', 'Michael')",
|
||||
"insert into Users (user_id, name) values ('2', 'Avery')",
|
||||
"insert into Users (user_id, name) values ('10', 'Eleanor')",
|
||||
"Truncate table Rides",
|
||||
"insert into Rides (ride_id, user_id, distance) values ('72', '17', '160')",
|
||||
"insert into Rides (ride_id, user_id, distance) values ('42', '14', '161')",
|
||||
"insert into Rides (ride_id, user_id, distance) values ('45', '4', '59')",
|
||||
"insert into Rides (ride_id, user_id, distance) values ('32', '2', '197')",
|
||||
"insert into Rides (ride_id, user_id, distance) values ('15', '4', '357')",
|
||||
"insert into Rides (ride_id, user_id, distance) values ('56', '2', '196')",
|
||||
"insert into Rides (ride_id, user_id, distance) values ('10', '14', '25')"
|
||||
],
|
||||
"enableRunCode": true,
|
||||
"enableTestMode": false,
|
||||
"enableDebugger": false,
|
||||
"envInfo": "{\"mysql\": [\"MySQL\", \"<p><code>MySQL 8.0</code>.</p>\"], \"mssql\": [\"MS SQL Server\", \"<p><code>mssql server 2019</code>.</p>\"], \"oraclesql\": [\"Oracle\", \"<p><code>Oracle Sql 11.2</code>.</p>\"], \"pythondata\": [\"Pandas\", \"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0</p>\"]}",
|
||||
"libraryUrl": null,
|
||||
"adminUrl": null,
|
||||
"challengeQuestion": null,
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
202
leetcode/originData/apply-operations-to-maximize-score.json
Normal file
202
leetcode/originData/apply-operations-to-maximize-score.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
File diff suppressed because one or more lines are too long
163
leetcode/originData/find-the-longest-equal-subarray.json
Normal file
163
leetcode/originData/find-the-longest-equal-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
174
leetcode/originData/furthest-point-from-origin.json
Normal file
174
leetcode/originData/furthest-point-from-origin.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
173
leetcode/originData/max-pair-sum-in-an-array.json
Normal file
173
leetcode/originData/max-pair-sum-in-an-array.json
Normal file
File diff suppressed because one or more lines are too long
162
leetcode/originData/maximize-the-profit-as-the-salesman.json
Normal file
162
leetcode/originData/maximize-the-profit-as-the-salesman.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
File diff suppressed because one or more lines are too long
162
leetcode/originData/sorting-three-groups.json
Normal file
162
leetcode/originData/sorting-three-groups.json
Normal file
File diff suppressed because one or more lines are too long
49
leetcode/problem/apply-operations-to-maximize-score.html
Normal file
49
leetcode/problem/apply-operations-to-maximize-score.html
Normal file
@ -0,0 +1,49 @@
|
||||
<p>You are given an array <code>nums</code> of <code>n</code> positive integers and an integer <code>k</code>.</p>
|
||||
|
||||
<p>Initially, you start with a score of <code>1</code>. You have to maximize your score by applying the following operation at most <code>k</code> times:</p>
|
||||
|
||||
<ul>
|
||||
<li>Choose any <strong>non-empty</strong> subarray <code>nums[l, ..., r]</code> that you haven't chosen previously.</li>
|
||||
<li>Choose an element <code>x</code> of <code>nums[l, ..., r]</code> with the highest <strong>prime score</strong>. If multiple such elements exist, choose the one with the smallest index.</li>
|
||||
<li>Multiply your score by <code>x</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Here, <code>nums[l, ..., r]</code> denotes the subarray of <code>nums</code> starting at index <code>l</code> and ending at the index <code>r</code>, both ends being inclusive.</p>
|
||||
|
||||
<p>The <strong>prime score</strong> of an integer <code>x</code> is equal to the number of distinct prime factors of <code>x</code>. For example, the prime score of <code>300</code> is <code>3</code> since <code>300 = 2 * 2 * 3 * 5 * 5</code>.</p>
|
||||
|
||||
<p>Return <em>the <strong>maximum possible score</strong> after applying at most </em><code>k</code><em> operations</em>.</p>
|
||||
|
||||
<p>Since the answer may be large, return it modulo <code>10<sup>9 </sup>+ 7</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [8,3,9,3,8], k = 2
|
||||
<strong>Output:</strong> 81
|
||||
<strong>Explanation:</strong> To get a score of 81, we can apply the following operations:
|
||||
- Choose subarray nums[2, ..., 2]. nums[2] is the only element in this subarray. Hence, we multiply the score by nums[2]. The score becomes 1 * 9 = 9.
|
||||
- Choose subarray nums[2, ..., 3]. Both nums[2] and nums[3] have a prime score of 1, but nums[2] has the smaller index. Hence, we multiply the score by nums[2]. The score becomes 9 * 9 = 81.
|
||||
It can be proven that 81 is the highest score one can obtain.</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [19,12,14,6,10,18], k = 3
|
||||
<strong>Output:</strong> 4788
|
||||
<strong>Explanation:</strong> To get a score of 4788, we can apply the following operations:
|
||||
- Choose subarray nums[0, ..., 0]. nums[0] is the only element in this subarray. Hence, we multiply the score by nums[0]. The score becomes 1 * 19 = 19.
|
||||
- Choose subarray nums[5, ..., 5]. nums[5] is the only element in this subarray. Hence, we multiply the score by nums[5]. The score becomes 19 * 18 = 342.
|
||||
- Choose subarray nums[2, ..., 3]. Both nums[2] and nums[3] have a prime score of 2, but nums[2] has the smaller index. Hence, we multipy the score by nums[2]. The score becomes 342 * 14 = 4788.
|
||||
It can be proven that 4788 is the highest score one can obtain.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length == n <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= nums[i] <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= k <= min(n * (n + 1) / 2, 10<sup>9</sup>)</code></li>
|
||||
</ul>
|
@ -0,0 +1,43 @@
|
||||
<p>Given an array of strings <code>words</code> and a string <code>s</code>, determine if <code>s</code> is an <strong>acronym</strong> of words.</p>
|
||||
|
||||
<p>The string <code>s</code> is considered an acronym of <code>words</code> if it can be formed by concatenating the <strong>first</strong> character of each string in <code>words</code> <strong>in order</strong>. For example, <code>"ab"</code> can be formed from <code>["apple", "banana"]</code>, but it can't be formed from <code>["bear", "aardvark"]</code>.</p>
|
||||
|
||||
<p>Return <code>true</code><em> if </em><code>s</code><em> is an acronym of </em><code>words</code><em>, and </em><code>false</code><em> otherwise. </em></p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> words = ["alice","bob","charlie"], s = "abc"
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong> The first character in the words "alice", "bob", and "charlie" are 'a', 'b', and 'c', respectively. Hence, s = "abc" is the acronym.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> words = ["an","apple"], s = "a"
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation:</strong> The first character in the words "an" and "apple" are 'a' and 'a', respectively.
|
||||
The acronym formed by concatenating these characters is "aa".
|
||||
Hence, s = "a" is not the acronym.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> words = ["never","gonna","give","up","on","you"], s = "ngguoy"
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation: </strong>By concatenating the first character of the words in the array, we get the string "ngguoy".
|
||||
Hence, s = "ngguoy" is the acronym.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= words.length <= 100</code></li>
|
||||
<li><code>1 <= words[i].length <= 10</code></li>
|
||||
<li><code>1 <= s.length <= 100</code></li>
|
||||
<li><code>words[i]</code> and <code>s</code> consist of lowercase English letters.</li>
|
||||
</ul>
|
@ -0,0 +1,39 @@
|
||||
Given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code> and an integer <code>target</code>, return <em>the number of pairs</em> <code>(i, j)</code> <em>where</em> <code>0 <= i < j < n</code> <em>and</em> <code>nums[i] + nums[j] < target</code>.
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [-1,1,2,3,1], target = 2
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> There are 3 pairs of indices that satisfy the conditions in the statement:
|
||||
- (0, 1) since 0 < 1 and nums[0] + nums[1] = 0 < target
|
||||
- (0, 2) since 0 < 2 and nums[0] + nums[2] = 1 < target
|
||||
- (0, 4) since 0 < 4 and nums[0] + nums[4] = 0 < target
|
||||
Note that (0, 3) is not counted since nums[0] + nums[3] is not strictly less than the target.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [-6,2,5,-2,-7,-1,3], target = -2
|
||||
<strong>Output:</strong> 10
|
||||
<strong>Explanation:</strong> There are 10 pairs of indices that satisfy the conditions in the statement:
|
||||
- (0, 1) since 0 < 1 and nums[0] + nums[1] = -4 < target
|
||||
- (0, 3) since 0 < 3 and nums[0] + nums[3] = -8 < target
|
||||
- (0, 4) since 0 < 4 and nums[0] + nums[4] = -13 < target
|
||||
- (0, 5) since 0 < 5 and nums[0] + nums[5] = -7 < target
|
||||
- (0, 6) since 0 < 6 and nums[0] + nums[6] = -3 < target
|
||||
- (1, 4) since 1 < 4 and nums[1] + nums[4] = -5 < target
|
||||
- (3, 4) since 3 < 4 and nums[3] + nums[4] = -9 < target
|
||||
- (3, 5) since 3 < 5 and nums[3] + nums[5] = -3 < target
|
||||
- (4, 5) since 4 < 5 and nums[4] + nums[5] = -8 < target
|
||||
- (4, 6) since 4 < 6 and nums[4] + nums[6] = -4 < target
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length == n <= 50</code></li>
|
||||
<li><code>-50 <= nums[i], target <= 50</code></li>
|
||||
</ul>
|
@ -0,0 +1,31 @@
|
||||
<p>You are given two integers, <code>n</code> and <code>k</code>.</p>
|
||||
|
||||
<p>An array of <strong>distinct</strong> positive integers is called a <b>k-avoiding</b> array if there does not exist any pair of distinct elements that sum to <code>k</code>.</p>
|
||||
|
||||
<p>Return <em>the <strong>minimum</strong> possible sum of a k-avoiding array of length </em><code>n</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 5, k = 4
|
||||
<strong>Output:</strong> 18
|
||||
<strong>Explanation:</strong> Consider the k-avoiding array [1,2,4,5,6], which has a sum of 18.
|
||||
It can be proven that there is no k-avoiding array with a sum less than 18.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 2, k = 6
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> We can construct the array [1,2], which has a sum of 3.
|
||||
It can be proven that there is no k-avoiding array with a sum less than 3.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n, k <= 50</code></li>
|
||||
</ul>
|
@ -0,0 +1,29 @@
|
||||
<p>You are given the <code>head</code> of a <strong>non-empty</strong> linked list representing a non-negative integer without leading zeroes.</p>
|
||||
|
||||
<p>Return <em>the </em><code>head</code><em> of the linked list after <strong>doubling</strong> it</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2023/05/28/example.png" style="width: 401px; height: 81px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> head = [1,8,9]
|
||||
<strong>Output:</strong> [3,7,8]
|
||||
<strong>Explanation:</strong> The figure above corresponds to the given linked list which represents the number 189. Hence, the returned linked list represents the number 189 * 2 = 378.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2023/05/28/example2.png" style="width: 401px; height: 81px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> head = [9,9,9]
|
||||
<strong>Output:</strong> [1,9,9,8]
|
||||
<strong>Explanation:</strong> The figure above corresponds to the given linked list which represents the number 999. Hence, the returned linked list reprersents the number 999 * 2 = 1998.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>The number of nodes in the list is in the range <code>[1, 10<sup>4</sup>]</code></li>
|
||||
<li><font face="monospace"><code>0 <= Node.val <= 9</code></font></li>
|
||||
<li>The input is generated such that the list represents a number that does not have leading zeros, except the number <code>0</code> itself.</li>
|
||||
</ul>
|
39
leetcode/problem/find-the-longest-equal-subarray.html
Normal file
39
leetcode/problem/find-the-longest-equal-subarray.html
Normal file
@ -0,0 +1,39 @@
|
||||
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> and an integer <code>k</code>.</p>
|
||||
|
||||
<p>A subarray is called <strong>equal</strong> if all of its elements are equal. Note that the empty subarray is an <strong>equal</strong> subarray.</p>
|
||||
|
||||
<p>Return <em>the length of the <strong>longest</strong> possible equal subarray after deleting <strong>at most</strong> </em><code>k</code><em> elements from </em><code>nums</code>.</p>
|
||||
|
||||
<p>A <b>subarray</b> is a contiguous, possibly empty sequence of elements within an array.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,3,2,3,1,3], k = 3
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> It's optimal to delete the elements at index 2 and index 4.
|
||||
After deleting them, nums becomes equal to [1, 3, 3, 3].
|
||||
The longest equal subarray starts at i = 1 and ends at j = 3 with length equal to 3.
|
||||
It can be proven that no longer equal subarrays can be created.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,1,2,2,1,1], k = 2
|
||||
<strong>Output:</strong> 4
|
||||
<strong>Explanation:</strong> It's optimal to delete the elements at index 2 and index 3.
|
||||
After deleting them, nums becomes equal to [1, 1, 1, 1].
|
||||
The array itself is an equal subarray, so the answer is 4.
|
||||
It can be proven that no longer equal subarrays can be created.
|
||||
</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] <= nums.length</code></li>
|
||||
<li><code>0 <= k <= nums.length</code></li>
|
||||
</ul>
|
@ -0,0 +1,52 @@
|
||||
<p>You are given positive integers <code>n</code> and <code>target</code>.</p>
|
||||
|
||||
<p>An array <code>nums</code> is <strong>beautiful</strong> if it meets the following conditions:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>nums.length == n</code>.</li>
|
||||
<li><code>nums</code> consists of pairwise <strong>distinct</strong> <strong>positive</strong> integers.</li>
|
||||
<li>There doesn't exist two <strong>distinct</strong> indices, <code>i</code> and <code>j</code>, in the range <code>[0, n - 1]</code>, such that <code>nums[i] + nums[j] == target</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the <strong>minimum</strong> possible sum that a beautiful array could have</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 2, target = 3
|
||||
<strong>Output:</strong> 4
|
||||
<strong>Explanation:</strong> We can see that nums = [1,3] is beautiful.
|
||||
- The array nums has length n = 2.
|
||||
- The array nums consists of pairwise distinct positive integers.
|
||||
- There doesn't exist two distinct indices, i and j, with nums[i] + nums[j] == 3.
|
||||
It can be proven that 4 is the minimum possible sum that a beautiful array could have.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 3, target = 3
|
||||
<strong>Output:</strong> 8
|
||||
<strong>Explanation:</strong> We can see that nums = [1,3,4] is beautiful.
|
||||
- The array nums has length n = 3.
|
||||
- The array nums consists of pairwise distinct positive integers.
|
||||
- There doesn't exist two distinct indices, i and j, with nums[i] + nums[j] == 3.
|
||||
It can be proven that 8 is the minimum possible sum that a beautiful array could have.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 1, target = 1
|
||||
<strong>Output:</strong> 1
|
||||
<strong>Explanation:</strong> We can see, that nums = [1] is beautiful.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= target <= 10<sup>5</sup></code></li>
|
||||
</ul>
|
43
leetcode/problem/furthest-point-from-origin.html
Normal file
43
leetcode/problem/furthest-point-from-origin.html
Normal file
@ -0,0 +1,43 @@
|
||||
<p>You are given a string <code>moves</code> of length <code>n</code> consisting only of characters <code>'L'</code>, <code>'R'</code>, and <code>'_'</code>. The string represents your movement on a number line starting from the origin <code>0</code>.</p>
|
||||
|
||||
<p>In the <code>i<sup>th</sup></code> move, you can choose one of the following directions:</p>
|
||||
|
||||
<ul>
|
||||
<li>move to the left if <code>moves[i] = 'L'</code> or <code>moves[i] = '_'</code></li>
|
||||
<li>move to the right if <code>moves[i] = 'R'</code> or <code>moves[i] = '_'</code></li>
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the <strong>distance from the origin</strong> of the <strong>furthest</strong> point you can get to after </em><code>n</code><em> moves</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> moves = "L_RL__R"
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> The furthest point we can reach from the origin 0 is point -3 through the following sequence of moves "LLRLLLR".
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> moves = "_R__LL_"
|
||||
<strong>Output:</strong> 5
|
||||
<strong>Explanation:</strong> The furthest point we can reach from the origin 0 is point -5 through the following sequence of moves "LRLLLLL".
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> moves = "_______"
|
||||
<strong>Output:</strong> 7
|
||||
<strong>Explanation:</strong> The furthest point we can reach from the origin 0 is point 7 through the following sequence of moves "RRRRRRR".
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= moves.length == n <= 50</code></li>
|
||||
<li><code>moves</code> consists only of characters <code>'L'</code>, <code>'R'</code> and <code>'_'</code>.</li>
|
||||
</ul>
|
@ -0,0 +1,44 @@
|
||||
<p>You are given two <strong>0-indexed</strong> strings <code>str1</code> and <code>str2</code>.</p>
|
||||
|
||||
<p>In an operation, you select a <strong>set</strong> of indices in <code>str1</code>, and for each index <code>i</code> in the set, increment <code>str1[i]</code> to the next character <strong>cyclically</strong>. That is <code>'a'</code> becomes <code>'b'</code>, <code>'b'</code> becomes <code>'c'</code>, and so on, and <code>'z'</code> becomes <code>'a'</code>.</p>
|
||||
|
||||
<p>Return <code>true</code> <em>if it is possible to make </em><code>str2</code> <em>a subsequence of </em><code>str1</code> <em>by performing the operation <strong>at most once</strong></em>, <em>and</em> <code>false</code> <em>otherwise</em>.</p>
|
||||
|
||||
<p><strong>Note:</strong> A subsequence of a string is a new string that is formed from the original string by deleting some (possibly none) of the characters without disturbing the relative positions of the remaining characters.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> str1 = "abc", str2 = "ad"
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong> Select index 2 in str1.
|
||||
Increment str1[2] to become 'd'.
|
||||
Hence, str1 becomes "abd" and str2 is now a subsequence. Therefore, true is returned.</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> str1 = "zc", str2 = "ad"
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong> Select indices 0 and 1 in str1.
|
||||
Increment str1[0] to become 'a'.
|
||||
Increment str1[1] to become 'd'.
|
||||
Hence, str1 becomes "ad" and str2 is now a subsequence. Therefore, true is returned.</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> str1 = "ab", str2 = "d"
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation:</strong> In this example, it can be shown that it is impossible to make str2 a subsequence of str1 using the operation at most once.
|
||||
Therefore, false is returned.</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= str1.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= str2.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>str1</code> and <code>str2</code> consist of only lowercase English letters.</li>
|
||||
</ul>
|
30
leetcode/problem/max-pair-sum-in-an-array.html
Normal file
30
leetcode/problem/max-pair-sum-in-an-array.html
Normal file
@ -0,0 +1,30 @@
|
||||
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to find the <strong>maximum</strong> sum of a pair of numbers from <code>nums</code> such that the maximum <strong>digit </strong>in both numbers are equal.</p>
|
||||
|
||||
<p>Return <em>the maximum sum or</em> <code>-1</code><em> if no such pair exists</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [51,71,17,24,42]
|
||||
<strong>Output:</strong> 88
|
||||
<strong>Explanation:</strong>
|
||||
For i = 1 and j = 2, nums[i] and nums[j] have equal maximum digits with a pair sum of 71 + 17 = 88.
|
||||
For i = 3 and j = 4, nums[i] and nums[j] have equal maximum digits with a pair sum of 24 + 42 = 66.
|
||||
It can be shown that there are no other pairs with equal maximum digits, so the answer is 88.</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,2,3,4]
|
||||
<strong>Output:</strong> -1
|
||||
<strong>Explanation:</strong> No pair exists in nums with equal maximum digits.
|
||||
</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>
|
41
leetcode/problem/maximize-the-profit-as-the-salesman.html
Normal file
41
leetcode/problem/maximize-the-profit-as-the-salesman.html
Normal file
@ -0,0 +1,41 @@
|
||||
<p>You are given an integer <code>n</code> representing the number of houses on a number line, numbered from <code>0</code> to <code>n - 1</code>.</p>
|
||||
|
||||
<p>Additionally, you are given a 2D integer array <code>offers</code> where <code>offers[i] = [start<sub>i</sub>, end<sub>i</sub>, gold<sub>i</sub>]</code>, indicating that <code>i<sup>th</sup></code> buyer wants to buy all the houses from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> for <code>gold<sub>i</sub></code> amount of gold.</p>
|
||||
|
||||
<p>As a salesman, your goal is to <strong>maximize</strong> your earnings by strategically selecting and selling houses to buyers.</p>
|
||||
|
||||
<p>Return <em>the maximum amount of gold you can earn</em>.</p>
|
||||
|
||||
<p><strong>Note</strong> that different buyers can't buy the same house, and some houses may remain unsold.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 5, offers = [[0,0,1],[0,2,2],[1,3,2]]
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> There are 5 houses numbered from 0 to 4 and there are 3 purchase offers.
|
||||
We sell houses in the range [0,0] to 1<sup>st</sup> buyer for 1 gold and houses in the range [1,3] to 3<sup>rd</sup> buyer for 2 golds.
|
||||
It can be proven that 3 is the maximum amount of gold we can achieve.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 5, offers = [[0,0,1],[0,2,10],[1,3,2]]
|
||||
<strong>Output:</strong> 10
|
||||
<strong>Explanation:</strong> There are 5 houses numbered from 0 to 4 and there are 3 purchase offers.
|
||||
We sell houses in the range [0,2] to 2<sup>nd</sup> buyer for 10 golds.
|
||||
It can be proven that 10 is the maximum amount of gold we can achieve.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= offers.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>offers[i].length == 3</code></li>
|
||||
<li><code>0 <= start<sub>i</sub> <= end<sub>i</sub> <= n - 1</code></li>
|
||||
<li><code>1 <= gold<sub>i</sub> <= 10<sup>3</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,121 @@
|
||||
<p>You are given a <strong>0-indexed</strong> integer array <code>receiver</code> of length <code>n</code> and an integer <code>k</code>.</p>
|
||||
|
||||
<p>There are <code>n</code> players having a <strong>unique id</strong> in the range <code>[0, n - 1]</code> who will play a ball passing game, and <code>receiver[i]</code> is the id of the player who receives passes from the player with id <code>i</code>. Players can pass to themselves, <strong>i.e.</strong> <code>receiver[i]</code> may be equal to <code>i</code>.</p>
|
||||
|
||||
<p>You must choose one of the <code>n</code> players as the starting player for the game, and the ball will be passed <strong>exactly</strong> <code>k</code> times starting from the chosen player.</p>
|
||||
|
||||
<p>For a chosen starting player having id <code>x</code>, we define a function <code>f(x)</code> that denotes the <strong>sum</strong> of <code>x</code> and the <strong>ids</strong> of all players who receive the ball during the <code>k</code> passes, <strong>including repetitions</strong>. In other words, <code>f(x) = x + receiver[x] + receiver[receiver[x]] + ... + receiver<sup>(k)</sup>[x]</code>.</p>
|
||||
|
||||
<p>Your task is to choose a starting player having id <code>x</code> that <strong>maximizes</strong> the value of <code>f(x)</code>.</p>
|
||||
|
||||
<p>Return <em>an integer denoting the <strong>maximum</strong> value of the function.</em></p>
|
||||
|
||||
<p><strong>Note:</strong> <code>receiver</code> may contain duplicates.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<table border="1" cellspacing="3" style="border-collapse: separate; text-align: center;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th style="padding: 5px; border: 1px solid black;">Pass Number</th>
|
||||
<th style="padding: 5px; border: 1px solid black;">Sender ID</th>
|
||||
<th style="padding: 5px; border: 1px solid black;">Receiver ID</th>
|
||||
<th style="padding: 5px; border: 1px solid black;">x + Receiver IDs</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 5px; border: 1px solid black;"> </td>
|
||||
<td style="padding: 5px; border: 1px solid black;"> </td>
|
||||
<td style="padding: 5px; border: 1px solid black;"> </td>
|
||||
<td style="padding: 5px; border: 1px solid black;">2</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 5px; border: 1px solid black;">1</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">2</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">1</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">3</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 5px; border: 1px solid black;">2</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">1</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">0</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">3</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 5px; border: 1px solid black;">3</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">0</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">2</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">5</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 5px; border: 1px solid black;">4</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">2</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">1</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">6</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> receiver = [2,0,1], k = 4
|
||||
<strong>Output:</strong> 6
|
||||
<strong>Explanation:</strong> The table above shows a simulation of the game starting with the player having id x = 2.
|
||||
From the table, f(2) is equal to 6.
|
||||
It can be shown that 6 is the maximum achievable value of the function.
|
||||
Hence, the output is 6.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<table border="1" cellspacing="3" style="border-collapse: separate; text-align: center;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th style="padding: 5px; border: 1px solid black;">Pass Number</th>
|
||||
<th style="padding: 5px; border: 1px solid black;">Sender ID</th>
|
||||
<th style="padding: 5px; border: 1px solid black;">Receiver ID</th>
|
||||
<th style="padding: 5px; border: 1px solid black;">x + Receiver IDs</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 5px; border: 1px solid black;"> </td>
|
||||
<td style="padding: 5px; border: 1px solid black;"> </td>
|
||||
<td style="padding: 5px; border: 1px solid black;"> </td>
|
||||
<td style="padding: 5px; border: 1px solid black;">4</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 5px; border: 1px solid black;">1</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">4</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">3</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">7</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 5px; border: 1px solid black;">2</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">3</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">2</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">9</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 5px; border: 1px solid black;">3</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">2</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">1</td>
|
||||
<td style="padding: 5px; border: 1px solid black;">10</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> receiver = [1,1,1,2,3], k = 3
|
||||
<strong>Output:</strong> 10
|
||||
<strong>Explanation:</strong> The table above shows a simulation of the game starting with the player having id x = 4.
|
||||
From the table, f(4) is equal to 10.
|
||||
It can be shown that 10 is the maximum achievable value of the function.
|
||||
Hence, the output is 10.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= receiver.length == n <= 10<sup>5</sup></code></li>
|
||||
<li><code>0 <= receiver[i] <= n - 1</code></li>
|
||||
<li><code>1 <= k <= 10<sup>10</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,47 @@
|
||||
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> and an integer <code>x</code>.</p>
|
||||
|
||||
<p>Find the <strong>minimum absolute difference</strong> between two elements in the array that are at least <code>x</code> indices apart.</p>
|
||||
|
||||
<p>In other words, find two indices <code>i</code> and <code>j</code> such that <code>abs(i - j) >= x</code> and <code>abs(nums[i] - nums[j])</code> is minimized.</p>
|
||||
|
||||
<p>Return<em> an integer denoting the <strong>minimum</strong> absolute difference between two elements that are at least</em> <code>x</code> <em>indices apart</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [4,3,2,4], x = 2
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong> We can select nums[0] = 4 and nums[3] = 4.
|
||||
They are at least 2 indices apart, and their absolute difference is the minimum, 0.
|
||||
It can be shown that 0 is the optimal answer.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [5,3,2,10,15], x = 1
|
||||
<strong>Output:</strong> 1
|
||||
<strong>Explanation:</strong> We can select nums[1] = 3 and nums[2] = 2.
|
||||
They are at least 1 index apart, and their absolute difference is the minimum, 1.
|
||||
It can be shown that 1 is the optimal answer.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,2,3,4], x = 3
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> We can select nums[0] = 1 and nums[3] = 4.
|
||||
They are at least 3 indices apart, and their absolute difference is the minimum, 3.
|
||||
It can be shown that 3 is the optimal answer.
|
||||
</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>0 <= x < nums.length</code></li>
|
||||
</ul>
|
@ -0,0 +1,52 @@
|
||||
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of <strong>non-negative</strong> powers of <code>2</code>, and an integer <code>target</code>.</p>
|
||||
|
||||
<p>In one operation, you must apply the following changes to the array:</p>
|
||||
|
||||
<ul>
|
||||
<li>Choose any element of the array <code>nums[i]</code> such that <code>nums[i] > 1</code>.</li>
|
||||
<li>Remove <code>nums[i]</code> from the array.</li>
|
||||
<li>Add <strong>two</strong> occurrences of <code>nums[i] / 2</code> to the <strong>end</strong> of <code>nums</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return the <em><strong>minimum number of operations</strong> you need to perform so that </em><code>nums</code><em> contains a <strong>subsequence</strong> whose elements sum to</em> <code>target</code>. If it is impossible to obtain such a subsequence, return <code>-1</code>.</p>
|
||||
|
||||
<p>A <strong>subsequence</strong> is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,2,8], target = 7
|
||||
<strong>Output:</strong> 1
|
||||
<strong>Explanation:</strong> In the first operation, we choose element nums[2]. The array becomes equal to nums = [1,2,4,4].
|
||||
At this stage, nums contains the subsequence [1,2,4] which sums up to 7.
|
||||
It can be shown that there is no shorter sequence of operations that results in a subsequnce that sums up to 7.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,32,1,2], target = 12
|
||||
<strong>Output:</strong> 2
|
||||
<strong>Explanation:</strong> In the first operation, we choose element nums[1]. The array becomes equal to nums = [1,1,2,16,16].
|
||||
In the second operation, we choose element nums[3]. The array becomes equal to nums = [1,1,2,16,8,8]
|
||||
At this stage, nums contains the subsequence [1,1,2,8] which sums up to 12.
|
||||
It can be shown that there is no shorter sequence of operations that results in a subsequence that sums up to 12.</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,32,1], target = 35
|
||||
<strong>Output:</strong> -1
|
||||
<strong>Explanation:</strong> It can be shown that no sequence of operations results in a subsequence that sums up to 35.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 1000</code></li>
|
||||
<li><code>1 <= nums[i] <= 2<sup>30</sup></code></li>
|
||||
<li><code>nums</code> consists only of non-negative powers of two.</li>
|
||||
<li><code>1 <= target < 2<sup>31</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,52 @@
|
||||
<p>You are given positive integers <code>low</code>, <code>high</code>, and <code>k</code>.</p>
|
||||
|
||||
<p>A number is <strong>beautiful</strong> if it meets both of the following conditions:</p>
|
||||
|
||||
<ul>
|
||||
<li>The count of even digits in the number is equal to the count of odd digits.</li>
|
||||
<li>The number is divisible by <code>k</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the number of beautiful integers in the range</em> <code>[low, high]</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> low = 10, high = 20, k = 3
|
||||
<strong>Output:</strong> 2
|
||||
<strong>Explanation:</strong> There are 2 beautiful integers in the given range: [12,18].
|
||||
- 12 is beautiful because it contains 1 odd digit and 1 even digit, and is divisible by k = 3.
|
||||
- 18 is beautiful because it contains 1 odd digit and 1 even digit, and is divisible by k = 3.
|
||||
Additionally we can see that:
|
||||
- 16 is not beautiful because it is not divisible by k = 3.
|
||||
- 15 is not beautiful because it does not contain equal counts even and odd digits.
|
||||
It can be shown that there are only 2 beautiful integers in the given range.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> low = 1, high = 10, k = 1
|
||||
<strong>Output:</strong> 1
|
||||
<strong>Explanation:</strong> There is 1 beautiful integer in the given range: [10].
|
||||
- 10 is beautiful because it contains 1 odd digit and 1 even digit, and is divisible by k = 1.
|
||||
It can be shown that there is only 1 beautiful integer in the given range.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> low = 5, high = 5, k = 2
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong> There are 0 beautiful integers in the given range.
|
||||
- 5 is not beautiful because it is not divisible by k = 2 and it does not contain equal even and odd digits.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 < low <= high <= 10<sup>9</sup></code></li>
|
||||
<li><code>0 < k <= 20</code></li>
|
||||
</ul>
|
63
leetcode/problem/sorting-three-groups.html
Normal file
63
leetcode/problem/sorting-three-groups.html
Normal file
@ -0,0 +1,63 @@
|
||||
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.<br />
|
||||
<br />
|
||||
The numbers from <code>0</code> to <code>n - 1</code> are divided into three groups numbered from <code>1</code> to <code>3</code>, where number <code>i</code> belongs to group <code>nums[i]</code>. Notice that some groups may be <strong>empty</strong>.<br />
|
||||
<br />
|
||||
You are allowed to perform this operation any number of times:</p>
|
||||
|
||||
<ul>
|
||||
<li>Pick number <code>x</code> and change its group. More formally, change <code>nums[x]</code> to any number from <code>1</code> to <code>3</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>A new array <code>res</code> is constructed using the following procedure:</p>
|
||||
|
||||
<ol>
|
||||
<li>Sort the numbers in each group independently.</li>
|
||||
<li>Append the elements of groups <code>1</code>, <code>2</code>, and <code>3</code> to <code>res</code> <strong>in this order</strong>.</li>
|
||||
</ol>
|
||||
|
||||
<p>Array <code>nums</code> is called a <strong>beautiful array</strong> if the constructed array <code>res</code> is sorted in <strong>non-decreasing</strong> order.</p>
|
||||
|
||||
<p>Return <em>the <strong>minimum</strong> number of operations to make </em><code>nums</code><em> a <strong>beautiful array</strong></em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [2,1,3,2,1]
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> It's optimal to perform three operations:
|
||||
1. change nums[0] to 1.
|
||||
2. change nums[2] to 1.
|
||||
3. change nums[3] to 1.
|
||||
After performing the operations and sorting the numbers in each group, group 1 becomes equal to [0,1,2,3,4] and group 2 and group 3 become empty. Hence, res is equal to [0,1,2,3,4] which is sorted in non-decreasing order.
|
||||
It can be proven that there is no valid sequence of less than three operations.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,3,2,1,3,3]
|
||||
<strong>Output:</strong> 2
|
||||
<strong>Explanation:</strong> It's optimal to perform two operations:
|
||||
1. change nums[1] to 1.
|
||||
2. change nums[2] to 1.
|
||||
After performing the operations and sorting the numbers in each group, group 1 becomes equal to [0,1,2,3], group 2 becomes empty, and group 3 becomes equal to [4,5]. Hence, res is equal to [0,1,2,3,4,5] which is sorted in non-decreasing order.
|
||||
It can be proven that there is no valid sequence of less than two operations.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [2,2,2,2,3,3]
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong> It's optimal to not perform operations.
|
||||
After sorting the numbers in each group, group 1 becomes empty, group 2 becomes equal to [0,1,2,3] and group 3 becomes equal to [4,5]. Hence, res is equal to [0,1,2,3,4,5] which is sorted in non-decreasing order.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 100</code></li>
|
||||
<li><code>1 <= nums[i] <= 3</code></li>
|
||||
</ul>
|
Loading…
Reference in New Issue
Block a user