1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 10:38:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
zhangbk1 2024-06-05 08:50:06 +08:00
parent a8fcd060a2
commit 4b8628b444
56 changed files with 14794 additions and 9128 deletions

View File

@ -1,6 +1,6 @@
# 力扣题库(完整版) # 力扣题库(完整版)
> 最后更新日期: **2024.05.16** > 最后更新日期: **2024.06.05**
> >
> 使用脚本前请务必仔细完整阅读本 `README.md` 文件 > 使用脚本前请务必仔细完整阅读本 `README.md` 文件

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,62 @@
{
"data": {
"question": {
"questionId": "3473",
"questionFrontendId": "3166",
"categoryTitle": "Database",
"boundTopicId": 2791590,
"title": "Calculate Parking Fees and Duration",
"titleSlug": "calculate-parking-fees-and-duration",
"content": null,
"translatedTitle": "计算停车费与时长",
"translatedContent": null,
"isPaidOnly": true,
"difficulty": "Medium",
"likes": 0,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
"contributors": [],
"langToValidPlayground": null,
"topicTags": [
{
"name": "Database",
"slug": "database",
"translatedName": "数据库",
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": null,
"stats": "{\"totalAccepted\": \"45\", \"totalSubmission\": \"69\", \"totalAcceptedRaw\": 45, \"totalSubmissionRaw\": 69, \"acRate\": \"65.2%\"}",
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "{\"headers\":{\"ParkingTransactions\":[\"lot_id\",\"car_id\",\"entry_time\",\"exit_time\",\"fee_paid\"]},\"rows\":{\"ParkingTransactions\":[[1,1001,\"2023-06-01 08:00:00\",\"2023-06-01 10:30:00\",5.00],[1,1001,\"2023-06-02 11:00:00\",\"2023-06-02 12:45:00\",3.00],[2,1001,\"2023-06-01 10:45:00\",\"2023-06-01 12:00:00\",6.00],[2,1002,\"2023-06-01 09:00:00\",\"2023-06-01 11:30:00\",4.00],[3,1001,\"2023-06-03 07:00:00\",\"2023-06-03 09:00:00\",4.00],[3,1002,\"2023-06-02 12:00:00\",\"2023-06-02 14:00:00\",2.00]]}}",
"metaData": "{\"mysql\":[\"CREATE TABLE If not exists ParkingTransactions (\\n lot_id INT,\\n car_id INT,\\n entry_time DATETIME,\\n exit_time DATETIME,\\n fee_paid DECIMAL(10, 2)\\n)\\n\"],\"mssql\":[\"CREATE TABLE ParkingTransactions (\\n lot_id INT,\\n car_id INT,\\n entry_time DATETIME,\\n exit_time DATETIME,\\n fee_paid DECIMAL(10, 2)\\n);\\n\"],\"oraclesql\":[\"CREATE TABLE ParkingTransactions (\\n lot_id NUMBER,\\n car_id NUMBER,\\n entry_time DATE,\\n exit_time DATE,\\n fee_paid NUMBER(10, 2)\\n)\\n\",\"ALTER SESSION SET nls_date_format='YYYY-MM-DD HH24:MI:SS'\"],\"database\":true,\"name\":\"calculate_fees_and_duration\",\"postgresql\":[\"CREATE TABLE IF NOT EXISTS ParkingTransactions (\\n lot_id INTEGER,\\n car_id INTEGER,\\n entry_time TIMESTAMP,\\n exit_time TIMESTAMP,\\n fee_paid NUMERIC(10, 2)\\n);\"],\"pythondata\":[\"ParkingTransactions = pd.DataFrame([], columns=['lot_id', 'car_id', 'entry_time', 'exit_time', 'fee_paid']).astype({\\n 'lot_id': 'Int64',\\n 'car_id': 'Int64',\\n 'entry_time': 'datetime64[ns]',\\n 'exit_time': 'datetime64[ns]',\\n 'fee_paid': 'float64'\\n})\"],\"database_schema\":{\"ParkingTransactions\":{\"lot_id\":\"INT\",\"car_id\":\"INT\",\"entry_time\":\"DATETIME\",\"exit_time\":\"DATETIME\",\"fee_paid\":\"DECIMAL(10, 2)\"}}}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [
"CREATE TABLE If not exists ParkingTransactions (\n lot_id INT,\n car_id INT,\n entry_time DATETIME,\n exit_time DATETIME,\n fee_paid DECIMAL(10, 2)\n)\n",
"Truncate table ParkingTransactions",
"insert into ParkingTransactions (lot_id, car_id, entry_time, exit_time, fee_paid) values ('1', '1001', '2023-06-01 08:00:00', '2023-06-01 10:30:00', '5.0')",
"insert into ParkingTransactions (lot_id, car_id, entry_time, exit_time, fee_paid) values ('1', '1001', '2023-06-02 11:00:00', '2023-06-02 12:45:00', '3.0')",
"insert into ParkingTransactions (lot_id, car_id, entry_time, exit_time, fee_paid) values ('2', '1001', '2023-06-01 10:45:00', '2023-06-01 12:00:00', '6.0')",
"insert into ParkingTransactions (lot_id, car_id, entry_time, exit_time, fee_paid) values ('2', '1002', '2023-06-01 09:00:00', '2023-06-01 11:30:00', '4.0')",
"insert into ParkingTransactions (lot_id, car_id, entry_time, exit_time, fee_paid) values ('3', '1001', '2023-06-03 07:00:00', '2023-06-03 09:00:00', '4.0')",
"insert into ParkingTransactions (lot_id, car_id, entry_time, exit_time, fee_paid) values ('3', '1002', '2023-06-02 12:00:00', '2023-06-02 14:00:00', '2.0')"
],
"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>\"],\"postgresql\":[\"PostgreSQL\",\"<p>PostgreSQL 16<\\/p>\"]}",
"book": null,
"isSubscribed": false,
"isDailyQuestion": false,
"dailyRecordStatus": null,
"editorType": "CKEDITOR",
"ugcQuestionId": null,
"style": "LEETCODE",
"exampleTestcases": "{\"headers\":{\"ParkingTransactions\":[\"lot_id\",\"car_id\",\"entry_time\",\"exit_time\",\"fee_paid\"]},\"rows\":{\"ParkingTransactions\":[[1,1001,\"2023-06-01 08:00:00\",\"2023-06-01 10:30:00\",5.00],[1,1001,\"2023-06-02 11:00:00\",\"2023-06-02 12:45:00\",3.00],[2,1001,\"2023-06-01 10:45:00\",\"2023-06-01 12:00:00\",6.00],[2,1002,\"2023-06-01 09:00:00\",\"2023-06-01 11:30:00\",4.00],[3,1001,\"2023-06-03 07:00:00\",\"2023-06-03 09:00:00\",4.00],[3,1002,\"2023-06-02 12:00:00\",\"2023-06-02 14:00:00\",2.00]]}}",
"__typename": "QuestionNode"
}
}
}

View File

@ -0,0 +1,63 @@
{
"data": {
"question": {
"questionId": "3465",
"questionFrontendId": "3156",
"categoryTitle": "Database",
"boundTopicId": 2783743,
"title": "Employee Task Duration and Concurrent Tasks",
"titleSlug": "employee-task-duration-and-concurrent-tasks",
"content": null,
"translatedTitle": "员工任务持续时间和并发任务",
"translatedContent": null,
"isPaidOnly": true,
"difficulty": "Hard",
"likes": 1,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
"contributors": [],
"langToValidPlayground": null,
"topicTags": [
{
"name": "Database",
"slug": "database",
"translatedName": "数据库",
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": null,
"stats": "{\"totalAccepted\": \"40\", \"totalSubmission\": \"87\", \"totalAcceptedRaw\": 40, \"totalSubmissionRaw\": 87, \"acRate\": \"46.0%\"}",
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "{\"headers\":{\"Tasks\":[\"task_id\",\"employee_id\",\"start_time\",\"end_time\"]},\"rows\":{\"Tasks\":[[1,1001,\"2023-05-01 08:00:00\",\"2023-05-01 09:00:00\"],[2,1001,\"2023-05-01 08:30:00\",\"2023-05-01 10:30:00\"],[3,1001,\"2023-05-01 11:00:00\",\"2023-05-01 12:00:00\"],[7,1001,\"2023-05-01 13:00:00\",\"2023-05-01 15:30:00\"],[4,1002,\"2023-05-01 09:00:00\",\"2023-05-01 10:00:00\"],[5,1002,\"2023-05-01 09:30:00\",\"2023-05-01 11:30:00\"],[6,1003,\"2023-05-01 14:00:00\",\"2023-05-01 16:00:00\"]]}}",
"metaData": "{\"mysql\":[\"CREATE TABLE if Not exists Tasks (\\n task_id INT ,\\n employee_id INT,\\n start_time DATETIME,\\n end_time DATETIME\\n);\"],\"mssql\":[\"CREATE TABLE Tasks (\\n task_id INT PRIMARY KEY,\\n employee_id INT,\\n start_time DATETIME,\\n end_time DATETIME\\n);\\n\"],\"oraclesql\":[\"CREATE TABLE Tasks (\\n task_id int ,\\n employee_id int,\\n start_time DATE,\\n end_time DATE\\n)\\n\\n\\n\\n\\n\\n\\n\",\"ALTER SESSION SET nls_date_format='YYYY-MM-DD HH24:MI:SS'\"],\"postgresql\":[\"CREATE TABLE IF NOT EXISTS Tasks (\\n task_id INT,\\n employee_id INT,\\n start_time TIMESTAMP,\\n end_time TIMESTAMP\\n);\\n\"],\"pythondata\":[\"Tasks = pd.DataFrame([], columns=['task_id', 'employee_id', 'start_time', 'end_time']).astype({\\n 'task_id': 'Int64',\\n 'employee_id': 'Int64',\\n 'start_time': 'datetime64[ns]',\\n 'end_time': 'datetime64[ns]'\\n})\"],\"database\":true,\"name\":\"find_total_duration\",\"database_schema\":{\"Tasks\":{\"task_id\":\"INT\",\"employee_id\":\"INT\",\"start_time\":\"DATETIME\",\"end_time\":\"DATETIME\"}}}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [
"CREATE TABLE if Not exists Tasks (\n task_id INT ,\n employee_id INT,\n start_time DATETIME,\n end_time DATETIME\n);",
"Truncate table Tasks",
"insert into Tasks (task_id, employee_id, start_time, end_time) values ('1', '1001', '2023-05-01 08:00:00', '2023-05-01 09:00:00')",
"insert into Tasks (task_id, employee_id, start_time, end_time) values ('2', '1001', '2023-05-01 08:30:00', '2023-05-01 10:30:00')",
"insert into Tasks (task_id, employee_id, start_time, end_time) values ('3', '1001', '2023-05-01 11:00:00', '2023-05-01 12:00:00')",
"insert into Tasks (task_id, employee_id, start_time, end_time) values ('7', '1001', '2023-05-01 13:00:00', '2023-05-01 15:30:00')",
"insert into Tasks (task_id, employee_id, start_time, end_time) values ('4', '1002', '2023-05-01 09:00:00', '2023-05-01 10:00:00')",
"insert into Tasks (task_id, employee_id, start_time, end_time) values ('5', '1002', '2023-05-01 09:30:00', '2023-05-01 11:30:00')",
"insert into Tasks (task_id, employee_id, start_time, end_time) values ('6', '1003', '2023-05-01 14:00:00', '2023-05-01 16:00:00')"
],
"enableRunCode": true,
"envInfo": "{\"mysql\":[\"MySQL\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>PostgreSQL 16<\\/p>\"]}",
"book": null,
"isSubscribed": false,
"isDailyQuestion": false,
"dailyRecordStatus": null,
"editorType": "CKEDITOR",
"ugcQuestionId": null,
"style": "LEETCODE",
"exampleTestcases": "{\"headers\":{\"Tasks\":[\"task_id\",\"employee_id\",\"start_time\",\"end_time\"]},\"rows\":{\"Tasks\":[[1,1001,\"2023-05-01 08:00:00\",\"2023-05-01 09:00:00\"],[2,1001,\"2023-05-01 08:30:00\",\"2023-05-01 10:30:00\"],[3,1001,\"2023-05-01 11:00:00\",\"2023-05-01 12:00:00\"],[7,1001,\"2023-05-01 13:00:00\",\"2023-05-01 15:30:00\"],[4,1002,\"2023-05-01 09:00:00\",\"2023-05-01 10:00:00\"],[5,1002,\"2023-05-01 09:30:00\",\"2023-05-01 11:30:00\"],[6,1003,\"2023-05-01 14:00:00\",\"2023-05-01 16:00:00\"]]}}",
"__typename": "QuestionNode"
}
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,64 @@
{
"data": {
"question": {
"questionId": "3481",
"questionFrontendId": "3172",
"categoryTitle": "Database",
"boundTopicId": 2798976,
"title": "Second Day Verification",
"titleSlug": "second-day-verification",
"content": null,
"translatedTitle": "第二天验证",
"translatedContent": null,
"isPaidOnly": true,
"difficulty": "Easy",
"likes": 0,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
"contributors": [],
"langToValidPlayground": null,
"topicTags": [
{
"name": "Database",
"slug": "database",
"translatedName": "数据库",
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": null,
"stats": "{\"totalAccepted\": \"28\", \"totalSubmission\": \"36\", \"totalAcceptedRaw\": 28, \"totalSubmissionRaw\": 36, \"acRate\": \"77.8%\"}",
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "{\"headers\":{\"emails\":[\"email_id\",\"user_id\",\"signup_date\"],\"texts\":[\"text_id\",\"email_id\",\"signup_action\",\"action_date\"]},\"rows\":{\"emails\":[[125,7771,\"2022-06-14 09:30:00\"],[433,1052,\"2022-07-09 08:15:00\"],[234,7005,\"2022-08-20 10:00:00\"]],\"texts\":[[1,125,\"Verified\",\"2022-06-15 08:30:00\"],[2,433,\"Not Verified\",\"2022-07-10 10:45:00\"],[4,234,\"Verified\",\"2022-08-21 09:30:00\"]]}}",
"metaData": "{\"mysql\":[\"CREATE TABLE If not exists emails (\\n email_id INT,\\n user_id INT,\\n signup_date DATETIME\\n);\",\"CREATE TABLE If not exists texts (\\n text_id INT,\\n email_id INT,\\n signup_action ENUM('Verified', 'Not Verified'),\\n action_date DATETIME\\n);\"],\"mssql\":[\"CREATE TABLE emails (\\n email_id INT,\\n user_id INT,\\n signup_date DATETIME\\n);\",\"CREATE TABLE texts (\\n text_id INT,\\n email_id INT,\\n signup_action VARCHAR(12),\\n action_date DATETIME\\n);\"],\"oraclesql\":[\"CREATE TABLE emails (\\n email_id NUMBER,\\n user_id NUMBER,\\n signup_date DATE\\n)\\n\",\"CREATE TABLE texts (\\n text_id NUMBER,\\n email_id NUMBER,\\n signup_action VARCHAR(32),\\n action_date DATE\\n)\",\"ALTER SESSION SET nls_date_format='YYYY-MM-DD HH24:MI:SS'\"],\"database\":true,\"name\":\"find_second_day_signups\",\"postgresql\":[\"CREATE TABLE emails (\\n email_id INTEGER,\\n user_id INTEGER,\\n signup_date DATE\\n);\\n\",\"CREATE TABLE texts (\\n text_id INTEGER,\\n email_id INTEGER,\\n signup_action VARCHAR(32),\\n action_date DATE\\n);\\n\",\"SELECT to_char(action_date, 'YYYY-MM-DD HH24:MI:SS') FROM texts;\\n\"],\"pythondata\":[\"emails = pd.DataFrame([], columns=['email_id', 'user_id', 'signup_date']).astype({\\n 'email_id': 'Int64', # Nullable integer type\\n 'user_id': 'Int64', # Nullable integer type\\n 'signup_date': 'datetime64[ns]' # DateTime type for signup date\\n})\",\"texts = pd.DataFrame([], columns=['text_id', 'email_id', 'signup_action', 'action_date']).astype({\\n 'text_id': 'Int64', # Nullable integer type for text_id\\n 'email_id': 'Int64', # Nullable integer type for email_id\\n 'signup_action': 'object', # Using 'object' to store string values for ENUM\\n 'action_date': 'datetime64[ns]' # DateTime type for action_date\\n})\"],\"database_schema\":{\"emails\":{\"email_id\":\"INT\",\"user_id\":\"INT\",\"signup_date\":\"DATETIME\"},\"texts\":{\"text_id\":\"INT\",\"email_id\":\"INT\",\"signup_action\":\"ENUM('Verified', 'Not Verified')\",\"action_date\":\"DATETIME\"}}}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [
"CREATE TABLE If not exists emails (\n email_id INT,\n user_id INT,\n signup_date DATETIME\n);",
"CREATE TABLE If not exists texts (\n text_id INT,\n email_id INT,\n signup_action ENUM('Verified', 'Not Verified'),\n action_date DATETIME\n);",
"Truncate table emails",
"insert into emails (email_id, user_id, signup_date) values ('125', '7771', '2022-06-14 09:30:00')",
"insert into emails (email_id, user_id, signup_date) values ('433', '1052', '2022-07-09 08:15:00')",
"insert into emails (email_id, user_id, signup_date) values ('234', '7005', '2022-08-20 10:00:00')",
"Truncate table texts",
"insert into texts (text_id, email_id, signup_action, action_date) values ('1', '125', 'Verified', '2022-06-15 08:30:00')",
"insert into texts (text_id, email_id, signup_action, action_date) values ('2', '433', 'Not Verified', '2022-07-10 10:45:00')",
"insert into texts (text_id, email_id, signup_action, action_date) values ('4', '234', 'Verified', '2022-08-21 09:30:00')"
],
"enableRunCode": true,
"envInfo": "{\"mysql\":[\"MySQL\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>PostgreSQL 16<\\/p>\"]}",
"book": null,
"isSubscribed": false,
"isDailyQuestion": false,
"dailyRecordStatus": null,
"editorType": "CKEDITOR",
"ugcQuestionId": null,
"style": "LEETCODE",
"exampleTestcases": "{\"headers\":{\"emails\":[\"email_id\",\"user_id\",\"signup_date\"],\"texts\":[\"text_id\",\"email_id\",\"signup_action\",\"action_date\"]},\"rows\":{\"emails\":[[125,7771,\"2022-06-14 09:30:00\"],[433,1052,\"2022-07-09 08:15:00\"],[234,7005,\"2022-08-20 10:00:00\"]],\"texts\":[[1,125,\"Verified\",\"2022-06-15 08:30:00\"],[2,433,\"Not Verified\",\"2022-07-10 10:45:00\"],[4,234,\"Verified\",\"2022-08-21 09:30:00\"]]}}",
"__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

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

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

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

View File

@ -0,0 +1,47 @@
<p>给你一个整数数组 <code>nums</code> 和一个二维数组 <code>queries</code>,其中 <code>queries[i] = [pos<sub>i</sub>, x<sub>i</sub>]</code></p>
<p>对于每个查询 <code>i</code>,首先将 <code>nums[pos<sub>i</sub>]</code> 设置为 <code>x<sub>i</sub></code>,然后计算查询 <code>i</code> 的答案,该答案为 <code>nums</code><strong>不包含相邻元素 </strong><span data-keyword="subsequence-array">子序列</span><strong>最大 </strong>和。</p>
<p>返回所有查询的答案之和。</p>
<p>由于最终答案可能非常大,返回其对 <code>10<sup>9</sup> + 7</code> <strong>取余</strong> 的结果。</p>
<p><strong>子序列</strong> 是指从另一个数组中删除一些或不删除元素而不改变剩余元素顺序得到的数组。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">nums = [3,5,9], queries = [[1,-2],[0,-3]]</span></p>
<p><strong>输出:</strong><span class="example-io">21</span></p>
<p><strong>解释:</strong><br />
执行第 1 个查询后,<code>nums = [3,-2,9]</code>,不包含相邻元素的子序列的最大和为 <code>3 + 9 = 12</code><br />
执行第 2 个查询后,<code>nums = [-3,-2,9]</code>,不包含相邻元素的子序列的最大和为 9 。</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">nums = [0,-1], queries = [[0,-5]]</span></p>
<p><strong>输出:</strong><span class="example-io">0</span></p>
<p><strong>解释:</strong><br />
执行第 1 个查询后,<code>nums = [-5,-1]</code>,不包含相邻元素的子序列的最大和为 0选择空子序列</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>-10<sup>5</sup> &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= queries.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>queries[i] == [pos<sub>i</sub>, x<sub>i</sub>]</code></li>
<li><code>0 &lt;= pos<sub>i</sub> &lt;= nums.length - 1</code></li>
<li><code>-10<sup>5</sup> &lt;= x<sub>i</sub> &lt;= 10<sup>5</sup></code></li>
</ul>

View File

@ -0,0 +1,41 @@
<p>给你两个整数数组 <code>nums1</code><code>nums2</code>,长度分别为 <code>n</code><code>m</code>。同时给你一个<strong>正整数</strong> <code>k</code></p>
<p>如果 <code>nums1[i]</code> 可以被 <code>nums2[j] * k</code> 整除,则称数对 <code>(i, j)</code><strong>优质数对</strong><code>0 &lt;= i &lt;= n - 1</code>, <code>0 &lt;= j &lt;= m - 1</code>)。</p>
<p>返回<strong> 优质数对 </strong>的总数。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">nums1 = [1,3,4], nums2 = [1,3,4], k = 1</span></p>
<p><strong>输出:</strong><span class="example-io">5</span></p>
<p><strong>解释:</strong></p>
<p>5个优质数对分别是 <code>(0, 0)</code>, <code>(1, 0)</code>, <code>(1, 1)</code>, <code>(2, 0)</code>, 和 <code>(2, 2)</code></p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">nums1 = [1,2,4,12], nums2 = [2,4], k = 3</span></p>
<p><strong>输出:</strong><span class="example-io">2</span></p>
<p><strong>解释:</strong></p>
<p>2个优质数对分别是 <code>(3, 0)</code><code>(3, 1)</code></p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= n, m &lt;= 50</code></li>
<li><code>1 &lt;= nums1[i], nums2[j] &lt;= 50</code></li>
<li><code>1 &lt;= k &lt;= 50</code></li>
</ul>

View File

@ -0,0 +1,41 @@
<p>给你两个整数数组 <code>nums1</code><code>nums2</code>,长度分别为 <code>n</code><code>m</code>。同时给你一个<strong>正整数</strong> <code>k</code></p>
<p>如果 <code>nums1[i]</code> 可以被 <code>nums2[j] * k</code> 整除,则称数对 <code>(i, j)</code><strong>优质数对</strong><code>0 &lt;= i &lt;= n - 1</code>, <code>0 &lt;= j &lt;= m - 1</code>)。</p>
<p>返回<strong> 优质数对 </strong>的总数。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">nums1 = [1,3,4], nums2 = [1,3,4], k = 1</span></p>
<p><strong>输出:</strong><span class="example-io">5</span></p>
<p><strong>解释:</strong></p>
<p>5个优质数对分别是 <code>(0, 0)</code>, <code>(1, 0)</code>, <code>(1, 1)</code>, <code>(2, 0)</code>, 和 <code>(2, 2)</code></p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">nums1 = [1,2,4,12], nums2 = [2,4], k = 3</span></p>
<p><strong>输出:</strong><span class="example-io">2</span></p>
<p><strong>解释:</strong></p>
<p>2个优质数对分别是 <code>(3, 0)</code><code>(3, 1)</code></p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= n, m &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums1[i], nums2[j] &lt;= 10<sup>6</sup></code></li>
<li><code>1 &lt;= k &lt;= 10<sup>3</sup></code></li>
</ul>

View File

@ -0,0 +1,180 @@
<p>给你一个字符串 <code>s</code>,模拟每秒钟的事件 <code>i</code></p>
<ul>
<li>如果 <code>s[i] == 'E'</code>,表示有一位顾客进入候诊室并占用一把椅子。</li>
<li>如果 <code>s[i] == 'L'</code>,表示有一位顾客离开候诊室,从而释放一把椅子。</li>
</ul>
<p>返回保证每位进入候诊室的顾客都能有椅子坐的<strong> 最少 </strong>椅子数,假设候诊室最初是 <strong>空的 </strong></p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">s = "EEEEEEE"</span></p>
<p><strong>输出:</strong><span class="example-io">7</span></p>
<p><strong>解释:</strong></p>
<p>每秒后都有一个顾客进入候诊室,没有人离开。因此,至少需要 7 把椅子。</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">s = "ELELEEL"</span></p>
<p><strong>输出:</strong><span class="example-io">2</span></p>
<p><strong>解释:</strong></p>
<p>假设候诊室里有 2 把椅子。下表显示了每秒钟等候室的状态。</p>
</div>
<table>
<tbody>
<tr>
<th></th>
<th>事件</th>
<th>候诊室的人数</th>
<th>可用的椅子数</th>
</tr>
<tr>
<td>0</td>
<td>Enter</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>1</td>
<td>Leave</td>
<td>0</td>
<td>2</td>
</tr>
<tr>
<td>2</td>
<td>Enter</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>3</td>
<td>Leave</td>
<td>0</td>
<td>2</td>
</tr>
<tr>
<td>4</td>
<td>Enter</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>5</td>
<td>Enter</td>
<td>2</td>
<td>0</td>
</tr>
<tr>
<td>6</td>
<td>Leave</td>
<td>1</td>
<td>1</td>
</tr>
</tbody>
</table>
<p><strong class="example">示例 3</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">s = "ELEELEELLL"</span></p>
<p><strong>输出:</strong><span class="example-io">3</span></p>
<p><strong>解释:</strong></p>
<p>假设候诊室里有 3 把椅子。下表显示了每秒钟等候室的状态。</p>
</div>
<table>
<tbody>
<tr>
<th></th>
<th>事件</th>
<th>候诊室的人数</th>
<th>可用的椅子数</th>
</tr>
<tr>
<td>0</td>
<td>Enter</td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>1</td>
<td>Leave</td>
<td>0</td>
<td>3</td>
</tr>
<tr>
<td>2</td>
<td>Enter</td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>Enter</td>
<td>2</td>
<td>1</td>
</tr>
<tr>
<td>4</td>
<td>Leave</td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>5</td>
<td>Enter</td>
<td>2</td>
<td>1</td>
</tr>
<tr>
<td>6</td>
<td>Enter</td>
<td>3</td>
<td>0</td>
</tr>
<tr>
<td>7</td>
<td>Leave</td>
<td>2</td>
<td>1</td>
</tr>
<tr>
<td>8</td>
<td>Leave</td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>9</td>
<td>Leave</td>
<td>0</td>
<td>3</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 50</code></li>
<li><code>s</code> 仅由字母 <code>'E'</code><code>'L'</code> 组成。</li>
<li><code>s</code> 表示一个有效的进出序列。</li>
</ul>

View File

@ -0,0 +1,45 @@
<p>给你一个字符串&nbsp;<code>s</code>&nbsp;。它可能包含任意数量的&nbsp;<code>'*'</code>&nbsp;字符。你的任务是删除所有的&nbsp;<code>'*'</code>&nbsp;字符。</p>
<p>当字符串还存在至少一个&nbsp;<code>'*'</code>&nbsp;字符时,你可以执行以下操作:</p>
<ul>
<li>删除最左边的&nbsp;<code>'*'</code>&nbsp;字符,同时删除该星号字符左边一个字典序 <strong>最小</strong>&nbsp;的字符。如果有多个字典序最小的字符,你可以删除它们中的任意一个。</li>
</ul>
<p>请你返回删除所有&nbsp;<code>'*'</code>&nbsp;字符以后,剩余字符连接而成的 <span data-keyword="lexicographically-smaller-string">字典序最小</span> 的字符串。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>s = "aaba*"</span></p>
<p><span class="example-io"><b>输出:</b>"aab"</span></p>
<p><strong>解释:</strong></p>
<p>删除 <code>'*'</code>&nbsp;号和它左边的其中一个&nbsp;<code>'a'</code>&nbsp;字符。如果我们选择删除&nbsp;<code>s[3]</code>&nbsp;<code>s</code>&nbsp;字典序最小。</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>s = "abc"</span></p>
<p><span class="example-io"><b>输出:</b>"abc"</span></p>
<p><strong>解释:</strong></p>
<p>字符串中没有&nbsp;<code>'*'</code>&nbsp;字符。<!-- notionvc: ff07e34f-b1d6-41fb-9f83-5d0ba3c1ecde --></p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
<li><code>s</code>&nbsp;只含有小写英文字母和&nbsp;<code>'*'</code>&nbsp;字符。</li>
<li>输入保证操作可以删除所有的&nbsp;<code>'*'</code>&nbsp;字符。</li>
</ul>

View File

@ -0,0 +1,86 @@
<p>给你有一个 <strong>非负</strong>&nbsp;整数&nbsp;<code>k</code>&nbsp;。有一个无限长度的台阶,<strong>最低</strong>&nbsp;一层编号为 0 。</p>
<p>虎老师有一个整数&nbsp;<code>jump</code>&nbsp;,一开始值为 0 。虎老师从台阶 1 开始,虎老师可以使用 <strong>任意</strong>&nbsp;次操作,目标是到达第&nbsp;<code>k</code> 级台阶。假设虎老师位于台阶 <code>i</code> ,一次 <strong>操作</strong> 中,虎老师可以:</p>
<ul>
<li>向下走一级到&nbsp;<code>i - 1</code>&nbsp;,但该操作&nbsp;<strong>不能</strong>&nbsp;连续使用,如果在台阶第 0 级也不能使用。</li>
<li>向上走到台阶&nbsp;<code>i + 2<sup>jump</sup></code>&nbsp;处,然后&nbsp;<code>jump</code>&nbsp;变为&nbsp;<code>jump + 1</code>&nbsp;</li>
</ul>
<p>请你返回虎老师到达台阶 <code>k</code>&nbsp;处的总方案数。</p>
<p><b>注意</b>&nbsp;,虎老师可能到达台阶 <code>k</code>&nbsp;处后,通过一些操作重新回到台阶 <code>k</code>&nbsp;处,这视为不同的方案。</p>
<p>&nbsp;</p>
<p><b>示例 1</b></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>k = 0</span></p>
<p><span class="example-io"><b>输出:</b>2</span></p>
<p><strong>解释:</strong></p>
<p>2 种到达台阶 0 的方案为:</p>
<ul>
<li>虎老师从台阶&nbsp;1 开始。
<ul>
<li>执行第一种操作,从台阶 1 向下走到台阶 0 。</li>
</ul>
</li>
<li>虎老师从台阶 1 开始。
<ul>
<li>执行第一种操作,从台阶 1 向下走到台阶 0 。</li>
<li>执行第二种操作,向上走 2<sup>0</sup>&nbsp;级台阶到台阶 1 。</li>
<li>执行第一种操作,从台阶 1 向下走到台阶 0 。</li>
</ul>
</li>
</ul>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>k = 1</span></p>
<p><span class="example-io"><b>输出:</b>4</span></p>
<p><strong>解释:</strong></p>
<p>4 种到达台阶 1 的方案为:</p>
<ul>
<li>虎老师从台阶 1 开始,已经到达台阶 1 。</li>
<li>虎老师从台阶 1 开始。
<ul>
<li>执行第一种操作,从台阶 1 向下走到台阶 0 。</li>
<li>执行第二种操作,向上走 2<sup>0</sup>&nbsp;级台阶到台阶 1 。</li>
</ul>
</li>
<li>虎老师从台阶 1 开始。
<ul>
<li>执行第二种操作,向上走 2<sup>0</sup>&nbsp;级台阶到台阶 2 。</li>
<li>执行第一种操作,向下走 1 级台阶到台阶 1 。</li>
</ul>
</li>
<li>虎老师从台阶 1 开始。
<ul>
<li>执行第一种操作,从台阶 1 向下走到台阶 0 。</li>
<li>执行第二种操作,向上走&nbsp;2<sup>0</sup>&nbsp;级台阶到台阶 1 。</li>
<li>执行第一种操作,向下走 1 级台阶到台阶 0 。</li>
<li>执行第二种操作,向上走 2<sup>1</sup>&nbsp;级台阶到台阶 2 。</li>
<li>执行第一种操作,向下走&nbsp;1 级台阶到台阶 1 。</li>
</ul>
</li>
</ul>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>0 &lt;= k &lt;= 10<sup>9</sup></code></li>
</ul>

View File

@ -0,0 +1,58 @@
<p>给你一个字符串 <code>word</code>,请你使用以下算法进行压缩:</p>
<ul>
<li>从空字符串 <code>comp</code> 开始。当 <code>word</code> <strong>不为空</strong> 时,执行以下操作:
<ul>
<li>移除 <code>word</code> 的最长单字符前缀,该前缀由单一字符 <code>c</code> 重复多次组成,且该前缀长度 <strong>最多 </strong>为 9 。</li>
<li>将前缀的长度和字符 <code>c</code> 追加到 <code>comp</code></li>
</ul>
</li>
</ul>
<p>返回字符串 <code>comp</code></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">word = "abcde"</span></p>
<p><strong>输出:</strong><span class="example-io">"1a1b1c1d1e"</span></p>
<p><strong>解释:</strong></p>
<p>初始时,<code>comp = ""</code> 。进行 5 次操作,每次操作分别选择 <code>"a"</code><code>"b"</code><code>"c"</code><code>"d"</code><code>"e"</code> 作为前缀。</p>
<p>对每个前缀,将 <code>"1"</code> 和对应的字符追加到 <code>comp</code></p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">word = "aaaaaaaaaaaaaabb"</span></p>
<p><strong>输出:</strong><span class="example-io">"9a5a2b"</span></p>
<p><strong>解释:</strong></p>
<p>初始时,<code>comp = ""</code>。进行 3 次操作,每次操作分别选择 <code>"aaaaaaaaa"</code><code>"aaaaa"</code><code>"bb"</code> 作为前缀。</p>
<ul>
<li>对于前缀 <code>"aaaaaaaaa"</code>,将 <code>"9"</code><code>"a"</code> 追加到 <code>comp</code></li>
<li>对于前缀 <code>"aaaaa"</code>,将 <code>"5"</code><code>"a"</code> 追加到 <code>comp</code></li>
<li>对于前缀 <code>"bb"</code>,将 <code>"2"</code><code>"b"</code> 追加到 <code>comp</code></li>
</ul>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= word.length &lt;= 2 * 10<sup>5</sup></code></li>
<li><code>word</code> 仅由小写英文字母组成。</li>
</ul>

View File

@ -0,0 +1,43 @@
<p>车尔尼有一个数组&nbsp;<code>nums</code>&nbsp;,它只包含 <strong></strong>&nbsp;整数,所有正整数的数位长度都 <strong>相同</strong>&nbsp;</p>
<p>两个整数的 <strong>数位不同</strong>&nbsp;指的是两个整数 <b>相同</b>&nbsp;位置上不同数字的数目。</p>
<p>请车尔尼返回 <code>nums</code>&nbsp;<strong>所有</strong>&nbsp;整数对里,<strong>数位不同之和。</strong></p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>nums = [13,23,12]</span></p>
<p><b>输出:</b>4</p>
<p><strong>解释:</strong><br />
计算过程如下:<br />
-&nbsp;<strong>1</strong>3 和&nbsp;<strong>2</strong>3 的数位不同为&nbsp;1 。<br />
- 1<strong>3</strong> 和 1<strong>2</strong>&nbsp;的数位不同为&nbsp;1 。<br />
-&nbsp;<strong>23</strong>&nbsp;<strong>12</strong>&nbsp;的数位不同为&nbsp;2 。<br />
所以所有整数数对的数位不同之和为&nbsp;<code>1 + 1 + 2 = 4</code>&nbsp;</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>nums = [10,10,10,10]</span></p>
<p><span class="example-io"><b>输出:</b>0</span></p>
<p><strong>解释:</strong><br />
数组中所有整数都相同,所以所有整数数对的数位不同之和为 0 。</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>2 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i] &lt; 10<sup>9</sup></code></li>
<li><code>nums</code>&nbsp;中的整数都有相同的数位长度。</li>
</ul>

View File

@ -0,0 +1,60 @@
<p>给你一个整数&nbsp;<code>limit</code>&nbsp;和一个大小为 <code>n x 2</code>&nbsp;的二维数组&nbsp;<code>queries</code>&nbsp;</p>
<p>总共有&nbsp;<code>limit + 1</code>&nbsp;个球,每个球的编号为&nbsp;<code>[0, limit]</code>&nbsp;中一个&nbsp;<strong>互不相同</strong>&nbsp;的数字。一开始,所有球都没有颜色。<code>queries</code>&nbsp;中每次操作的格式为&nbsp;<code>[x, y]</code>&nbsp;,你需要将球&nbsp;<code>x</code>&nbsp;染上颜色&nbsp;<code>y</code>&nbsp;。每次操作之后,你需要求出所有球中&nbsp;<strong>不同</strong>&nbsp;颜色的数目。</p>
<p>请你返回一个长度为 <code>n</code>&nbsp;的数组&nbsp;<code>result</code>&nbsp;,其中&nbsp;<code>result[i]</code>&nbsp;是第 <code>i</code>&nbsp;次操作以后不同颜色的数目。</p>
<p><strong>注意</strong>&nbsp;,没有染色的球不算作一种颜色。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>limit = 4, queries = [[1,4],[2,5],[1,3],[3,4]]</span></p>
<p><span class="example-io"><b>输出:</b>[1,2,2,3]</span></p>
<p><strong>解释:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/04/17/ezgifcom-crop.gif" style="width: 455px; height: 145px;" /></p>
<ul>
<li>操作 0&nbsp;后,球 1 颜色为 4 。</li>
<li>操作 1 后,球 1 颜色为&nbsp;4 ,球 2 颜色为 5 。</li>
<li>操作 2 后,球 1 颜色为 3 ,球 2 颜色为 5 。</li>
<li>操作 3 后,球 1 颜色为 3 ,球 2 颜色为 5 ,球 3 颜色为 4 。</li>
</ul>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>limit = 4, queries = [[0,1],[1,2],[2,2],[3,4],[4,5]]</span></p>
<p><span class="example-io"><b>输出:</b>[1,2,2,3,4]</span></p>
<p><strong>解释:</strong></p>
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/04/17/ezgifcom-crop2.gif" style="width: 457px; height: 144px;" /></strong></p>
<ul>
<li>操作 0&nbsp;后,球 0&nbsp;颜色为 1&nbsp;</li>
<li>操作 1&nbsp;后,球 0&nbsp;颜色为 1 ,球 1 颜色为 2 。</li>
<li>操作 2&nbsp;后,球 0&nbsp;颜色为 1 ,球 1 和 2&nbsp;颜色为 2 。</li>
<li>操作 3 后,球 0&nbsp;颜色为 1 ,球 1 和 2&nbsp;颜色为 2 ,球 3 颜色为 4 。</li>
<li>操作 4&nbsp;后,球 0&nbsp;颜色为 1 ,球 1 和 2&nbsp;颜色为 2 ,球 3 颜色为 4 ,球 4 颜色为 5 。</li>
</ul>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= limit &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= n == queries.length &lt;= 10<sup>5</sup></code></li>
<li><code>queries[i].length == 2</code></li>
<li><code>0 &lt;= queries[i][0] &lt;= limit</code></li>
<li><code>1 &lt;= queries[i][1] &lt;= 10<sup>9</sup></code></li>
</ul>

View File

@ -0,0 +1,53 @@
<p>给你一个数组&nbsp;<code>nums</code>&nbsp;和一个整数&nbsp;<code>k</code>&nbsp;。你需要找到&nbsp;<code>nums</code>&nbsp;的一个&nbsp;<span data-keyword="subarray-nonempty">子数组</span>&nbsp;,满足子数组中所有元素按位与运算&nbsp;<code>AND</code>&nbsp;的值与 <code>k</code>&nbsp;<strong>绝对差</strong>&nbsp;尽可能 <strong></strong>&nbsp;。换言之,你需要选择一个子数组&nbsp;<code>nums[l..r]</code>&nbsp;满足&nbsp;<code>|k - (nums[l] AND nums[l + 1] ... AND nums[r])|</code>&nbsp;最小。</p>
<p>请你返回 <strong>最小</strong>&nbsp;的绝对差值。</p>
<p><strong>子数组</strong>是数组中连续的&nbsp;<strong>非空</strong>&nbsp;元素序列。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>nums = [1,2,4,5], k = 3</span></p>
<p><span class="example-io"><b>输出:</b>1</span></p>
<p><strong>解释:</strong></p>
<p>子数组&nbsp;<code>nums[2..3]</code> 的按位&nbsp;<code>AND</code>&nbsp;运算值为 4 ,得到最小差值&nbsp;<code>|3 - 4| = 1</code>&nbsp;</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>nums = [1,2,1,2], k = 2</span></p>
<p><span class="example-io"><b>输出:</b>0</span></p>
<p><strong>解释:</strong></p>
<p>子数组&nbsp;<code>nums[1..1]</code> 的按位&nbsp;<code>AND</code>&nbsp;运算值为 2 ,得到最小差值&nbsp;<code>|2 - 2| = 0</code>&nbsp;</p>
</div>
<p><strong class="example">示例 3</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>nums = [1], k = 10</span></p>
<p><span class="example-io"><b>输出:</b>9</span></p>
<p><strong>解释:</strong></p>
<p>只有一个子数组,按位&nbsp;<code>AND</code>&nbsp;运算值为 1 ,得到最小差值&nbsp;<code>|10 - 1| = 9</code>&nbsp;</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= k &lt;= 10<sup>9</sup></code></li>
</ul>

View File

@ -0,0 +1,54 @@
<p>给你一个正整数 <code>days</code>,表示员工可工作的总天数(从第 1 天开始)。另给你一个二维数组 <code>meetings</code>,长度为 <code>n</code>,其中 <code>meetings[i] = [start_i, end_i]</code> 表示第 <code>i</code> 次会议的开始和结束天数(包含首尾)。</p>
<p>返回员工可工作且没有安排会议的天数。</p>
<p><strong>注意:</strong>会议时间可能会有重叠。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">days = 10, meetings = [[5,7],[1,3],[9,10]]</span></p>
<p><strong>输出:</strong><span class="example-io">2</span></p>
<p><strong>解释:</strong></p>
<p>第 4 天和第 8 天没有安排会议。</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">days = 5, meetings = [[2,4],[1,3]]</span></p>
<p><strong>输出:</strong><span class="example-io">1</span></p>
<p><strong>解释:</strong></p>
<p>第 5 天没有安排会议。</p>
</div>
<p><strong class="example">示例 3</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">days = 6, meetings = [[1,6]]</span></p>
<p><strong>输出:</strong>0</p>
<p><strong>解释:</strong></p>
<p>所有工作日都安排了会议。</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= days &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= meetings.length &lt;= 10<sup>5</sup></code></li>
<li><code>meetings[i].length == 2</code></li>
<li><code>1 &lt;= meetings[i][0] &lt;= meetings[i][1] &lt;= days</code></li>
</ul>

View File

@ -0,0 +1,48 @@
<p>给你一个整数数组&nbsp;<code>nums</code>&nbsp;,一个整数数组&nbsp;<code>queries</code>&nbsp;和一个整数&nbsp;<code>x</code>&nbsp;</p>
<p>对于每个查询&nbsp;<code>queries[i]</code>&nbsp;,你需要找到&nbsp;<code>nums</code>&nbsp;中第&nbsp;<code>queries[i]</code>&nbsp;&nbsp;<code>x</code>&nbsp;的位置,并返回它的下标。如果数组中&nbsp;<code>x</code>&nbsp;的出现次数少于&nbsp;<code>queries[i]</code>&nbsp;,该查询的答案为 -1 。</p>
<p>请你返回一个整数数组&nbsp;<code>answer</code>&nbsp;,包含所有查询的答案。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>nums = [1,3,1,7], queries = [1,3,2,4], x = 1</span></p>
<p><span class="example-io"><b>输出:</b>[0,-1,2,-1]</span></p>
<p><strong>解释:</strong></p>
<ul>
<li>第 1 个查询,第一个 1 出现在下标 0 处。</li>
<li>第 2 个查询,<code>nums</code>&nbsp;中只有两个 1 ,所以答案为 -1 。</li>
<li>第 3 个查询,第二个 1 出现在下标 2 处。</li>
<li>第 4 个查询,<code>nums</code>&nbsp;中只有两个 1 ,所以答案为 -1 。</li>
</ul>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>nums = [1,2,3], queries = [10], x = 5</span></p>
<p><span class="example-io"><b>输出:</b>[-1]</span></p>
<p><strong>解释:</strong></p>
<ul>
<li>第 1 个查询,<code>nums</code>&nbsp;中没有 5 ,所以答案为 -1 。</li>
</ul>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length, queries.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= queries[i] &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i], x &lt;= 10<sup>4</sup></code></li>
</ul>

View File

@ -0,0 +1,51 @@
<p>给你一个数组&nbsp;<code>nums</code>&nbsp;,数组中的数字 <strong>要么</strong> 出现一次,<strong>要么</strong>&nbsp;出现两次。</p>
<p>请你返回数组中所有出现两次数字的按位<em>&nbsp;</em><code>XOR</code>&nbsp;值,如果没有数字出现过两次,返回 0 。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>nums = [1,2,1,3]</span></p>
<p><span class="example-io"><b>输出:</b>1</span></p>
<p><strong>解释:</strong></p>
<p><code>nums</code>&nbsp;中唯一出现过两次的数字是 1 。</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>nums = [1,2,3]</span></p>
<p><span class="example-io"><b>输出:</b>0</span></p>
<p><strong>解释:</strong></p>
<p><code>nums</code>&nbsp;中没有数字出现两次。</p>
</div>
<p><strong class="example">示例 3</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>nums = [1,2,2,1]</span></p>
<p><span class="example-io"><b>输出:</b>3</span></p>
<p><strong>解释:</strong></p>
<p>数字 1 和&nbsp;2 出现过两次。<code>1 XOR 2 == 3</code>&nbsp;</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 50</code></li>
<li><code>1 &lt;= nums[i] &lt;= 50</code></li>
<li><code>nums</code>&nbsp;中每个数字要么出现过一次,要么出现过两次。</li>
</ul>

View File

@ -0,0 +1,56 @@
<p>有一条无限长的数轴,原点在 0 处,沿着 x 轴 <strong></strong>&nbsp;方向无限延伸。</p>
<p>给你一个二维数组&nbsp;<code>queries</code>&nbsp;,它包含两种操作:</p>
<ol>
<li>操作类型 1 <code>queries[i] = [1, x]</code>&nbsp;。在距离原点 <code>x</code>&nbsp;处建一个障碍物。数据保证当操作执行的时候,位置 <code>x</code>&nbsp;<strong>没有</strong>&nbsp;任何障碍物。</li>
<li>操作类型 2 <code>queries[i] = [2, x, sz]</code>&nbsp;。判断在数轴范围&nbsp;<code>[0, x]</code>&nbsp;内是否可以放置一个长度为&nbsp;<code>sz</code>&nbsp;的物块,这个物块需要&nbsp;<strong>完全</strong>&nbsp;放置在范围&nbsp;<code>[0, x]</code>&nbsp;内。如果物块与任何障碍物有重合,那么这个物块&nbsp;<strong>不能</strong>&nbsp;被放置,但物块可以与障碍物刚好接触。注意,你只是进行查询,并&nbsp;<strong>不是</strong>&nbsp;真的放置这个物块。每个查询都是相互独立的。</li>
</ol>
<p>请你返回一个 boolean 数组<code>results</code>&nbsp;,如果第&nbsp;<code>i</code> 个操作类型 2 的操作你可以放置物块,那么&nbsp;<code>results[i]</code>&nbsp;&nbsp;<code>true</code>&nbsp;,否则为 <code>false</code>&nbsp;</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>queries = [[1,2],[2,3,3],[2,3,1],[2,2,2]]</span></p>
<p><span class="example-io"><b>输出:</b>[false,true,true]</span></p>
<p><strong>解释:</strong></p>
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/04/22/example0block.png" style="padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; width: 309px; height: 129px;" /></strong></p>
<p>查询 0 ,在&nbsp;<code>x = 2</code>&nbsp;处放置一个障碍物。在&nbsp;<code>x = 3</code>&nbsp;之前任何大小不超过 2 的物块都可以被放置。</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>queries = </span>[[1,7],[2,7,6],[1,2],[2,7,5],[2,7,6]]<!-- notionvc: 4a471445-5af1-4d72-b11b-94d351a2c8e9 --></p>
<p><b>输出:</b>[true,true,false]</p>
<p><strong>解释:</strong></p>
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/04/22/example1block.png" style="padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; width: 310px; height: 130px;" /></strong></p>
<ul>
<li>查询 0 在&nbsp;<code>x = 7</code>&nbsp;处放置一个障碍物。在&nbsp;<code>x = 7</code>&nbsp;之前任何大小不超过 7 的物块都可以被放置。</li>
<li>查询 2 在&nbsp;<code>x = 2</code>&nbsp;处放置一个障碍物。现在,在&nbsp;<code>x = 7</code>&nbsp;之前任何大小不超过 5 的物块可以被放置,<code>x = 2</code>&nbsp;之前任何大小不超过 2 的物块可以被放置。</li>
</ul>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= queries.length &lt;= 15 * 10<sup>4</sup></code></li>
<li><code>2 &lt;= queries[i].length &lt;= 3</code></li>
<li><code>1 &lt;= queries[i][0] &lt;= 2</code></li>
<li><code>1 &lt;= x, sz &lt;= min(5 * 10<sup>4</sup>, 3 * queries.length)</code></li>
<li>输入保证操作 1 中,<code>x</code>&nbsp;处不会有障碍物。</li>
<li>输入保证至少有一个操作类型 2 。</li>
</ul>

View File

@ -0,0 +1,50 @@
<p>如果数组的每一对相邻元素都是两个奇偶性不同的数字,则该数组被认为是一个 <strong>特殊数组</strong></p>
<p>Aging 有一个整数数组 <code>nums</code>。如果 <code>nums</code> 是一个 <strong>特殊数组</strong> ,返回 <code>true</code>,否则返回 <code>false</code></p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">nums = [1]</span></p>
<p><strong>输出:</strong><span class="example-io">true</span></p>
<p><strong>解释:</strong></p>
<p>只有一个元素,所以答案为 <code>true</code></p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">nums = [2,1,4]</span></p>
<p><strong>输出:</strong><span class="example-io">true</span></p>
<p><strong>解释:</strong></p>
<p>只有两对相邻元素: <code>(2,1)</code><code>(1,4)</code>,它们都包含了奇偶性不同的数字,因此答案为 <code>true</code></p>
</div>
<p><strong class="example">示例 3</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">nums = [4,3,1,6]</span></p>
<p><strong>输出:</strong><span class="example-io">false</span></p>
<p><strong>解释:</strong></p>
<p><code>nums[1]</code><code>nums[2]</code> 都是奇数。因此答案为 <code>false</code></p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
<li><code>1 &lt;= nums[i] &lt;= 100</code></li>
</ul>

View File

@ -0,0 +1,46 @@
<p>如果数组的每一对相邻元素都是两个奇偶性不同的数字,则该数组被认为是一个 <strong>特殊数组</strong></p>
<p>周洋哥有一个整数数组 <code>nums</code> 和一个二维整数矩阵 <code>queries</code>,对于 <code>queries[i] = [from<sub>i</sub>, to<sub>i</sub>]</code>,请你帮助周洋哥检查子数组 <code>nums[from<sub>i</sub>..to<sub>i</sub>]</code> 是不是一个 <strong>特殊数组 </strong></p>
<p>返回布尔数组 <code>answer</code>,如果 <code>nums[from<sub>i</sub>..to<sub>i</sub>]</code> 是特殊数组,则 <code>answer[i]</code><code>true</code> ,否则,<code>answer[i]</code><code>false</code></p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">nums = [3,4,1,2,6], queries = [[0,4]]</span></p>
<p><strong>输出:</strong><span class="example-io">[false]</span></p>
<p><strong>解释:</strong></p>
<p>子数组是 <code>[3,4,1,2,6]</code>。2 和 6 都是偶数。</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">nums = [4,3,1,6], queries = [[0,2],[2,3]]</span></p>
<p><strong>输出:</strong><span class="example-io">[false,true]</span></p>
<p><strong>解释:</strong></p>
<ol>
<li>子数组是 <code>[4,3,1]</code>。3 和 1 都是奇数。因此这个查询的答案是 <code>false</code></li>
<li>子数组是 <code>[1,6]</code>。只有一对:<code>(1,6)</code>,且包含了奇偶性不同的数字。因此这个查询的答案是 <code>true</code></li>
</ol>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= queries.length &lt;= 10<sup>5</sup></code></li>
<li><code>queries[i].length == 2</code></li>
<li><code>0 &lt;= queries[i][0] &lt;= queries[i][1] &lt;= nums.length - 1</code></li>
</ul>

View File

@ -0,0 +1,45 @@
<p>You are given an array <code>nums</code> consisting of integers. You are also given a 2D array <code>queries</code>, where <code>queries[i] = [pos<sub>i</sub>, x<sub>i</sub>]</code>.</p>
<p>For query <code>i</code>, we first set <code>nums[pos<sub>i</sub>]</code> equal to <code>x<sub>i</sub></code>, then we calculate the answer to query <code>i</code> which is the <strong>maximum</strong> sum of a <span data-keyword="subsequence-array">subsequence</span> of <code>nums</code> where <strong>no two adjacent elements are selected</strong>.</p>
<p>Return the <em>sum</em> of the answers to all queries.</p>
<p>Since the final answer may be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</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>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [3,5,9], queries = [[1,-2],[0,-3]]</span></p>
<p><strong>Output:</strong> <span class="example-io">21</span></p>
<p><strong>Explanation:</strong><br />
After the 1<sup>st</sup> query, <code>nums = [3,-2,9]</code> and the maximum sum of a subsequence with non-adjacent elements is <code>3 + 9 = 12</code>.<br />
After the 2<sup>nd</sup> query, <code>nums = [-3,-2,9]</code> and the maximum sum of a subsequence with non-adjacent elements is 9.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [0,-1], queries = [[0,-5]]</span></p>
<p><strong>Output:</strong> <span class="example-io">0</span></p>
<p><strong>Explanation:</strong><br />
After the 1<sup>st</sup> query, <code>nums = [-5,-1]</code> and the maximum sum of a subsequence with non-adjacent elements is 0 (choosing an empty subsequence).</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>-10<sup>5</sup> &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= queries.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>queries[i] == [pos<sub>i</sub>, x<sub>i</sub>]</code></li>
<li><code>0 &lt;= pos<sub>i</sub> &lt;= nums.length - 1</code></li>
<li><code>-10<sup>5</sup> &lt;= x<sub>i</sub> &lt;= 10<sup>5</sup></code></li>
</ul>

View File

@ -0,0 +1,37 @@
<p>You are given 2 integer arrays <code>nums1</code> and <code>nums2</code> of lengths <code>n</code> and <code>m</code> respectively. You are also given a <strong>positive</strong> integer <code>k</code>.</p>
<p>A pair <code>(i, j)</code> is called <strong>good</strong> if <code>nums1[i]</code> is divisible by <code>nums2[j] * k</code> (<code>0 &lt;= i &lt;= n - 1</code>, <code>0 &lt;= j &lt;= m - 1</code>).</p>
<p>Return the total number of <strong>good</strong> pairs.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums1 = [1,3,4], nums2 = [1,3,4], k = 1</span></p>
<p><strong>Output:</strong> <span class="example-io">5</span></p>
<p><strong>Explanation:</strong></p>
The 5 good pairs are <code>(0, 0)</code>, <code>(1, 0)</code>, <code>(1, 1)</code>, <code>(2, 0)</code>, and <code>(2, 2)</code>.</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums1 = [1,2,4,12], nums2 = [2,4], k = 3</span></p>
<p><strong>Output:</strong> <span class="example-io">2</span></p>
<p><strong>Explanation:</strong></p>
<p>The 2 good pairs are <code>(3, 0)</code> and <code>(3, 1)</code>.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= n, m &lt;= 50</code></li>
<li><code>1 &lt;= nums1[i], nums2[j] &lt;= 50</code></li>
<li><code>1 &lt;= k &lt;= 50</code></li>
</ul>

View File

@ -0,0 +1,37 @@
<p>You are given 2 integer arrays <code>nums1</code> and <code>nums2</code> of lengths <code>n</code> and <code>m</code> respectively. You are also given a <strong>positive</strong> integer <code>k</code>.</p>
<p>A pair <code>(i, j)</code> is called <strong>good</strong> if <code>nums1[i]</code> is divisible by <code>nums2[j] * k</code> (<code>0 &lt;= i &lt;= n - 1</code>, <code>0 &lt;= j &lt;= m - 1</code>).</p>
<p>Return the total number of <strong>good</strong> pairs.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums1 = [1,3,4], nums2 = [1,3,4], k = 1</span></p>
<p><strong>Output:</strong> <span class="example-io">5</span></p>
<p><strong>Explanation:</strong></p>
The 5 good pairs are <code>(0, 0)</code>, <code>(1, 0)</code>, <code>(1, 1)</code>, <code>(2, 0)</code>, and <code>(2, 2)</code>.</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums1 = [1,2,4,12], nums2 = [2,4], k = 3</span></p>
<p><strong>Output:</strong> <span class="example-io">2</span></p>
<p><strong>Explanation:</strong></p>
<p>The 2 good pairs are <code>(3, 0)</code> and <code>(3, 1)</code>.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= n, m &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums1[i], nums2[j] &lt;= 10<sup>6</sup></code></li>
<li><code>1 &lt;= k &lt;= 10<sup>3</sup></code></li>
</ul>

View File

@ -0,0 +1,178 @@
<p>You are given a string <code>s</code>. Simulate events at each second <code>i</code>:</p>
<ul>
<li>If <code>s[i] == &#39;E&#39;</code>, a person enters the waiting room and takes one of the chairs in it.</li>
<li>If <code>s[i] == &#39;L&#39;</code>, a person leaves the waiting room, freeing up a chair.</li>
</ul>
<p>Return the <strong>minimum </strong>number of chairs needed so that a chair is available for every person who enters the waiting room given that it is initially <strong>empty</strong>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;EEEEEEE&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">7</span></p>
<p><strong>Explanation:</strong></p>
<p>After each second, a person enters the waiting room and no person leaves it. Therefore, a minimum of 7 chairs is needed.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;ELELEEL&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">2</span></p>
<p><strong>Explanation:</strong></p>
<p>Let&#39;s consider that there are 2 chairs in the waiting room. The table below shows the state of the waiting room at each second.</p>
</div>
<table>
<tbody>
<tr>
<th>Second</th>
<th>Event</th>
<th>People in the Waiting Room</th>
<th>Available Chairs</th>
</tr>
<tr>
<td>0</td>
<td>Enter</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>1</td>
<td>Leave</td>
<td>0</td>
<td>2</td>
</tr>
<tr>
<td>2</td>
<td>Enter</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>3</td>
<td>Leave</td>
<td>0</td>
<td>2</td>
</tr>
<tr>
<td>4</td>
<td>Enter</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>5</td>
<td>Enter</td>
<td>2</td>
<td>0</td>
</tr>
<tr>
<td>6</td>
<td>Leave</td>
<td>1</td>
<td>1</td>
</tr>
</tbody>
</table>
<p><strong class="example">Example 3:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;ELEELEELLL&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">3</span></p>
<p><strong>Explanation:</strong></p>
<p>Let&#39;s consider that there are 3 chairs in the waiting room. The table below shows the state of the waiting room at each second.</p>
</div>
<table>
<tbody>
<tr>
<th>Second</th>
<th>Event</th>
<th>People in the Waiting Room</th>
<th>Available Chairs</th>
</tr>
<tr>
<td>0</td>
<td>Enter</td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>1</td>
<td>Leave</td>
<td>0</td>
<td>3</td>
</tr>
<tr>
<td>2</td>
<td>Enter</td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>Enter</td>
<td>2</td>
<td>1</td>
</tr>
<tr>
<td>4</td>
<td>Leave</td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>5</td>
<td>Enter</td>
<td>2</td>
<td>1</td>
</tr>
<tr>
<td>6</td>
<td>Enter</td>
<td>3</td>
<td>0</td>
</tr>
<tr>
<td>7</td>
<td>Leave</td>
<td>2</td>
<td>1</td>
</tr>
<tr>
<td>8</td>
<td>Leave</td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>9</td>
<td>Leave</td>
<td>0</td>
<td>3</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 50</code></li>
<li><code>s</code> consists only of the letters <code>&#39;E&#39;</code> and <code>&#39;L&#39;</code>.</li>
<li><code>s</code> represents a valid sequence of entries and exits.</li>
</ul>

View File

@ -0,0 +1,43 @@
<p>You are given a string <code>s</code>. It may contain any number of <code>&#39;*&#39;</code> characters. Your task is to remove all <code>&#39;*&#39;</code> characters.</p>
<p>While there is a <code>&#39;*&#39;</code>, do the following operation:</p>
<ul>
<li>Delete the leftmost <code>&#39;*&#39;</code> and the <strong>smallest</strong> non-<code>&#39;*&#39;</code> character to its <em>left</em>. If there are several smallest characters, you can delete any of them.</li>
</ul>
<p>Return the <span data-keyword="lexicographically-smaller-string">lexicographically smallest</span> resulting string after removing all <code>&#39;*&#39;</code> characters.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;aaba*&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">&quot;aab&quot;</span></p>
<p><strong>Explanation:</strong></p>
<p>We should delete one of the <code>&#39;a&#39;</code> characters with <code>&#39;*&#39;</code>. If we choose <code>s[3]</code>, <code>s</code> becomes the lexicographically smallest.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;abc&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">&quot;abc&quot;</span></p>
<p><strong>Explanation:</strong></p>
<p>There is no <code>&#39;*&#39;</code> in the string.<!-- notionvc: ff07e34f-b1d6-41fb-9f83-5d0ba3c1ecde --></p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
<li><code>s</code> consists only of lowercase English letters and <code>&#39;*&#39;</code>.</li>
<li>The input is generated such that it is possible to delete all <code>&#39;*&#39;</code> characters.</li>
</ul>

View File

@ -0,0 +1,84 @@
<p>You are given a <strong>non-negative</strong> integer <code>k</code>. There exists a staircase with an infinite number of stairs, with the <strong>lowest</strong> stair numbered 0.</p>
<p>Alice has an integer <code>jump</code>, with an initial value of 0. She starts on stair 1 and wants to reach stair <code>k</code> using <strong>any</strong> number of <strong>operations</strong>. If she is on stair <code>i</code>, in one <strong>operation</strong> she can:</p>
<ul>
<li>Go down to stair <code>i - 1</code>. This operation <strong>cannot</strong> be used consecutively or on stair 0.</li>
<li>Go up to stair <code>i + 2<sup>jump</sup></code>. And then, <code>jump</code> becomes <code>jump + 1</code>.</li>
</ul>
<p>Return the <em>total</em> number of ways Alice can reach stair <code>k</code>.</p>
<p><strong>Note</strong> that it is possible that Alice reaches the stair <code>k</code>, and performs some operations to reach the stair <code>k</code> again.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">k = 0</span></p>
<p><strong>Output:</strong> <span class="example-io">2</span></p>
<p><strong>Explanation:</strong></p>
<p>The 2 possible ways of reaching stair 0 are:</p>
<ul>
<li>Alice starts at stair 1.
<ul>
<li>Using an operation of the first type, she goes down 1 stair to reach stair 0.</li>
</ul>
</li>
<li>Alice starts at stair 1.
<ul>
<li>Using an operation of the first type, she goes down 1 stair to reach stair 0.</li>
<li>Using an operation of the second type, she goes up 2<sup>0</sup> stairs to reach stair 1.</li>
<li>Using an operation of the first type, she goes down 1 stair to reach stair 0.</li>
</ul>
</li>
</ul>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">k = 1</span></p>
<p><strong>Output:</strong> <span class="example-io">4</span></p>
<p><strong>Explanation:</strong></p>
<p>The 4 possible ways of reaching stair 1 are:</p>
<ul>
<li>Alice starts at stair 1. Alice is at stair 1.</li>
<li>Alice starts at stair 1.
<ul>
<li>Using an operation of the first type, she goes down 1 stair to reach stair 0.</li>
<li>Using an operation of the second type, she goes up 2<sup>0</sup> stairs to reach stair 1.</li>
</ul>
</li>
<li>Alice starts at stair 1.
<ul>
<li>Using an operation of the second type, she goes up 2<sup>0</sup> stairs to reach stair 2.</li>
<li>Using an operation of the first type, she goes down 1 stair to reach stair 1.</li>
</ul>
</li>
<li>Alice starts at stair 1.
<ul>
<li>Using an operation of the first type, she goes down 1 stair to reach stair 0.</li>
<li>Using an operation of the second type, she goes up 2<sup>0</sup> stairs to reach stair 1.</li>
<li>Using an operation of the first type, she goes down 1 stair to reach stair 0.</li>
<li>Using an operation of the second type, she goes up 2<sup>1</sup> stairs to reach stair 2.</li>
<li>Using an operation of the first type, she goes down 1 stair to reach stair 1.</li>
</ul>
</li>
</ul>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>0 &lt;= k &lt;= 10<sup>9</sup></code></li>
</ul>

View File

@ -0,0 +1,54 @@
<p>Given a string <code>word</code>, compress it using the following algorithm:</p>
<ul>
<li>Begin with an empty string <code>comp</code>. While <code>word</code> is <strong>not</strong> empty, use the following operation:
<ul>
<li>Remove a maximum length prefix of <code>word</code> made of a <em>single character</em> <code>c</code> repeating <strong>at most</strong> 9 times.</li>
<li>Append the length of the prefix followed by <code>c</code> to <code>comp</code>.</li>
</ul>
</li>
</ul>
<p>Return the string <code>comp</code>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">word = &quot;abcde&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">&quot;1a1b1c1d1e&quot;</span></p>
<p><strong>Explanation:</strong></p>
<p>Initially, <code>comp = &quot;&quot;</code>. Apply the operation 5 times, choosing <code>&quot;a&quot;</code>, <code>&quot;b&quot;</code>, <code>&quot;c&quot;</code>, <code>&quot;d&quot;</code>, and <code>&quot;e&quot;</code> as the prefix in each operation.</p>
<p>For each prefix, append <code>&quot;1&quot;</code> followed by the character to <code>comp</code>.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">word = &quot;aaaaaaaaaaaaaabb&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">&quot;9a5a2b&quot;</span></p>
<p><strong>Explanation:</strong></p>
<p>Initially, <code>comp = &quot;&quot;</code>. Apply the operation 3 times, choosing <code>&quot;aaaaaaaaa&quot;</code>, <code>&quot;aaaaa&quot;</code>, and <code>&quot;bb&quot;</code> as the prefix in each operation.</p>
<ul>
<li>For prefix <code>&quot;aaaaaaaaa&quot;</code>, append <code>&quot;9&quot;</code> followed by <code>&quot;a&quot;</code> to <code>comp</code>.</li>
<li>For prefix <code>&quot;aaaaa&quot;</code>, append <code>&quot;5&quot;</code> followed by <code>&quot;a&quot;</code> to <code>comp</code>.</li>
<li>For prefix <code>&quot;bb&quot;</code>, append <code>&quot;2&quot;</code> followed by <code>&quot;b&quot;</code> to <code>comp</code>.</li>
</ul>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= word.length &lt;= 2 * 10<sup>5</sup></code></li>
<li><code>word</code> consists only of lowercase English letters.</li>
</ul>

View File

@ -0,0 +1,41 @@
<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers where all integers have the <strong>same</strong> number of digits.</p>
<p>The <strong>digit difference</strong> between two integers is the <em>count</em> of different digits that are in the <strong>same</strong> position in the two integers.</p>
<p>Return the <strong>sum</strong> of the <strong>digit differences</strong> between <strong>all</strong> pairs of integers in <code>nums</code>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [13,23,12]</span></p>
<p><strong>Output:</strong> 4</p>
<p><strong>Explanation:</strong><br />
We have the following:<br />
- The digit difference between <strong>1</strong>3 and <strong>2</strong>3 is 1.<br />
- The digit difference between 1<strong>3</strong> and 1<strong>2</strong> is 1.<br />
- The digit difference between <strong>23</strong> and <strong>12</strong> is 2.<br />
So the total sum of digit differences between all pairs of integers is <code>1 + 1 + 2 = 4</code>.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [10,10,10,10]</span></p>
<p><strong>Output:</strong> <span class="example-io">0</span></p>
<p><strong>Explanation:</strong><br />
All the integers in the array are the same. So the total sum of digit differences between all pairs of integers will be 0.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>2 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i] &lt; 10<sup>9</sup></code></li>
<li>All integers in <code>nums</code> have the same number of digits.</li>
</ul>

View File

@ -0,0 +1,58 @@
<p>You are given an integer <code>limit</code> and a 2D array <code>queries</code> of size <code>n x 2</code>.</p>
<p>There are <code>limit + 1</code> balls with <strong>distinct</strong> labels in the range <code>[0, limit]</code>. Initially, all balls are uncolored. For every query in <code>queries</code> that is of the form <code>[x, y]</code>, you mark ball <code>x</code> with the color <code>y</code>. After each query, you need to find the number of <strong>distinct</strong> colors among the balls.</p>
<p>Return an array <code>result</code> of length <code>n</code>, where <code>result[i]</code> denotes the number of distinct colors <em>after</em> <code>i<sup>th</sup></code> query.</p>
<p><strong>Note</strong> that when answering a query, lack of a color <em>will not</em> be considered as a color.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">limit = 4, queries = [[1,4],[2,5],[1,3],[3,4]]</span></p>
<p><strong>Output:</strong> <span class="example-io">[1,2,2,3]</span></p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/04/17/ezgifcom-crop.gif" style="width: 455px; height: 145px;" /></p>
<ul>
<li>After query 0, ball 1 has color 4.</li>
<li>After query 1, ball 1 has color 4, and ball 2 has color 5.</li>
<li>After query 2, ball 1 has color 3, and ball 2 has color 5.</li>
<li>After query 3, ball 1 has color 3, ball 2 has color 5, and ball 3 has color 4.</li>
</ul>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">limit = 4, queries = [[0,1],[1,2],[2,2],[3,4],[4,5]]</span></p>
<p><strong>Output:</strong> <span class="example-io">[1,2,2,3,4]</span></p>
<p><strong>Explanation:</strong></p>
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/04/17/ezgifcom-crop2.gif" style="width: 457px; height: 144px;" /></strong></p>
<ul>
<li>After query 0, ball 0 has color 1.</li>
<li>After query 1, ball 0 has color 1, and ball 1 has color 2.</li>
<li>After query 2, ball 0 has color 1, and balls 1 and 2 have color 2.</li>
<li>After query 3, ball 0 has color 1, balls 1 and 2 have color 2, and ball 3 has color 4.</li>
<li>After query 4, ball 0 has color 1, balls 1 and 2 have color 2, ball 3 has color 4, and ball 4 has color 5.</li>
</ul>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= limit &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= n == queries.length &lt;= 10<sup>5</sup></code></li>
<li><code>queries[i].length == 2</code></li>
<li><code>0 &lt;= queries[i][0] &lt;= limit</code></li>
<li><code>1 &lt;= queries[i][1] &lt;= 10<sup>9</sup></code></li>
</ul>

View File

@ -0,0 +1,51 @@
<p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>AND</code> of the subarray elements is as<strong> small</strong> as possible. In other words, select a subarray <code>nums[l..r]</code> such that <code>|k - (nums[l] AND nums[l + 1] ... AND nums[r])|</code> is minimum.</p>
<p>Return the <strong>minimum</strong> possible value of the absolute difference.</p>
<p>A <strong>subarray</strong> is a contiguous <b>non-empty</b> sequence of elements within an array.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,4,5], k = 3</span></p>
<p><strong>Output:</strong> <span class="example-io">1</span></p>
<p><strong>Explanation:</strong></p>
<p>The subarray <code>nums[2..3]</code> has <code>AND</code> value 4, which gives the minimum absolute difference <code>|3 - 4| = 1</code>.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,1,2], k = 2</span></p>
<p><strong>Output:</strong> <span class="example-io">0</span></p>
<p><strong>Explanation:</strong></p>
<p>The subarray <code>nums[1..1]</code> has <code>AND</code> value 2, which gives the minimum absolute difference <code>|2 - 2| = 0</code>.</p>
</div>
<p><strong class="example">Example 3:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [1], k = 10</span></p>
<p><strong>Output:</strong> <span class="example-io">9</span></p>
<p><strong>Explanation:</strong></p>
<p>There is a single subarray with <code>AND</code> value 1, which gives the minimum absolute difference <code>|10 - 1| = 9</code>.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= k &lt;= 10<sup>9</sup></code></li>
</ul>

View File

@ -0,0 +1,52 @@
<p>You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of meeting <code>i</code> (inclusive).</p>
<p>Return the count of days when the employee is available for work but no meetings are scheduled.</p>
<p><strong>Note: </strong>The meetings may overlap.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">days = 10, meetings = [[5,7],[1,3],[9,10]]</span></p>
<p><strong>Output:</strong> <span class="example-io">2</span></p>
<p><strong>Explanation:</strong></p>
<p>There is no meeting scheduled on the 4<sup>th</sup> and 8<sup>th</sup> days.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">days = 5, meetings = [[2,4],[1,3]]</span></p>
<p><strong>Output:</strong> <span class="example-io">1</span></p>
<p><strong>Explanation:</strong></p>
<p>There is no meeting scheduled on the 5<sup>th </sup>day.</p>
</div>
<p><strong class="example">Example 3:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">days = 6, meetings = [[1,6]]</span></p>
<p><strong>Output:</strong> 0</p>
<p><strong>Explanation:</strong></p>
<p>Meetings are scheduled for all working days.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= days &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= meetings.length &lt;= 10<sup>5</sup></code></li>
<li><code>meetings[i].length == 2</code></li>
<li><code><font face="monospace">1 &lt;= meetings[i][0] &lt;= meetings[i][1] &lt;= days</font></code></li>
</ul>

View File

@ -0,0 +1,46 @@
<p>You are given an integer array <code>nums</code>, an integer array <code>queries</code>, and an integer <code>x</code>.</p>
<p>For each <code>queries[i]</code>, you need to find the index of the <code>queries[i]<sup>th</sup></code> occurrence of <code>x</code> in the <code>nums</code> array. If there are fewer than <code>queries[i]</code> occurrences of <code>x</code>, the answer should be -1 for that query.</p>
<p>Return an integer array <code>answer</code> containing the answers to all queries.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [1,3,1,7], queries = [1,3,2,4], x = 1</span></p>
<p><strong>Output:</strong> <span class="example-io">[0,-1,2,-1]</span></p>
<p><strong>Explanation:</strong></p>
<ul>
<li>For the 1<sup>st</sup> query, the first occurrence of 1 is at index 0.</li>
<li>For the 2<sup>nd</sup> query, there are only two occurrences of 1 in <code>nums</code>, so the answer is -1.</li>
<li>For the 3<sup>rd</sup> query, the second occurrence of 1 is at index 2.</li>
<li>For the 4<sup>th</sup> query, there are only two occurrences of 1 in <code>nums</code>, so the answer is -1.</li>
</ul>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,3], queries = [10], x = 5</span></p>
<p><strong>Output:</strong> <span class="example-io">[-1]</span></p>
<p><strong>Explanation:</strong></p>
<ul>
<li>For the 1<sup>st</sup> query, 5 doesn&#39;t exist in <code>nums</code>, so the answer is -1.</li>
</ul>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= nums.length, queries.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= queries[i] &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i], x &lt;= 10<sup>4</sup></code></li>
</ul>

View File

@ -0,0 +1,49 @@
<p>You are given an array <code>nums</code>, where each number in the array appears <strong>either</strong><em> </em>once<em> </em>or<em> </em>twice.</p>
<p>Return the bitwise<em> </em><code>XOR</code> of all the numbers that appear twice in the array, or 0 if no number appears twice.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,1,3]</span></p>
<p><strong>Output:</strong> <span class="example-io">1</span></p>
<p><strong>Explanation:</strong></p>
<p>The only number that appears twice in&nbsp;<code>nums</code>&nbsp;is 1.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,3]</span></p>
<p><strong>Output:</strong> <span class="example-io">0</span></p>
<p><strong>Explanation:</strong></p>
<p>No number appears twice in&nbsp;<code>nums</code>.</p>
</div>
<p><strong class="example">Example 3:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,2,1]</span></p>
<p><strong>Output:</strong> <span class="example-io">3</span></p>
<p><strong>Explanation:</strong></p>
<p>Numbers 1 and 2 appeared twice. <code>1 XOR 2 == 3</code>.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 50</code></li>
<li><code>1 &lt;= nums[i] &lt;= 50</code></li>
<li>Each number in <code>nums</code> appears either once or twice.</li>
</ul>

View File

@ -0,0 +1,54 @@
<p>There exists an infinite number line, with its origin at 0 and extending towards the <strong>positive</strong> x-axis.</p>
<p>You are given a 2D array <code>queries</code>, which contains two types of queries:</p>
<ol>
<li>For a query of type 1, <code>queries[i] = [1, x]</code>. Build an obstacle at distance <code>x</code> from the origin. It is guaranteed that there is <strong>no</strong> obstacle at distance <code>x</code> when the query is asked.</li>
<li>For a query of type 2, <code>queries[i] = [2, x, sz]</code>. Check if it is possible to place a block of size <code>sz</code> <em>anywhere</em> in the range <code>[0, x]</code> on the line, such that the block <strong>entirely</strong> lies in the range <code>[0, x]</code>. A block <strong>cannot </strong>be placed if it intersects with any obstacle, but it may touch it. Note that you do<strong> not</strong> actually place the block. Queries are separate.</li>
</ol>
<p>Return a boolean array <code>results</code>, where <code>results[i]</code> is <code>true</code> if you can place the block specified in the <code>i<sup>th</sup></code> query of type 2, and <code>false</code> otherwise.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">queries = [[1,2],[2,3,3],[2,3,1],[2,2,2]]</span></p>
<p><strong>Output:</strong> <span class="example-io">[false,true,true]</span></p>
<p><strong>Explanation:</strong></p>
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/04/22/example0block.png" style="padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; width: 309px; height: 129px;" /></strong></p>
<p>For query 0, place an obstacle at <code>x = 2</code>. A block of size at most 2 can be placed before <code>x = 3</code>.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">queries = </span>[[1,7],[2,7,6],[1,2],[2,7,5],[2,7,6]]<!-- notionvc: 4a471445-5af1-4d72-b11b-94d351a2c8e9 --></p>
<p><strong>Output:</strong> [true,true,false]</p>
<p><strong>Explanation:</strong></p>
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/04/22/example1block.png" style="padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; width: 310px; height: 130px;" /></strong></p>
<ul>
<li>Place an obstacle at <code>x = 7</code> for query 0. A block of size at most 7 can be placed before <code>x = 7</code>.</li>
<li>Place an obstacle at <code>x = 2</code> for query 2. Now, a block of size at most 5 can be placed before <code>x = 7</code>, and a block of size at most 2 before <code>x = 2</code>.</li>
</ul>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= queries.length &lt;= 15 * 10<sup>4</sup></code></li>
<li><code>2 &lt;= queries[i].length &lt;= 3</code></li>
<li><code>1 &lt;= queries[i][0] &lt;= 2</code></li>
<li><code>1 &lt;= x, sz &lt;= min(5 * 10<sup>4</sup>, 3 * queries.length)</code></li>
<li>The input is generated such that for queries of type 1, no obstacle exists at distance <code>x</code> when the query is asked.</li>
<li>The input is generated such that there is at least one query of type 2.</li>
</ul>

View File

@ -0,0 +1,48 @@
<p>An array is considered <strong>special</strong> if every pair of its adjacent elements contains two numbers with different parity.<!-- notionvc: e6bed0fa-c67d-43a7-81b4-99fb85b99e98 --></p>
<p>You are given an array of integers <code>nums</code>. Return <code>true</code> if <code>nums</code> is a <strong>special</strong> array, otherwise, return <code>false</code>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [1]</span></p>
<p><strong>Output:</strong> <span class="example-io">true</span></p>
<p><strong>Explanation:</strong></p>
<p>There is only one element. So the answer is <code>true</code>.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [2,1,4]</span></p>
<p><strong>Output:</strong> <span class="example-io">true</span></p>
<p><strong>Explanation:</strong></p>
<p>There is only two pairs: <code>(2,1)</code> and <code>(1,4)</code>, and both of them contain numbers with different parity. So the answer is <code>true</code>.</p>
</div>
<p><strong class="example">Example 3:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [4,3,1,6]</span></p>
<p><strong>Output:</strong> <span class="example-io">false</span></p>
<p><strong>Explanation:</strong></p>
<p><code>nums[1]</code> and <code>nums[2]</code> are both odd. So the answer is <code>false</code>.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
<li><code>1 &lt;= nums[i] &lt;= 100</code></li>
</ul>

View File

@ -0,0 +1,44 @@
<p>An array is considered <strong>special</strong> if every pair of its adjacent elements contains two numbers with different parity.</p>
<p>You are given an array of integer <code>nums</code> and a 2D integer matrix <code>queries</code>, where for <code>queries[i] = [from<sub>i</sub>, to<sub>i</sub>]</code> your task is to check that <span data-keyword="subarray">subarray</span> <code>nums[from<sub>i</sub>..to<sub>i</sub>]</code> is <strong>special</strong> or not.</p>
<p>Return an array of booleans <code>answer</code> such that <code>answer[i]</code> is <code>true</code> if <code>nums[from<sub>i</sub>..to<sub>i</sub>]</code> is special.<!-- notionvc: e5d6f4e2-d20a-4fbd-9c7f-22fbe52ef730 --></p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [3,4,1,2,6], queries = [[0,4]]</span></p>
<p><strong>Output:</strong> <span class="example-io">[false]</span></p>
<p><strong>Explanation:</strong></p>
<p>The subarray is <code>[3,4,1,2,6]</code>. 2 and 6 are both even.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [4,3,1,6], queries = [[0,2],[2,3]]</span></p>
<p><strong>Output:</strong> <span class="example-io">[false,true]</span></p>
<p><strong>Explanation:</strong></p>
<ol>
<li>The subarray is <code>[4,3,1]</code>. 3 and 1 are both odd. So the answer to this query is <code>false</code>.</li>
<li>The subarray is <code>[1,6]</code>. There is only one pair: <code>(1,6)</code> and it contains numbers with different parity. So the answer to this query is <code>true</code>.</li>
</ol>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= queries.length &lt;= 10<sup>5</sup></code></li>
<li><code>queries[i].length == 2</code></li>
<li><code>0 &lt;= queries[i][0] &lt;= queries[i][1] &lt;= nums.length - 1</code></li>
</ul>