1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-04-18 08:39:41 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
zhangbk1 2024-07-16 16:03:30 +08:00
parent 847e599aec
commit 43a450d3d7
88 changed files with 25207 additions and 15592 deletions
README.md
leetcode-cn
origin-data.json
originData
problem (Chinese)
problem (English)
leetcode

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

File diff suppressed because it is too large Load Diff

@ -0,0 +1,60 @@
{
"data": {
"question": {
"questionId": "3512",
"questionFrontendId": "3204",
"categoryTitle": "Database",
"boundTopicId": 2827445,
"title": "Bitwise User Permissions Analysis",
"titleSlug": "bitwise-user-permissions-analysis",
"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\": \"63\", \"totalSubmission\": \"66\", \"totalAcceptedRaw\": 63, \"totalSubmissionRaw\": 66, \"acRate\": \"95.5%\"}",
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "{\"headers\":{\"user_permissions\":[\"user_id\",\"permissions\"]},\"rows\":{\"user_permissions\":[[1,5],[2,12],[3,7],[4,3]]}}",
"metaData": "{\"mysql\":[\"Create table if not exists user_permissions(user_id int, permissions int)\"],\"mssql\":[\"Create table user_permissions(user_id int, permissions int)\"],\"oraclesql\":[\"Create table user_permissions(user_id NUMBER, permissions NUMBER)\"],\"database\":true,\"name\":\"analyze_permissions\",\"postgresql\":[\"CREATE TABLE IF NOT EXISTS user_permissions (\\n user_id int,\\n permissions int\\n);\\n\"],\"pythondata\":[\"user_permissions = pd.DataFrame({\\n 'user_id': pd.Series(dtype='int'),\\n 'permissions': pd.Series(dtype='int')\\n})\"],\"database_schema\":{\"user_permissions\":{\"user_id\":\"INT\",\"permissions\":\"INT\"}}}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [
"Create table if not exists user_permissions(user_id int, permissions int)",
"Truncate table user_permissions",
"insert into user_permissions (user_id, permissions) values ('1', '5')",
"insert into user_permissions (user_id, permissions) values ('2', '12')",
"insert into user_permissions (user_id, permissions) values ('3', '7')",
"insert into user_permissions (user_id, permissions) values ('4', '3')"
],
"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\":{\"user_permissions\":[\"user_id\",\"permissions\"]},\"rows\":{\"user_permissions\":[[1,5],[2,12],[3,7],[4,3]]}}",
"__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,60 @@
{
"data": {
"question": {
"questionId": "3520",
"questionFrontendId": "3214",
"categoryTitle": "Database",
"boundTopicId": 2834912,
"title": "Year on Year Growth Rate",
"titleSlug": "year-on-year-growth-rate",
"content": null,
"translatedTitle": "同比增长率",
"translatedContent": null,
"isPaidOnly": true,
"difficulty": "Hard",
"likes": 0,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
"contributors": [],
"langToValidPlayground": null,
"topicTags": [
{
"name": "Database",
"slug": "database",
"translatedName": "数据库",
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": null,
"stats": "{\"totalAccepted\": \"67\", \"totalSubmission\": \"111\", \"totalAcceptedRaw\": 67, \"totalSubmissionRaw\": 111, \"acRate\": \"60.4%\"}",
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "{\"headers\":{\"user_transactions\":[\"transaction_id\",\"product_id\",\"spend\",\"transaction_date\"]},\"rows\":{\"user_transactions\":[[1341,123424,1500.60,\"2019-12-31 12:00:00\"],[1423,123424,1000.20,\"2020-12-31 12:00:00\"],[1623,123424,1246.44,\"2021-12-31 12:00:00\"],[1322,123424,2145.32,\"2022-12-31 12:00:00\"]]}}",
"metaData": "{\"mysql\":[\"Create Table if not exists user_transactions( transaction_id int, product_id int, spend decimal(10,2), \\ntransaction_date datetime)\"],\"mssql\":[\"Create Table user_transactions( transaction_id int, product_id int, spend decimal(10,2), \\ntransaction_date datetime)\"],\"oraclesql\":[\"Create Table user_transactions( transaction_id NUMBER, product_id NUMBER, spend NUMBER(10,2), \\ntransaction_date date)\",\"ALTER SESSION SET nls_date_format='YYYY-MM-DD HH24:MI:SS'\"],\"database\":true,\"name\":\"calculate_yoy_growth\",\"postgresql\":[\"CREATE TABLE IF NOT EXISTS user_transactions (\\n transaction_id INT,\\n product_id INT,\\n spend NUMERIC(10, 2),\\n transaction_date TIMESTAMP\\n);\\n\"],\"pythondata\":[\"user_transactions = pd.DataFrame(columns=['transaction_id', 'product_id', 'spend', 'transaction_date'], dtype={'transaction_id': 'int', 'product_id': 'int', 'spend': 'float', 'transaction_date': 'datetime64[ns]'})\\n\"],\"database_schema\":{\"user_transactions\":{\"transaction_id\":\"INT\",\"product_id\":\"INT\",\"spend\":\"DECIMAL(10, 2)\",\"transaction_date\":\"DATETIME\"}}}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [
"Create Table if not exists user_transactions( transaction_id int, product_id int, spend decimal(10,2), \ntransaction_date datetime)",
"Truncate table user_transactions",
"insert into user_transactions (transaction_id, product_id, spend, transaction_date) values ('1341', '123424', '1500.6', '2019-12-31 12:00:00')",
"insert into user_transactions (transaction_id, product_id, spend, transaction_date) values ('1423', '123424', '1000.2', '2020-12-31 12:00:00')",
"insert into user_transactions (transaction_id, product_id, spend, transaction_date) values ('1623', '123424', '1246.44', '2021-12-31 12:00:00')",
"insert into user_transactions (transaction_id, product_id, spend, transaction_date) values ('1322', '123424', '2145.32', '2022-12-31 12: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\":{\"user_transactions\":[\"transaction_id\",\"product_id\",\"spend\",\"transaction_date\"]},\"rows\":{\"user_transactions\":[[1341,123424,1500.60,\"2019-12-31 12:00:00\"],[1423,123424,1000.20,\"2020-12-31 12:00:00\"],[1623,123424,1246.44,\"2021-12-31 12:00:00\"],[1322,123424,2145.32,\"2022-12-31 12: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

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

@ -0,0 +1,63 @@
<p>给你两个整数 <code>red</code><code>blue</code>,分别表示红色球和蓝色球的数量。你需要使用这些球来组成一个三角形,满足第 1 行有 1 个球,第 2 行有 2 个球,第 3 行有 3 个球,依此类推。</p>
<p>每一行的球必须是 <strong>相同 </strong>颜色,且相邻行的颜色必须<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">red = 2, blue = 4</span></p>
<p><strong>输出:</strong> 3</p>
<p><strong>解释:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/16/brb.png" style="width: 300px; height: 240px; padding: 10px;" /></p>
<p>上图显示了唯一可能的排列方式。</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">red = 2, blue = 1</span></p>
<p><strong>输出:</strong> <span class="example-io">2</span></p>
<p><strong>解释:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/16/br.png" style="width: 150px; height: 135px; padding: 10px;" /><br />
上图显示了唯一可能的排列方式。</p>
</div>
<p><strong class="example">示例 3</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">red = 1, blue = 1</span></p>
<p><strong>输出:</strong> <span class="example-io">1</span></p>
</div>
<p><strong class="example">示例 4</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">red = 10, blue = 1</span></p>
<p><strong>输出:</strong> <span class="example-io">2</span></p>
<p><strong>解释:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/16/br.png" style="width: 150px; height: 135px; padding: 10px;" /><br />
上图显示了唯一可能的排列方式。</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= red, blue &lt;= 100</code></li>
</ul>

@ -0,0 +1,65 @@
<p>给你一个下标从 <strong>0</strong>&nbsp;开始的整数数组&nbsp;<code>enemyEnergies</code>&nbsp;,它表示一个下标从 <strong>0</strong>&nbsp;开始的敌人能量数组。</p>
<p>同时给你一个整数&nbsp;<code>currentEnergy</code>&nbsp;,它表示你一开始拥有的能量值总量。</p>
<p>你一开始的分数为&nbsp;<code>0</code>&nbsp;,且一开始所有的敌人都未标记。</p>
<p>你可以通过以下操作 <b>之一</b>&nbsp;<strong>任意次</strong>(也可以&nbsp;<strong>0</strong>&nbsp;次)来得分:</p>
<ul>
<li>选择一个 <strong>未标记</strong>&nbsp;且满足&nbsp;<code>currentEnergy &gt;= enemyEnergies[i]</code>&nbsp;的敌人&nbsp;<code>i</code>&nbsp;。在这个操作中:
<ul>
<li>你会获得 <code>1</code>&nbsp;分。</li>
<li>你的能量值减少&nbsp;<code>enemyEnergies[i]</code>&nbsp;,也就是说&nbsp;<code>currentEnergy = currentEnergy - enemyEnergies[i]</code>&nbsp;</li>
</ul>
</li>
<li>如果你目前&nbsp;<strong>至少</strong>&nbsp;<code>1</code>&nbsp;分,你可以选择一个&nbsp;<strong>未标记</strong>&nbsp;的敌人&nbsp;<code>i</code>&nbsp;。在这个操作中:
<ul>
<li>你的能量值增加 <code>enemyEnergies[i]</code>&nbsp;,也就是说&nbsp;<code>currentEnergy = currentEnergy + enemyEnergies[i]</code>&nbsp;</li>
<li>敌人&nbsp;<code>i</code> <strong>被标记</strong>&nbsp;</li>
</ul>
</li>
</ul>
<p>请你返回通过以上操作,<strong>最多</strong>&nbsp;可以获得多少分。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><b>输入:</b>enemyEnergies = [3,2,2], currentEnergy = 2</p>
<p><b>输出:</b>3</p>
<p><strong>解释:</strong></p>
<p>通过以下操作可以得到最大得分 3 分:</p>
<ul>
<li>对敌人 1 使用第一种操作:<code>points</code>&nbsp;增加 1 <code>currentEnergy</code>&nbsp;减少 2 。所以&nbsp;<code>points = 1</code>&nbsp;&nbsp;<code>currentEnergy = 0</code>&nbsp;</li>
<li>对敌人 0 使用第二种操作:<code>currentEnergy</code>&nbsp;增加 3 ,敌人 0 被标记。所以&nbsp;<code>points = 1</code>&nbsp;<code>currentEnergy = 3</code>&nbsp;,被标记的敌人包括&nbsp;<code>[0]</code>&nbsp;</li>
<li>对敌人 2 使用第一种操作:<code>points</code>&nbsp;增加 1 <code>currentEnergy</code>&nbsp;减少 2 。所以&nbsp;<code>points = 2</code>&nbsp;&nbsp;<code>currentEnergy = 1</code>&nbsp;,被标记的敌人包括<code>[0]</code>&nbsp;</li>
<li>对敌人 2 使用第二种操作:<code>currentEnergy</code>&nbsp;增加 2 ,敌人 2 被标记。所以&nbsp;<code>points = 2</code>&nbsp;<code>currentEnergy = 3</code>&nbsp;且被标记的敌人包括&nbsp;<code>[0, 2]</code>&nbsp;</li>
<li>对敌人 1 使用第一种操作:<code>points</code>&nbsp;增加 1 <code>currentEnergy</code>&nbsp;减少 2 。所以&nbsp;<code>points = 3</code>&nbsp;<code>currentEnergy = 1</code>&nbsp;,被标记的敌人包括&nbsp;<code>[0, 2]</code>&nbsp;</li>
</ul>
<p><strong>示例 2</strong></p>
<p><b>输入:</b>enemyEnergies =&nbsp;[2], currentEnergy = 10</p>
<p><b>输出:</b>5</p>
<p><strong>解释:</strong></p>
<p>通过对敌人 0 进行第一种操作 5 次,得到最大得分。</p>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= enemyEnergies.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= enemyEnergies[i] &lt;= 10<sup>9</sup></code></li>
<li><code>0 &lt;= currentEnergy &lt;= 10<sup>9</sup></code></li>
</ul>

@ -0,0 +1,38 @@
<p>给你一个仅由数字组成的字符串 <code>s</code>,在最多交换一次 <strong>相邻 </strong>且具有相同 <strong>奇偶性 </strong>的数字后,返回可以得到的<span data-keyword="lexicographically-smaller-string">字典序最小的字符串</span></p>
<p>如果两个数字都是奇数或都是偶数则它们具有相同的奇偶性。例如5 和 9、2 和 4 奇偶性相同,而 6 和 9 奇偶性不同。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">s = "45320"</span></p>
<p><strong>输出:</strong> <span class="example-io">"43520"</span></p>
<p><strong>解释:</strong></p>
<p><code>s[1] == '5'</code><code>s[2] == '3'</code> 都具有相同的奇偶性,交换它们可以得到字典序最小的字符串。</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">s = "001"</span></p>
<p><strong>输出:</strong> <span class="example-io">"001"</span></p>
<p><strong>解释:</strong></p>
<p>无需进行交换,因为 <code>s</code> 已经是字典序最小的。</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>2 &lt;= s.length &lt;= 100</code></li>
<li><code>s</code> 仅由数字组成。</li>
</ul>

@ -0,0 +1,51 @@
<p>给你一个整数数组 <code>colors</code>&nbsp;,它表示一个由红色和蓝色瓷砖组成的环,第 <code>i</code>&nbsp;块瓷砖的颜色为&nbsp;<code>colors[i]</code>&nbsp;</p>
<ul>
<li><code>colors[i] == 0</code>&nbsp;表示第&nbsp;<code>i</code>&nbsp;块瓷砖的颜色是 <strong>红色</strong>&nbsp;</li>
<li><code>colors[i] == 1</code>&nbsp;表示第 <code>i</code>&nbsp;块瓷砖的颜色是 <strong>蓝色</strong>&nbsp;</li>
</ul>
<p>环中连续 3 块瓷砖的颜色如果是 <strong>交替</strong>&nbsp;颜色(也就是说中间瓷砖的颜色与它<strong>&nbsp;左边</strong>&nbsp;<strong>右边</strong>&nbsp;的颜色都不同),那么它被称为一个 <strong>交替</strong>&nbsp;组。</p>
<p>请你返回 <strong>交替</strong>&nbsp;组的数目。</p>
<p><b>注意</b>&nbsp;,由于&nbsp;<code>colors</code>&nbsp;表示一个 <strong></strong>&nbsp;<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>colors = [1,1,1]</span></p>
<p><span class="example-io"><b>输出:</b>0</span></p>
<p><strong>解释:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/05/16/image_2024-05-16_23-53-171.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" /></p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>colors = [0,1,0,0,1]</span></p>
<p><b>输出:</b>3</p>
<p><b>解释:</b></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/05/16/image_2024-05-16_23-47-491.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" /></p>
<p>交替组包括:</p>
<p><strong class="example"><img alt="" src="https://assets.leetcode.com/uploads/2024/05/16/image_2024-05-16_23-50-441.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" /></strong><img alt="" src="https://assets.leetcode.com/uploads/2024/05/16/image_2024-05-16_23-48-211.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" /><strong class="example"><img alt="" src="https://assets.leetcode.com/uploads/2024/05/16/image_2024-05-16_23-49-351.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" /></strong></p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>3 &lt;= colors.length &lt;= 100</code></li>
<li><code>0 &lt;= colors[i] &lt;= 1</code></li>
</ul>

@ -0,0 +1,66 @@
<p>给你一个整数数组 <code>colors</code>&nbsp;和一个整数&nbsp;<code>k</code>&nbsp;<code>colors</code>表示一个由红色和蓝色瓷砖组成的环,第 <code>i</code>&nbsp;块瓷砖的颜色为&nbsp;<code>colors[i]</code>&nbsp;</p>
<ul>
<li><code>colors[i] == 0</code>&nbsp;表示第&nbsp;<code>i</code>&nbsp;块瓷砖的颜色是 <strong>红色</strong>&nbsp;</li>
<li><code>colors[i] == 1</code>&nbsp;表示第 <code>i</code>&nbsp;块瓷砖的颜色是 <strong>蓝色</strong>&nbsp;</li>
</ul>
<p>环中连续 <code>k</code>&nbsp;块瓷砖的颜色如果是 <strong>交替</strong>&nbsp;颜色(也就是说除了第一块和最后一块瓷砖以外,中间瓷砖的颜色与它<strong>&nbsp;左边</strong>&nbsp;<strong>右边</strong>&nbsp;的颜色都不同),那么它被称为一个 <strong>交替</strong>&nbsp;组。</p>
<p>请你返回 <strong>交替</strong>&nbsp;组的数目。</p>
<p><b>注意</b>&nbsp;,由于&nbsp;<code>colors</code>&nbsp;表示一个 <strong></strong>&nbsp;<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>colors = [0,1,0,1,0], k = 3</span></p>
<p><span class="example-io"><b>输出:</b>3</span></p>
<p><strong>解释:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/19/screenshot-2024-05-28-183519.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" /></p>
<p>交替组包括:</p>
<p><strong class="example"><img alt="" src="https://assets.leetcode.com/uploads/2024/05/28/screenshot-2024-05-28-182448.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" /></strong><img alt="" src="https://assets.leetcode.com/uploads/2024/05/28/screenshot-2024-05-28-182844.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" /><strong class="example"><img alt="" src="https://assets.leetcode.com/uploads/2024/05/28/screenshot-2024-05-28-183057.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" /></strong></p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>colors = [0,1,0,0,1,0,1], k = 6</span></p>
<p><b>输出:</b>2</p>
<p><b>解释:</b></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/19/screenshot-2024-05-28-183907.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" /></p>
<p>交替组包括:</p>
<p><strong class="example"><img alt="" src="https://assets.leetcode.com/uploads/2024/06/19/screenshot-2024-05-28-184128.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" /></strong><img alt="" src="https://assets.leetcode.com/uploads/2024/06/19/screenshot-2024-05-28-184240.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" /></p>
<p><strong>示例 3</strong></p>
<p><strong>输入:</strong>colors = [1,1,0,1], k = 4</p>
<p><strong>输出:</strong>0</p>
<p><strong>解释:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/19/screenshot-2024-05-28-184516.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" /></p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>3 &lt;= colors.length &lt;= 10<sup>5</sup></code></li>
<li><code>0 &lt;= colors[i] &lt;= 1</code></li>
<li><code>3 &lt;= k &lt;= colors.length</code></li>
</ul>

@ -0,0 +1,58 @@
<p>给你一个整数数组 <code>nums</code> 和一个链表的头节点 <code>head</code>。从链表中<strong>移除</strong>所有存在于 <code>nums</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,2,3], head = [1,2,3,4,5]</span></p>
<p><strong>输出:</strong> <span class="example-io">[4,5]</span></p>
<p><strong>解释:</strong></p>
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/06/11/linkedlistexample0.png" style="width: 400px; height: 66px;" /></strong></p>
<p>移除数值为 1, 2 和 3 的节点。</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">nums = [1], head = [1,2,1,2,1,2]</span></p>
<p><strong>输出:</strong> <span class="example-io">[2,2,2]</span></p>
<p><strong>解释:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/11/linkedlistexample1.png" style="height: 62px; width: 450px;" /></p>
<p>移除数值为 1 的节点。</p>
</div>
<p><strong class="example">示例 3</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">nums = [5], head = [1,2,3,4]</span></p>
<p><strong>输出:</strong> <span class="example-io">[1,2,3,4]</span></p>
<p><strong>解释:</strong></p>
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/06/11/linkedlistexample2.png" style="width: 400px; height: 83px;" /></strong></p>
<p>链表中不存在值为 5 的节点。</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>5</sup></code></li>
<li><code>nums</code> 中的所有元素都是唯一的。</li>
<li>链表中的节点数在 <code>[1, 10<sup>5</sup>]</code> 的范围内。</li>
<li><code>1 &lt;= Node.val &lt;= 10<sup>5</sup></code></li>
<li>输入保证链表中至少有一个值没有在&nbsp;<code>nums</code> 中出现过。</li>
</ul>

@ -0,0 +1,74 @@
<p>有一个&nbsp;<code>m x n</code>&nbsp;大小的矩形蛋糕,需要切成&nbsp;<code>1 x 1</code>&nbsp;的小块。</p>
<p>给你整数&nbsp;<code>m</code>&nbsp;<code>n</code>&nbsp;和两个数组:</p>
<ul>
<li><code>horizontalCut</code> 的大小为&nbsp;<code>m - 1</code>&nbsp;,其中&nbsp;<code>horizontalCut[i]</code>&nbsp;表示沿着水平线 <code>i</code>&nbsp;切蛋糕的开销。</li>
<li><code>verticalCut</code> 的大小为&nbsp;<code>n - 1</code>&nbsp;,其中&nbsp;<code>verticalCut[j]</code>&nbsp;表示沿着垂直线&nbsp;<code>j</code>&nbsp;切蛋糕的开销。</li>
</ul>
<p>一次操作中,你可以选择任意不是&nbsp;<code>1 x 1</code>&nbsp;大小的矩形蛋糕并执行以下操作之一:</p>
<ol>
<li>沿着水平线&nbsp;<code>i</code>&nbsp;切开蛋糕,开销为&nbsp;<code>horizontalCut[i]</code>&nbsp;</li>
<li>沿着垂直线&nbsp;<code>j</code>&nbsp;切开蛋糕,开销为&nbsp;<code>verticalCut[j]</code>&nbsp;</li>
</ol>
<p>每次操作后,这块蛋糕都被切成两个独立的小蛋糕。</p>
<p>每次操作的开销都为最开始对应切割线的开销,并且不会改变。</p>
<p>请你返回将蛋糕全部切成&nbsp;<code>1 x 1</code>&nbsp;的蛋糕块的&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>m = 3, n = 2, horizontalCut = [1,3], verticalCut = [5]</span></p>
<p><span class="example-io"><b>输出:</b>13</span></p>
<p><strong>解释:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/04/ezgifcom-animated-gif-maker-1.gif" style="width: 280px; height: 320px;" /></p>
<ul>
<li>沿着垂直线 0 切开蛋糕,开销为 5 。</li>
<li>沿着水平线 0 切开&nbsp;<code>3 x 1</code>&nbsp;的蛋糕块,开销为 1 。</li>
<li>沿着水平线 0 切开 <code>3 x 1</code>&nbsp;的蛋糕块,开销为 1 。</li>
<li>沿着水平线 1 切开 <code>2 x 1</code>&nbsp;的蛋糕块,开销为 3 。</li>
<li>沿着水平线 1 切开 <code>2 x 1</code>&nbsp;的蛋糕块,开销为 3 。</li>
</ul>
<p>总开销为&nbsp;<code>5 + 1 + 1 + 3 + 3 = 13</code>&nbsp;</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>m = 2, n = 2, horizontalCut = [7], verticalCut = [4]</span></p>
<p><span class="example-io"><b>输出:</b>15</span></p>
<p><strong>解释:</strong></p>
<ul>
<li>沿着水平线 0 切开蛋糕,开销为 7 。</li>
<li>沿着垂直线 0 切开&nbsp;<code>1 x 2</code>&nbsp;的蛋糕块,开销为 4 。</li>
<li>沿着垂直线 0 切开&nbsp;<code>1 x 2</code>&nbsp;的蛋糕块,开销为 4 。</li>
</ul>
<p>总开销为&nbsp;<code>7 + 4 + 4 = 15</code>&nbsp;</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= m, n &lt;= 20</code></li>
<li><code>horizontalCut.length == m - 1</code></li>
<li><code>verticalCut.length == n - 1</code></li>
<li><code>1 &lt;= horizontalCut[i], verticalCut[i] &lt;= 10<sup>3</sup></code></li>
</ul>

@ -0,0 +1,74 @@
<p>有一个&nbsp;<code>m x n</code>&nbsp;大小的矩形蛋糕,需要切成&nbsp;<code>1 x 1</code>&nbsp;的小块。</p>
<p>给你整数&nbsp;<code>m</code>&nbsp;<code>n</code>&nbsp;和两个数组:</p>
<ul>
<li><code>horizontalCut</code> 的大小为&nbsp;<code>m - 1</code>&nbsp;,其中&nbsp;<code>horizontalCut[i]</code>&nbsp;表示沿着水平线 <code>i</code>&nbsp;切蛋糕的开销。</li>
<li><code>verticalCut</code> 的大小为&nbsp;<code>n - 1</code>&nbsp;,其中&nbsp;<code>verticalCut[j]</code>&nbsp;表示沿着垂直线&nbsp;<code>j</code>&nbsp;切蛋糕的开销。</li>
</ul>
<p>一次操作中,你可以选择任意不是&nbsp;<code>1 x 1</code>&nbsp;大小的矩形蛋糕并执行以下操作之一:</p>
<ol>
<li>沿着水平线&nbsp;<code>i</code>&nbsp;切开蛋糕,开销为&nbsp;<code>horizontalCut[i]</code>&nbsp;</li>
<li>沿着垂直线&nbsp;<code>j</code>&nbsp;切开蛋糕,开销为&nbsp;<code>verticalCut[j]</code>&nbsp;</li>
</ol>
<p>每次操作后,这块蛋糕都被切成两个独立的小蛋糕。</p>
<p>每次操作的开销都为最开始对应切割线的开销,并且不会改变。</p>
<p>请你返回将蛋糕全部切成&nbsp;<code>1 x 1</code>&nbsp;的蛋糕块的&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>m = 3, n = 2, horizontalCut = [1,3], verticalCut = [5]</span></p>
<p><span class="example-io"><b>输出:</b>13</span></p>
<p><strong>解释:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/04/ezgifcom-animated-gif-maker-1.gif" style="width: 280px; height: 320px;" /></p>
<ul>
<li>沿着垂直线 0 切开蛋糕,开销为 5 。</li>
<li>沿着水平线 0 切开&nbsp;<code>3 x 1</code>&nbsp;的蛋糕块,开销为 1 。</li>
<li>沿着水平线 0 切开 <code>3 x 1</code>&nbsp;的蛋糕块,开销为 1 。</li>
<li>沿着水平线 1 切开 <code>2 x 1</code>&nbsp;的蛋糕块,开销为 3 。</li>
<li>沿着水平线 1 切开 <code>2 x 1</code>&nbsp;的蛋糕块,开销为 3 。</li>
</ul>
<p>总开销为&nbsp;<code>5 + 1 + 1 + 3 + 3 = 13</code>&nbsp;</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>m = 2, n = 2, horizontalCut = [7], verticalCut = [4]</span></p>
<p><span class="example-io"><b>输出:</b>15</span></p>
<p><strong>解释:</strong></p>
<ul>
<li>沿着水平线 0 切开蛋糕,开销为 7 。</li>
<li>沿着垂直线 0 切开&nbsp;<code>1 x 2</code>&nbsp;的蛋糕块,开销为 4 。</li>
<li>沿着垂直线 0 切开&nbsp;<code>1 x 2</code>&nbsp;的蛋糕块,开销为 4 。</li>
</ul>
<p>总开销为&nbsp;<code>7 + 4 + 4 = 15</code>&nbsp;</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= m, n &lt;= 10<sup>5</sup></code></li>
<li><code>horizontalCut.length == m - 1</code></li>
<li><code>verticalCut.length == n - 1</code></li>
<li><code>1 &lt;= horizontalCut[i], verticalCut[i] &lt;= 10<sup>3</sup></code></li>
</ul>

@ -0,0 +1,49 @@
<p>给你两棵 <strong>无向</strong>&nbsp;树,分别有&nbsp;<code>n</code>&nbsp;<code>m</code>&nbsp;个节点,节点编号分别为&nbsp;<code>0</code>&nbsp;&nbsp;<code>n - 1</code>&nbsp;&nbsp;<code>0</code>&nbsp;&nbsp;<code>m - 1</code>&nbsp;。给你两个二维整数数组&nbsp;<code>edges1</code>&nbsp;<code>edges2</code>&nbsp;,长度分别为&nbsp;<code>n - 1</code>&nbsp;<code>m - 1</code>&nbsp;,其中&nbsp;<code>edges1[i] = [a<sub>i</sub>, b<sub>i</sub>]</code>&nbsp;表示在第一棵树中节点&nbsp;<code>a<sub>i</sub></code>&nbsp;<code>b<sub>i</sub></code>&nbsp;之间有一条边,<code>edges2[i] = [u<sub>i</sub>, v<sub>i</sub>]</code>&nbsp;表示在第二棵树中节点&nbsp;<code>u<sub>i</sub></code>&nbsp;<code>v<sub>i</sub></code>&nbsp;之间有一条边。</p>
<p>你必须在第一棵树和第二棵树中分别选一个节点,并用一条边连接它们。</p>
<p>请你返回添加边后得到的树中,<strong>最小直径</strong>&nbsp;为多少。</p>
<p>一棵树的 <strong>直径</strong>&nbsp;指的是树中任意两个节点之间的最长路径长度。</p>
<p>&nbsp;</p>
<p><b>示例 1</b><img alt="" src="https://assets.leetcode.com/uploads/2024/04/22/example11-transformed.png" style="width: 1000px; height: 494px;" /></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>edges1 = [[0,1],[0,2],[0,3]], edges2 = [[0,1]]</span></p>
<p><span class="example-io"><b>输出:</b>3</span></p>
<p><strong>解释:</strong></p>
<p>将第一棵树中的节点 0 与第二棵树中的任意节点连接,得到一棵直径为 3 的树。</p>
</div>
<p><strong class="example">示例 2<img alt="" src="https://assets.leetcode.com/uploads/2024/04/22/example211.png" style="width: 1000px; height: 492px;" /></strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>edges1 = [[0,1],[0,2],[0,3],[2,4],[2,5],[3,6],[2,7]], edges2 = [[0,1],[0,2],[0,3],[2,4],[2,5],[3,6],[2,7]]</span></p>
<p><span class="example-io"><b>输出:</b>5</span></p>
<p><strong>解释:</strong></p>
<p>将第一棵树中的节点 0 和第二棵树中的节点 0 连接,可以得到一棵直径为 5 的树。</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>edges1.length == n - 1</code></li>
<li><code>edges2.length == m - 1</code></li>
<li><code>edges1[i].length == edges2[i].length == 2</code></li>
<li><code>edges1[i] = [a<sub>i</sub>, b<sub>i</sub>]</code></li>
<li><code>0 &lt;= a<sub>i</sub>, b<sub>i</sub> &lt; n</code></li>
<li><code>edges2[i] = [u<sub>i</sub>, v<sub>i</sub>]</code></li>
<li><code>0 &lt;= u<sub>i</sub>, v<sub>i</sub> &lt; m</code></li>
<li>输入保证&nbsp;<code>edges1</code>&nbsp;<code>edges2</code>&nbsp;分别表示一棵合法的树。</li>
</ul>

@ -0,0 +1,48 @@
<p>给你一个整数数组&nbsp;<code>nums</code>&nbsp;和一个整数&nbsp;<code>k</code>&nbsp;,请你返回&nbsp;<code>nums</code>&nbsp;中有多少个<span data-keyword="subarray-nonempty">子数组</span>满足:子数组中所有元素按位&nbsp;<code>AND</code>&nbsp;的结果为 <code>k</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,1,1], k = 1</span></p>
<p><span class="example-io"><b>输出:</b>6</span></p>
<p><strong>解释:</strong></p>
<p>所有子数组都只含有元素 1 。</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>nums = [1,1,2], k = 1</span></p>
<p><span class="example-io"><b>输出:</b>3</span></p>
<p><b>解释:</b></p>
<p>按位&nbsp;<code>AND</code>&nbsp;值为 1 的子数组包括:<code>[<u><strong>1</strong></u>,1,2]</code>, <code>[1,<u><strong>1</strong></u>,2]</code>, <code>[<u><strong>1,1</strong></u>,2]</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,3], k = 2</span></p>
<p><span class="example-io"><b>输出:</b>2</span></p>
<p><strong>解释:</strong></p>
<p>按位&nbsp;<code>AND</code>&nbsp;值为 2 的子数组包括:<code>[1,<b><u>2</u></b>,3]</code>, <code>[1,<u><strong>2,3</strong></u>]</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>0 &lt;= nums[i], k &lt;= 10<sup>9</sup></code></li>
</ul>

@ -0,0 +1,48 @@
<p>给你一个字符串 <code>s</code> 和一个整数 <code>k</code>。请你使用以下算法加密字符串:</p>
<ul>
<li>对于字符串 <code>s</code> 中的每个字符 <code>c</code>,用字符串中 <code>c</code> 后面的第 <code>k</code> 个字符替换 <code>c</code>(以循环方式)。</li>
</ul>
<p>返回加密后的字符串。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">s = "dart", k = 3</span></p>
<p><strong>输出:</strong> <span class="example-io">"tdar"</span></p>
<p><strong>解释:</strong></p>
<ul>
<li>对于 <code>i = 0</code><code>'d'</code> 后面的第 3 个字符是 <code>'t'</code></li>
<li>对于 <code>i = 1</code><code>'a'</code> 后面的第 3 个字符是 <code>'d'</code></li>
<li>对于 <code>i = 2</code><code>'r'</code> 后面的第 3 个字符是 <code>'a'</code></li>
<li>对于 <code>i = 3</code><code>'t'</code> 后面的第 3 个字符是 <code>'r'</code></li>
</ul>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">s = "aaa", k = 1</span></p>
<p><strong>输出:</strong> <span class="example-io">"aaa"</span></p>
<p><strong>解释:</strong></p>
<p>由于所有字符都相同,加密后的字符串也将相同。</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 100</code></li>
<li><code>1 &lt;= k &lt;= 10<sup>4</sup></code></li>
<li><code>s</code> 仅由小写英文字母组成。</li>
</ul>

@ -0,0 +1,58 @@
<p>给你一个整数数组 <code>nums</code></p>
<p><code>nums</code> 的子序列 <code>sub</code> 的长度为 <code>x</code> ,如果其满足以下条件,则称其为 <strong>有效子序列</strong></p>
<ul>
<li><code>(sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == ... == (sub[x - 2] + sub[x - 1]) % 2</code></li>
</ul>
<p>返回 <code>nums</code><strong>最长的有效子序列</strong> 的长度。</p>
<p>一个&nbsp;<strong>子序列</strong>&nbsp;指的是从原数组中删除一些元素(也可以不删除任何元素),剩余元素保持原来顺序组成的新数组。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">nums = [1,2,3,4]</span></p>
<p><strong>输出:</strong> <span class="example-io">4</span></p>
<p><strong>解释:</strong></p>
<p>最长的有效子序列是 <code>[1, 2, 3, 4]</code></p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">nums = [1,2,1,1,2,1,2]</span></p>
<p><strong>输出:</strong> 6</p>
<p><strong>解释:</strong></p>
<p>最长的有效子序列是 <code>[1, 2, 1, 2, 1, 2]</code></p>
</div>
<p><strong class="example">示例 3</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">nums = [1,3]</span></p>
<p><strong>输出:</strong> <span class="example-io">2</span></p>
<p><strong>解释:</strong></p>
<p>最长的有效子序列是 <code>[1, 3]</code></p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>2 &lt;= nums.length &lt;= 2 * 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>7</sup></code></li>
</ul>

@ -0,0 +1,43 @@
给你一个整数数组&nbsp;<code>nums</code>&nbsp;和一个 <strong></strong>&nbsp;整数&nbsp;<code>k</code>&nbsp;
<p><code>nums</code>&nbsp;的一个&nbsp;<span data-keyword="subsequence-array">子序列</span> <code>sub</code>&nbsp;的长度为 <code>x</code>&nbsp;,如果其满足以下条件,则称其为 <strong>有效子序列</strong>&nbsp;</p>
<ul>
<li><code>(sub[0] + sub[1]) % k == (sub[1] + sub[2]) % k == ... == (sub[x - 2] + sub[x - 1]) % k</code></li>
</ul>
返回 <code>nums</code>&nbsp;<strong>最长</strong><strong>有效子序列</strong>&nbsp;的长度。
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>nums = [1,2,3,4,5], k = 2</span></p>
<p><span class="example-io"><b>输出:</b>5</span></p>
<p><b>解释:</b></p>
<p>最长有效子序列是&nbsp;<code>[1, 2, 3, 4, 5]</code>&nbsp;</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>nums = [1,4,2,3,1,4], k = 3</span></p>
<p><span class="example-io"><b>输出:</b>4</span></p>
<p><strong>解释:</strong></p>
<p>最长有效子序列是&nbsp;<code>[1, 4, 1, 4]</code>&nbsp;</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>2 &lt;= nums.length &lt;= 10<sup>3</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>7</sup></code></li>
<li><code>1 &lt;= k &lt;= 10<sup>3</sup></code></li>
</ul>

@ -0,0 +1,56 @@
<p>给你一个字符串 <code>target</code>、一个字符串数组 <code>words</code> 以及一个整数数组 <code>costs</code>,这两个数组长度相同。</p>
<p>设想一个空字符串 <code>s</code></p>
<p>你可以执行以下操作任意次数(包括<strong></strong>次):</p>
<ul>
<li>选择一个在范围&nbsp; <code>[0, words.length - 1]</code> 的索引 <code>i</code></li>
<li><code>words[i]</code> 追加到 <code>s</code></li>
<li>该操作的成本是 <code>costs[i]</code></li>
</ul>
<p>返回使 <code>s</code> 等于 <code>target</code><strong>最小</strong> 成本。如果不可能,返回 <code>-1</code></p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">target = "abcdef", words = ["abdef","abc","d","def","ef"], costs = [100,1,1,10,5]</span></p>
<p><strong>输出:</strong> <span class="example-io">7</span></p>
<p><strong>解释:</strong></p>
<ul>
<li>选择索引 1 并以成本 1 将 <code>"abc"</code> 追加到 <code>s</code>,得到 <code>s = "abc"</code></li>
<li>选择索引 2 并以成本 1 将 <code>"d"</code> 追加到 <code>s</code>,得到 <code>s = "abcd"</code></li>
<li>选择索引 4 并以成本 5 将 <code>"ef"</code> 追加到 <code>s</code>,得到 <code>s = "abcdef"</code></li>
</ul>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">target = "aaaa", words = ["z","zz","zzz"], costs = [1,10,100]</span></p>
<p><strong>输出:</strong> <span class="example-io">-1</span></p>
<p><strong>解释:</strong></p>
<p>无法使 <code>s</code> 等于 <code>target</code>,因此返回 -1。</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= target.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>1 &lt;= words.length == costs.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>1 &lt;= words[i].length &lt;= target.length</code></li>
<li>所有 <code>words[i].length</code> 的总和小于或等于 <code>5 * 10<sup>4</sup></code></li>
<li><code>target</code><code>words[i]</code> 仅由小写英文字母组成。</li>
<li><code>1 &lt;= costs[i] &lt;= 10<sup>4</sup></code></li>
</ul>

@ -0,0 +1,39 @@
<p>给你一个正整数 <code>n</code></p>
<p>如果一个二进制字符串 <code>x</code> 的所有长度为 2 的<span data-keyword="substring-nonempty">子字符串</span>中包含 <strong>至少</strong> 一个 <code>"1"</code>,则称 <code>x</code> 是一个<strong> 有效</strong> 字符串。</p>
<p>返回所有长度为 <code>n</code><strong> 有效</strong> 字符串,可以以任意顺序排列。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">n = 3</span></p>
<p><strong>输出:</strong> <span class="example-io">["010","011","101","110","111"]</span></p>
<p><strong>解释:</strong></p>
<p>长度为 3 的有效字符串有:<code>"010"</code><code>"011"</code><code>"101"</code><code>"110"</code><code>"111"</code></p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">n = 1</span></p>
<p><strong>输出:</strong> <span class="example-io">["0","1"]</span></p>
<p><strong>解释:</strong></p>
<p>长度为 1 的有效字符串有:<code>"0"</code><code>"1"</code></p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= n &lt;= 18</code></li>
</ul>

@ -0,0 +1,54 @@
<p>给你一个二维字符矩阵 <code>grid</code>,其中 <code>grid[i][j]</code> 可能是 <code>'X'</code><code>'Y'</code><code>'.'</code>,返回满足以下条件的<span data-keyword="submatrix">子矩阵</span>数量:</p>
<ul>
<li>包含 <code>grid[0][0]</code></li>
<li><code>'X'</code><code>'Y'</code> 的频数相等。</li>
<li>至少包含一个 <code>'X'</code></li>
</ul>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">grid = [["X","Y","."],["Y",".","."]]</span></p>
<p><strong>输出:</strong> <span class="example-io">3</span></p>
<p><strong>解释:</strong></p>
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/06/07/examplems.png" style="padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; width: 175px; height: 350px;" /></strong></p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">grid = [["X","X"],["X","Y"]]</span></p>
<p><strong>输出:</strong> <span class="example-io">0</span></p>
<p><strong>解释:</strong></p>
<p>不存在满足 <code>'X'</code><code>'Y'</code> 频数相等的子矩阵。</p>
</div>
<p><strong class="example">示例 3</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">grid = [[".","."],[".","."]]</span></p>
<p><strong>输出:</strong> <span class="example-io">0</span></p>
<p><strong>解释:</strong></p>
<p>不存在满足至少包含一个 <code>'X'</code> 的子矩阵。</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= grid.length, grid[i].length &lt;= 1000</code></li>
<li><code>grid[i][j]</code> 可能是 <code>'X'</code><code>'Y'</code><code>'.'</code>.</li>
</ul>

@ -0,0 +1,61 @@
<p>You are given two integers <code>red</code> and <code>blue</code> representing the count of red and blue colored balls. You have to arrange these balls to form a triangle such that the 1<sup>st</sup> row will have 1 ball, the 2<sup>nd</sup> row will have 2 balls, the 3<sup>rd</sup> row will have 3 balls, and so on.</p>
<p>All the balls in a particular row should be the <strong>same</strong> color, and adjacent rows should have <strong>different</strong> colors.</p>
<p>Return the <strong>maximum</strong><em> height of the triangle</em> that can be achieved.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">red = 2, blue = 4</span></p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/16/brb.png" style="width: 300px; height: 240px; padding: 10px;" /></p>
<p>The only possible arrangement is shown above.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">red = 2, blue = 1</span></p>
<p><strong>Output:</strong> <span class="example-io">2</span></p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/16/br.png" style="width: 150px; height: 135px; padding: 10px;" /><br />
The only possible arrangement is shown above.</p>
</div>
<p><strong class="example">Example 3:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">red = 1, blue = 1</span></p>
<p><strong>Output:</strong> <span class="example-io">1</span></p>
</div>
<p><strong class="example">Example 4:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">red = 10, blue = 1</span></p>
<p><strong>Output:</strong> <span class="example-io">2</span></p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/16/br.png" style="width: 150px; height: 135px; padding: 10px;" /><br />
The only possible arrangement is shown above.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= red, blue &lt;= 100</code></li>
</ul>

@ -0,0 +1,67 @@
<p>You are given an integer array <code>enemyEnergies</code> denoting the energy values of various enemies.</p>
<p>You are also given an integer <code>currentEnergy</code> denoting the amount of energy you have initially.</p>
<p>You start with 0 points, and all the enemies are unmarked initially.</p>
<p>You can perform <strong>either</strong> of the following operations <strong>zero </strong>or multiple times to gain points:</p>
<ul>
<li>Choose an <strong>unmarked</strong> enemy, <code>i</code>, such that <code>currentEnergy &gt;= enemyEnergies[i]</code>. By choosing this option:
<ul>
<li>You gain 1 point.</li>
<li>Your energy is reduced by the enemy&#39;s energy, i.e. <code>currentEnergy = currentEnergy - enemyEnergies[i]</code>.</li>
</ul>
</li>
<li>If you have <strong>at least</strong> 1 point, you can choose an <strong>unmarked</strong> enemy, <code>i</code>. By choosing this option:
<ul>
<li>Your energy increases by the enemy&#39;s energy, i.e. <code>currentEnergy = currentEnergy + enemyEnergies[i]</code>.</li>
<li>The <font face="monospace">e</font>nemy <code>i</code> is <strong>marked</strong>.</li>
</ul>
</li>
</ul>
<p>Return an integer denoting the <strong>maximum</strong> points you can get in the end by optimally performing operations.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">enemyEnergies = [3,2,2], currentEnergy = 2</span></p>
<p><strong>Output:</strong> <span class="example-io">3</span></p>
<p><strong>Explanation:</strong></p>
<p>The following operations can be performed to get 3 points, which is the maximum:</p>
<ul>
<li>First operation on enemy 1: <code>points</code> increases by 1, and <code>currentEnergy</code> decreases by 2. So, <code>points = 1</code>, and <code>currentEnergy = 0</code>.</li>
<li>Second operation on enemy 0: <code>currentEnergy</code> increases by 3, and enemy 0 is marked. So, <code>points = 1</code>, <code>currentEnergy = 3</code>, and marked enemies = <code>[0]</code>.</li>
<li>First operation on enemy 2: <code>points</code> increases by 1, and <code>currentEnergy</code> decreases by 2. So, <code>points = 2</code>, <code>currentEnergy = 1</code>, and marked enemies = <code>[0]</code>.</li>
<li>Second operation on enemy 2: <code>currentEnergy</code> increases by 2, and enemy 2 is marked. So, <code>points = 2</code>, <code>currentEnergy = 3</code>, and marked enemies = <code>[0, 2]</code>.</li>
<li>First operation on enemy 1: <code>points</code> increases by 1, and <code>currentEnergy</code> decreases by 2. So, <code>points = 3</code>, <code>currentEnergy = 1</code>, and marked enemies = <code>[0, 2]</code>.</li>
</ul>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">enemyEnergies = </span>[2]<span class="example-io">, currentEnergy = 10</span></p>
<p><strong>Output:</strong> <span class="example-io">5</span></p>
<p><strong>Explanation: </strong></p>
<p>Performing the first operation 5 times on enemy 0 results in the maximum number of points.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= enemyEnergies.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= enemyEnergies[i] &lt;= 10<sup>9</sup></code></li>
<li><code>0 &lt;= currentEnergy &lt;= 10<sup>9</sup></code></li>
</ul>

@ -0,0 +1,36 @@
<p>Given a string <code>s</code> containing only digits, return the <span data-keyword="lexicographically-smaller-string">lexicographically smallest string</span> that can be obtained after swapping <strong>adjacent</strong> digits in <code>s</code> with the same <strong>parity</strong> at most <strong>once</strong>.</p>
<p>Digits have the same parity if both are odd or both are even. For example, 5 and 9, as well as 2 and 4, have the same parity, while 6 and 9 do not.</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;45320&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">&quot;43520&quot;</span></p>
<p><strong>Explanation: </strong></p>
<p><code>s[1] == &#39;5&#39;</code> and <code>s[2] == &#39;3&#39;</code> both have the same parity, and swapping them results in the lexicographically smallest string.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;001&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">&quot;001&quot;</span></p>
<p><strong>Explanation:</strong></p>
<p>There is no need to perform a swap because <code>s</code> is already the lexicographically smallest.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>2 &lt;= s.length &lt;= 100</code></li>
<li><code>s</code> consists only of digits.</li>
</ul>

@ -0,0 +1,49 @@
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>colors[i] == 1</code> means that tile <code>i</code> is <strong>blue</strong>.</li>
</ul>
<p>Every 3 contiguous tiles in the circle with <strong>alternating</strong> colors (the middle tile has a different color from its <strong>left</strong> and <strong>right</strong> tiles) is called an <strong>alternating</strong> group.</p>
<p>Return the number of <strong>alternating</strong> groups.</p>
<p><strong>Note</strong> that since <code>colors</code> represents a <strong>circle</strong>, the <strong>first</strong> and the <strong>last</strong> tiles are considered to be next to each other.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">colors = [1,1,1]</span></p>
<p><strong>Output:</strong> <span class="example-io">0</span></p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/05/16/image_2024-05-16_23-53-171.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" /></p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">colors = [0,1,0,0,1]</span></p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/05/16/image_2024-05-16_23-47-491.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" /></p>
<p>Alternating groups:</p>
<p><strong class="example"><img alt="" src="https://assets.leetcode.com/uploads/2024/05/16/image_2024-05-16_23-50-441.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" /></strong><img alt="" src="https://assets.leetcode.com/uploads/2024/05/16/image_2024-05-16_23-48-211.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" /><strong class="example"><img alt="" src="https://assets.leetcode.com/uploads/2024/05/16/image_2024-05-16_23-49-351.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" /></strong></p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>3 &lt;= colors.length &lt;= 100</code></li>
<li><code>0 &lt;= colors[i] &lt;= 1</code></li>
</ul>

@ -0,0 +1,66 @@
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>colors[i] == 1</code> means that tile <code>i</code> is <strong>blue</strong>.</li>
</ul>
<p>An <strong>alternating</strong> group is every <code>k</code> contiguous tiles in the circle with <strong>alternating</strong> colors (each tile in the group except the first and last one has a different color from its <strong>left</strong> and <strong>right</strong> tiles).</p>
<p>Return the number of <strong>alternating</strong> groups.</p>
<p><strong>Note</strong> that since <code>colors</code> represents a <strong>circle</strong>, the <strong>first</strong> and the <strong>last</strong> tiles are considered to be next to each other.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">colors = [0,1,0,1,0], k = 3</span></p>
<p><strong>Output:</strong> <span class="example-io">3</span></p>
<p><strong>Explanation:</strong></p>
<p><strong><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/06/19/screenshot-2024-05-28-183519.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /></strong></p>
<p>Alternating groups:</p>
<p><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/05/28/screenshot-2024-05-28-182448.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/05/28/screenshot-2024-05-28-182844.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/05/28/screenshot-2024-05-28-183057.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /></p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">colors = [0,1,0,0,1,0,1], k = 6</span></p>
<p><strong>Output:</strong> <span class="example-io">2</span></p>
<p><strong>Explanation:</strong></p>
<p><strong><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/06/19/screenshot-2024-05-28-183907.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /></strong></p>
<p>Alternating groups:</p>
<p><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/06/19/screenshot-2024-05-28-184128.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/06/19/screenshot-2024-05-28-184240.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /></p>
</div>
<p><strong class="example">Example 3:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">colors = [1,1,0,1], k = 4</span></p>
<p><strong>Output:</strong> <span class="example-io">0</span></p>
<p><strong>Explanation:</strong></p>
<p><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/06/19/screenshot-2024-05-28-184516.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /></p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>3 &lt;= colors.length &lt;= 10<sup>5</sup></code></li>
<li><code>0 &lt;= colors[i] &lt;= 1</code></li>
<li><code>3 &lt;= k &lt;= colors.length</code></li>
</ul>

@ -0,0 +1,56 @@
<p>You are given an array of integers <code>nums</code> and the <code>head</code> of a linked list. Return the <code>head</code> of the modified linked list after <strong>removing</strong> all nodes from the linked list that have a value that exists 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 = [1,2,3], head = [1,2,3,4,5]</span></p>
<p><strong>Output:</strong> <span class="example-io">[4,5]</span></p>
<p><strong>Explanation:</strong></p>
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/06/11/linkedlistexample0.png" style="width: 400px; height: 66px;" /></strong></p>
<p>Remove the nodes with values 1, 2, and 3.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [1], head = [1,2,1,2,1,2]</span></p>
<p><strong>Output:</strong> <span class="example-io">[2,2,2]</span></p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/11/linkedlistexample1.png" style="height: 62px; width: 450px;" /></p>
<p>Remove the nodes with value 1.</p>
</div>
<p><strong class="example">Example 3:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [5], head = [1,2,3,4]</span></p>
<p><strong>Output:</strong> <span class="example-io">[1,2,3,4]</span></p>
<p><strong>Explanation:</strong></p>
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/06/11/linkedlistexample2.png" style="width: 400px; height: 83px;" /></strong></p>
<p>No node has value 5.</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>5</sup></code></li>
<li>All elements in <code>nums</code> are unique.</li>
<li>The number of nodes in the given list is in the range <code>[1, 10<sup>5</sup>]</code>.</li>
<li><code>1 &lt;= Node.val &lt;= 10<sup>5</sup></code></li>
<li>The input is generated such that there is at least one node in the linked list that has a value not present in <code>nums</code>.</li>
</ul>

@ -0,0 +1,72 @@
<p>There is an <code>m x n</code> cake that needs to be cut into <code>1 x 1</code> pieces.</p>
<p>You are given integers <code>m</code>, <code>n</code>, and two arrays:</p>
<ul>
<li><code>horizontalCut</code> of size <code>m - 1</code>, where <code>horizontalCut[i]</code> represents the cost to cut along the horizontal line <code>i</code>.</li>
<li><code>verticalCut</code> of size <code>n - 1</code>, where <code>verticalCut[j]</code> represents the cost to cut along the vertical line <code>j</code>.</li>
</ul>
<p>In one operation, you can choose any piece of cake that is not yet a <code>1 x 1</code> square and perform one of the following cuts:</p>
<ol>
<li>Cut along a horizontal line <code>i</code> at a cost of <code>horizontalCut[i]</code>.</li>
<li>Cut along a vertical line <code>j</code> at a cost of <code>verticalCut[j]</code>.</li>
</ol>
<p>After the cut, the piece of cake is divided into two distinct pieces.</p>
<p>The cost of a cut depends only on the initial cost of the line and does not change.</p>
<p>Return the <strong>minimum</strong> total cost to cut the entire cake into <code>1 x 1</code> pieces.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">m = 3, n = 2, horizontalCut = [1,3], verticalCut = [5]</span></p>
<p><strong>Output:</strong> <span class="example-io">13</span></p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/04/ezgifcom-animated-gif-maker-1.gif" style="width: 280px; height: 320px;" /></p>
<ul>
<li>Perform a cut on the vertical line 0 with cost 5, current total cost is 5.</li>
<li>Perform a cut on the horizontal line 0 on <code>3 x 1</code> subgrid with cost 1.</li>
<li>Perform a cut on the horizontal line 0 on <code>3 x 1</code> subgrid with cost 1.</li>
<li>Perform a cut on the horizontal line 1 on <code>2 x 1</code> subgrid with cost 3.</li>
<li>Perform a cut on the horizontal line 1 on <code>2 x 1</code> subgrid with cost 3.</li>
</ul>
<p>The total cost is <code>5 + 1 + 1 + 3 + 3 = 13</code>.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">m = 2, n = 2, horizontalCut = [7], verticalCut = [4]</span></p>
<p><strong>Output:</strong> <span class="example-io">15</span></p>
<p><strong>Explanation:</strong></p>
<ul>
<li>Perform a cut on the horizontal line 0 with cost 7.</li>
<li>Perform a cut on the vertical line 0 on <code>1 x 2</code> subgrid with cost 4.</li>
<li>Perform a cut on the vertical line 0 on <code>1 x 2</code> subgrid with cost 4.</li>
</ul>
<p>The total cost is <code>7 + 4 + 4 = 15</code>.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= m, n &lt;= 20</code></li>
<li><code>horizontalCut.length == m - 1</code></li>
<li><code>verticalCut.length == n - 1</code></li>
<li><code>1 &lt;= horizontalCut[i], verticalCut[i] &lt;= 10<sup>3</sup></code></li>
</ul>

@ -0,0 +1,72 @@
<p>There is an <code>m x n</code> cake that needs to be cut into <code>1 x 1</code> pieces.</p>
<p>You are given integers <code>m</code>, <code>n</code>, and two arrays:</p>
<ul>
<li><code>horizontalCut</code> of size <code>m - 1</code>, where <code>horizontalCut[i]</code> represents the cost to cut along the horizontal line <code>i</code>.</li>
<li><code>verticalCut</code> of size <code>n - 1</code>, where <code>verticalCut[j]</code> represents the cost to cut along the vertical line <code>j</code>.</li>
</ul>
<p>In one operation, you can choose any piece of cake that is not yet a <code>1 x 1</code> square and perform one of the following cuts:</p>
<ol>
<li>Cut along a horizontal line <code>i</code> at a cost of <code>horizontalCut[i]</code>.</li>
<li>Cut along a vertical line <code>j</code> at a cost of <code>verticalCut[j]</code>.</li>
</ol>
<p>After the cut, the piece of cake is divided into two distinct pieces.</p>
<p>The cost of a cut depends only on the initial cost of the line and does not change.</p>
<p>Return the <strong>minimum</strong> total cost to cut the entire cake into <code>1 x 1</code> pieces.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">m = 3, n = 2, horizontalCut = [1,3], verticalCut = [5]</span></p>
<p><strong>Output:</strong> <span class="example-io">13</span></p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/04/ezgifcom-animated-gif-maker-1.gif" style="width: 280px; height: 320px;" /></p>
<ul>
<li>Perform a cut on the vertical line 0 with cost 5, current total cost is 5.</li>
<li>Perform a cut on the horizontal line 0 on <code>3 x 1</code> subgrid with cost 1.</li>
<li>Perform a cut on the horizontal line 0 on <code>3 x 1</code> subgrid with cost 1.</li>
<li>Perform a cut on the horizontal line 1 on <code>2 x 1</code> subgrid with cost 3.</li>
<li>Perform a cut on the horizontal line 1 on <code>2 x 1</code> subgrid with cost 3.</li>
</ul>
<p>The total cost is <code>5 + 1 + 1 + 3 + 3 = 13</code>.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">m = 2, n = 2, horizontalCut = [7], verticalCut = [4]</span></p>
<p><strong>Output:</strong> <span class="example-io">15</span></p>
<p><strong>Explanation:</strong></p>
<ul>
<li>Perform a cut on the horizontal line 0 with cost 7.</li>
<li>Perform a cut on the vertical line 0 on <code>1 x 2</code> subgrid with cost 4.</li>
<li>Perform a cut on the vertical line 0 on <code>1 x 2</code> subgrid with cost 4.</li>
</ul>
<p>The total cost is <code>7 + 4 + 4 = 15</code>.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= m, n &lt;= 10<sup>5</sup></code></li>
<li><code>horizontalCut.length == m - 1</code></li>
<li><code>verticalCut.length == n - 1</code></li>
<li><code>1 &lt;= horizontalCut[i], verticalCut[i] &lt;= 10<sup>3</sup></code></li>
</ul>

@ -0,0 +1,47 @@
<p>There exist two <strong>undirected </strong>trees with <code>n</code> and <code>m</code> nodes, numbered from <code>0</code> to <code>n - 1</code> and from <code>0</code> to <code>m - 1</code>, respectively. You are given two 2D integer arrays <code>edges1</code> and <code>edges2</code> of lengths <code>n - 1</code> and <code>m - 1</code>, respectively, where <code>edges1[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that there is an edge between nodes <code>a<sub>i</sub></code> and <code>b<sub>i</sub></code> in the first tree and <code>edges2[i] = [u<sub>i</sub>, v<sub>i</sub>]</code> indicates that there is an edge between nodes <code>u<sub>i</sub></code> and <code>v<sub>i</sub></code> in the second tree.</p>
<p>You must connect one node from the first tree with another node from the second tree with an edge.</p>
<p>Return the <strong>minimum </strong>possible <strong>diameter </strong>of the resulting tree.</p>
<p>The <strong>diameter</strong> of a tree is the length of the <em>longest</em> path between any two nodes in the tree.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong><img alt="" src="https://assets.leetcode.com/uploads/2024/04/22/example11-transformed.png" /></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">edges1 = [[0,1],[0,2],[0,3]], edges2 = [[0,1]]</span></p>
<p><strong>Output:</strong> <span class="example-io">3</span></p>
<p><strong>Explanation:</strong></p>
<p>We can obtain a tree of diameter 3 by connecting node 0 from the first tree with any node from the second tree.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2024/04/22/example211.png" />
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">edges1 = [[0,1],[0,2],[0,3],[2,4],[2,5],[3,6],[2,7]], edges2 = [[0,1],[0,2],[0,3],[2,4],[2,5],[3,6],[2,7]]</span></p>
<p><strong>Output:</strong> <span class="example-io">5</span></p>
<p><strong>Explanation:</strong></p>
<p>We can obtain a tree of diameter 5 by connecting node 0 from the first tree with node 0 from the second tree.</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>edges1.length == n - 1</code></li>
<li><code>edges2.length == m - 1</code></li>
<li><code>edges1[i].length == edges2[i].length == 2</code></li>
<li><code>edges1[i] = [a<sub>i</sub>, b<sub>i</sub>]</code></li>
<li><code>0 &lt;= a<sub>i</sub>, b<sub>i</sub> &lt; n</code></li>
<li><code>edges2[i] = [u<sub>i</sub>, v<sub>i</sub>]</code></li>
<li><code>0 &lt;= u<sub>i</sub>, v<sub>i</sub> &lt; m</code></li>
<li>The input is generated such that <code>edges1</code> and <code>edges2</code> represent valid trees.</li>
</ul>

@ -0,0 +1,46 @@
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</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,1,1], k = 1</span></p>
<p><strong>Output:</strong> <span class="example-io">6</span></p>
<p><strong>Explanation:</strong></p>
<p>All subarrays contain only 1&#39;s.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [1,1,2], k = 1</span></p>
<p><strong>Output:</strong> <span class="example-io">3</span></p>
<p><strong>Explanation:</strong></p>
<p>Subarrays having an <code>AND</code> value of 1 are: <code>[<u><strong>1</strong></u>,1,2]</code>, <code>[1,<u><strong>1</strong></u>,2]</code>, <code>[<u><strong>1,1</strong></u>,2]</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,3], k = 2</span></p>
<p><strong>Output:</strong> <span class="example-io">2</span></p>
<p><strong>Explanation:</strong></p>
<p>Subarrays having an <code>AND</code> value of 2 are: <code>[1,<b><u>2</u></b>,3]</code>, <code>[1,<u><strong>2,3</strong></u>]</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>0 &lt;= nums[i], k &lt;= 10<sup>9</sup></code></li>
</ul>

@ -0,0 +1,46 @@
<p>You are given a string <code>s</code> and an integer <code>k</code>. Encrypt the string using the following algorithm:</p>
<ul>
<li>For each character <code>c</code> in <code>s</code>, replace <code>c</code> with the <code>k<sup>th</sup></code> character after <code>c</code> in the string (in a cyclic manner).</li>
</ul>
<p>Return the <em>encrypted string</em>.</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;dart&quot;, k = 3</span></p>
<p><strong>Output:</strong> <span class="example-io">&quot;tdar&quot;</span></p>
<p><strong>Explanation:</strong></p>
<ul>
<li>For <code>i = 0</code>, the 3<sup>rd</sup> character after <code>&#39;d&#39;</code> is <code>&#39;t&#39;</code>.</li>
<li>For <code>i = 1</code>, the 3<sup>rd</sup> character after <code>&#39;a&#39;</code> is <code>&#39;d&#39;</code>.</li>
<li>For <code>i = 2</code>, the 3<sup>rd</sup> character after <code>&#39;r&#39;</code> is <code>&#39;a&#39;</code>.</li>
<li>For <code>i = 3</code>, the 3<sup>rd</sup> character after <code>&#39;t&#39;</code> is <code>&#39;r&#39;</code>.</li>
</ul>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;aaa&quot;, k = 1</span></p>
<p><strong>Output:</strong> <span class="example-io">&quot;aaa&quot;</span></p>
<p><strong>Explanation:</strong></p>
<p>As all the characters are the same, the encrypted string will also be the same.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 100</code></li>
<li><code>1 &lt;= k &lt;= 10<sup>4</sup></code></li>
<li><code>s</code> consists only of lowercase English letters.</li>
</ul>

@ -0,0 +1,55 @@
You are given an integer array <code>nums</code>.
<p>A <span data-keyword="subsequence-array">subsequence</span> <code>sub</code> of <code>nums</code> with length <code>x</code> is called <strong>valid</strong> if it satisfies:</p>
<ul>
<li><code>(sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == ... == (sub[x - 2] + sub[x - 1]) % 2.</code></li>
</ul>
<p>Return the length of the <strong>longest</strong> <strong>valid</strong> subsequence of <code>nums</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 = [1,2,3,4]</span></p>
<p><strong>Output:</strong> <span class="example-io">4</span></p>
<p><strong>Explanation:</strong></p>
<p>The longest valid subsequence is <code>[1, 2, 3, 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 = [1,2,1,1,2,1,2]</span></p>
<p><strong>Output:</strong> 6</p>
<p><strong>Explanation:</strong></p>
<p>The longest valid subsequence is <code>[1, 2, 1, 2, 1, 2]</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,3]</span></p>
<p><strong>Output:</strong> <span class="example-io">2</span></p>
<p><strong>Explanation:</strong></p>
<p>The longest valid subsequence is <code>[1, 3]</code>.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>2 &lt;= nums.length &lt;= 2 * 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>7</sup></code></li>
</ul>

@ -0,0 +1,40 @@
You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.
<p>A <span data-keyword="subsequence-array">subsequence</span> <code>sub</code> of <code>nums</code> with length <code>x</code> is called <strong>valid</strong> if it satisfies:</p>
<ul>
<li><code>(sub[0] + sub[1]) % k == (sub[1] + sub[2]) % k == ... == (sub[x - 2] + sub[x - 1]) % k.</code></li>
</ul>
Return the length of the <strong>longest</strong> <strong>valid</strong> subsequence of <code>nums</code>.
<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,3,4,5], k = 2</span></p>
<p><strong>Output:</strong> <span class="example-io">5</span></p>
<p><strong>Explanation:</strong></p>
<p>The longest valid subsequence is <code>[1, 2, 3, 4, 5]</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,4,2,3,1,4], k = 3</span></p>
<p><strong>Output:</strong> <span class="example-io">4</span></p>
<p><strong>Explanation:</strong></p>
<p>The longest valid subsequence is <code>[1, 4, 1, 4]</code>.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>2 &lt;= nums.length &lt;= 10<sup>3</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>7</sup></code></li>
<li><code>1 &lt;= k &lt;= 10<sup>3</sup></code></li>
</ul>

@ -0,0 +1,56 @@
<p>You are given a string <code>target</code>, an array of strings <code>words</code>, and an integer array <code>costs</code>, both arrays of the same length.</p>
<p>Imagine an empty string <code>s</code>.</p>
<p>You can perform the following operation any number of times (including <strong>zero</strong>):</p>
<ul>
<li>Choose an index <code>i</code> in the range <code>[0, words.length - 1]</code>.</li>
<li>Append <code>words[i]</code> to <code>s</code>.</li>
<li>The cost of operation is <code>costs[i]</code>.</li>
</ul>
<p>Return the <strong>minimum</strong> cost to make <code>s</code> equal to <code>target</code>. If it&#39;s not possible, return <code>-1</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">target = &quot;abcdef&quot;, words = [&quot;abdef&quot;,&quot;abc&quot;,&quot;d&quot;,&quot;def&quot;,&quot;ef&quot;], costs = [100,1,1,10,5]</span></p>
<p><strong>Output:</strong> <span class="example-io">7</span></p>
<p><strong>Explanation:</strong></p>
<p>The minimum cost can be achieved by performing the following operations:</p>
<ul>
<li>Select index 1 and append <code>&quot;abc&quot;</code> to <code>s</code> at a cost of 1, resulting in <code>s = &quot;abc&quot;</code>.</li>
<li>Select index 2 and append <code>&quot;d&quot;</code> to <code>s</code> at a cost of 1, resulting in <code>s = &quot;abcd&quot;</code>.</li>
<li>Select index 4 and append <code>&quot;ef&quot;</code> to <code>s</code> at a cost of 5, resulting in <code>s = &quot;abcdef&quot;</code>.</li>
</ul>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">target = &quot;aaaa&quot;, words = [&quot;z&quot;,&quot;zz&quot;,&quot;zzz&quot;], costs = [1,10,100]</span></p>
<p><strong>Output:</strong> <span class="example-io">-1</span></p>
<p><strong>Explanation:</strong></p>
<p>It is impossible to make <code>s</code> equal to <code>target</code>, so we return -1.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= target.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>1 &lt;= words.length == costs.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>1 &lt;= words[i].length &lt;= target.length</code></li>
<li>The total sum of <code>words[i].length</code> is less than or equal to <code>5 * 10<sup>4</sup></code>.</li>
<li><code>target</code> and <code>words[i]</code> consist only of lowercase English letters.</li>
<li><code>1 &lt;= costs[i] &lt;= 10<sup>4</sup></code></li>
</ul>

@ -0,0 +1,37 @@
<p>You are given a positive integer <code>n</code>.</p>
<p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p>
<p>Return all <strong>valid</strong> strings with length <code>n</code><strong>, </strong>in <em>any</em> order.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 3</span></p>
<p><strong>Output:</strong> <span class="example-io">[&quot;010&quot;,&quot;011&quot;,&quot;101&quot;,&quot;110&quot;,&quot;111&quot;]</span></p>
<p><strong>Explanation:</strong></p>
<p>The valid strings of length 3 are: <code>&quot;010&quot;</code>, <code>&quot;011&quot;</code>, <code>&quot;101&quot;</code>, <code>&quot;110&quot;</code>, and <code>&quot;111&quot;</code>.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 1</span></p>
<p><strong>Output:</strong> <span class="example-io">[&quot;0&quot;,&quot;1&quot;]</span></p>
<p><strong>Explanation:</strong></p>
<p>The valid strings of length 1 are: <code>&quot;0&quot;</code> and <code>&quot;1&quot;</code>.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= n &lt;= 18</code></li>
</ul>

@ -0,0 +1,52 @@
<p>Given a 2D character matrix <code>grid</code>, where <code>grid[i][j]</code> is either <code>&#39;X&#39;</code>, <code>&#39;Y&#39;</code>, or <code>&#39;.&#39;</code>, return the number of <span data-keyword="submatrix">submatrices</span> that contain:</p>
<ul>
<li><code>grid[0][0]</code></li>
<li>an <strong>equal</strong> frequency of <code>&#39;X&#39;</code> and <code>&#39;Y&#39;</code>.</li>
<li><strong>at least</strong> one <code>&#39;X&#39;</code>.</li>
</ul>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">grid = [[&quot;X&quot;,&quot;Y&quot;,&quot;.&quot;],[&quot;Y&quot;,&quot;.&quot;,&quot;.&quot;]]</span></p>
<p><strong>Output:</strong> <span class="example-io">3</span></p>
<p><strong>Explanation:</strong></p>
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/06/07/examplems.png" style="padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; width: 175px; height: 350px;" /></strong></p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">grid = [[&quot;X&quot;,&quot;X&quot;],[&quot;X&quot;,&quot;Y&quot;]]</span></p>
<p><strong>Output:</strong> <span class="example-io">0</span></p>
<p><strong>Explanation:</strong></p>
<p>No submatrix has an equal frequency of <code>&#39;X&#39;</code> and <code>&#39;Y&#39;</code>.</p>
</div>
<p><strong class="example">Example 3:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">grid = [[&quot;.&quot;,&quot;.&quot;],[&quot;.&quot;,&quot;.&quot;]]</span></p>
<p><strong>Output:</strong> <span class="example-io">0</span></p>
<p><strong>Explanation:</strong></p>
<p>No submatrix has at least one <code>&#39;X&#39;</code>.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= grid.length, grid[i].length &lt;= 1000</code></li>
<li><code>grid[i][j]</code> is either <code>&#39;X&#39;</code>, <code>&#39;Y&#39;</code>, or <code>&#39;.&#39;</code>.</li>
</ul>

File diff suppressed because it is too large Load Diff

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

@ -0,0 +1,49 @@
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>colors[i] == 1</code> means that tile <code>i</code> is <strong>blue</strong>.</li>
</ul>
<p>Every 3 contiguous tiles in the circle with <strong>alternating</strong> colors (the middle tile has a different color from its <strong>left</strong> and <strong>right</strong> tiles) is called an <strong>alternating</strong> group.</p>
<p>Return the number of <strong>alternating</strong> groups.</p>
<p><strong>Note</strong> that since <code>colors</code> represents a <strong>circle</strong>, the <strong>first</strong> and the <strong>last</strong> tiles are considered to be next to each other.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">colors = [1,1,1]</span></p>
<p><strong>Output:</strong> <span class="example-io">0</span></p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/05/16/image_2024-05-16_23-53-171.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" /></p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">colors = [0,1,0,0,1]</span></p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/05/16/image_2024-05-16_23-47-491.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" /></p>
<p>Alternating groups:</p>
<p><strong class="example"><img alt="" src="https://assets.leetcode.com/uploads/2024/05/16/image_2024-05-16_23-50-441.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" /></strong><img alt="" src="https://assets.leetcode.com/uploads/2024/05/16/image_2024-05-16_23-48-211.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" /><strong class="example"><img alt="" src="https://assets.leetcode.com/uploads/2024/05/16/image_2024-05-16_23-49-351.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" /></strong></p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>3 &lt;= colors.length &lt;= 100</code></li>
<li><code>0 &lt;= colors[i] &lt;= 1</code></li>
</ul>

@ -0,0 +1,66 @@
<p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>colors[i] == 1</code> means that tile <code>i</code> is <strong>blue</strong>.</li>
</ul>
<p>An <strong>alternating</strong> group is every <code>k</code> contiguous tiles in the circle with <strong>alternating</strong> colors (each tile in the group except the first and last one has a different color from its <strong>left</strong> and <strong>right</strong> tiles).</p>
<p>Return the number of <strong>alternating</strong> groups.</p>
<p><strong>Note</strong> that since <code>colors</code> represents a <strong>circle</strong>, the <strong>first</strong> and the <strong>last</strong> tiles are considered to be next to each other.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">colors = [0,1,0,1,0], k = 3</span></p>
<p><strong>Output:</strong> <span class="example-io">3</span></p>
<p><strong>Explanation:</strong></p>
<p><strong><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/06/19/screenshot-2024-05-28-183519.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /></strong></p>
<p>Alternating groups:</p>
<p><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/05/28/screenshot-2024-05-28-182448.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/05/28/screenshot-2024-05-28-182844.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/05/28/screenshot-2024-05-28-183057.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /></p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">colors = [0,1,0,0,1,0,1], k = 6</span></p>
<p><strong>Output:</strong> <span class="example-io">2</span></p>
<p><strong>Explanation:</strong></p>
<p><strong><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/06/19/screenshot-2024-05-28-183907.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /></strong></p>
<p>Alternating groups:</p>
<p><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/06/19/screenshot-2024-05-28-184128.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/06/19/screenshot-2024-05-28-184240.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /></p>
</div>
<p><strong class="example">Example 3:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">colors = [1,1,0,1], k = 4</span></p>
<p><strong>Output:</strong> <span class="example-io">0</span></p>
<p><strong>Explanation:</strong></p>
<p><img alt="" data-darkreader-inline-bgcolor="" data-darkreader-inline-bgimage="" src="https://assets.leetcode.com/uploads/2024/06/19/screenshot-2024-05-28-184516.png" style="width: 150px; height: 150px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; --darkreader-inline-bgimage: initial; --darkreader-inline-bgcolor: #181a1b;" /></p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>3 &lt;= colors.length &lt;= 10<sup>5</sup></code></li>
<li><code>0 &lt;= colors[i] &lt;= 1</code></li>
<li><code>3 &lt;= k &lt;= colors.length</code></li>
</ul>

@ -0,0 +1,56 @@
<p>You are given a string <code>target</code>, an array of strings <code>words</code>, and an integer array <code>costs</code>, both arrays of the same length.</p>
<p>Imagine an empty string <code>s</code>.</p>
<p>You can perform the following operation any number of times (including <strong>zero</strong>):</p>
<ul>
<li>Choose an index <code>i</code> in the range <code>[0, words.length - 1]</code>.</li>
<li>Append <code>words[i]</code> to <code>s</code>.</li>
<li>The cost of operation is <code>costs[i]</code>.</li>
</ul>
<p>Return the <strong>minimum</strong> cost to make <code>s</code> equal to <code>target</code>. If it&#39;s not possible, return <code>-1</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">target = &quot;abcdef&quot;, words = [&quot;abdef&quot;,&quot;abc&quot;,&quot;d&quot;,&quot;def&quot;,&quot;ef&quot;], costs = [100,1,1,10,5]</span></p>
<p><strong>Output:</strong> <span class="example-io">7</span></p>
<p><strong>Explanation:</strong></p>
<p>The minimum cost can be achieved by performing the following operations:</p>
<ul>
<li>Select index 1 and append <code>&quot;abc&quot;</code> to <code>s</code> at a cost of 1, resulting in <code>s = &quot;abc&quot;</code>.</li>
<li>Select index 2 and append <code>&quot;d&quot;</code> to <code>s</code> at a cost of 1, resulting in <code>s = &quot;abcd&quot;</code>.</li>
<li>Select index 4 and append <code>&quot;ef&quot;</code> to <code>s</code> at a cost of 5, resulting in <code>s = &quot;abcdef&quot;</code>.</li>
</ul>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">target = &quot;aaaa&quot;, words = [&quot;z&quot;,&quot;zz&quot;,&quot;zzz&quot;], costs = [1,10,100]</span></p>
<p><strong>Output:</strong> <span class="example-io">-1</span></p>
<p><strong>Explanation:</strong></p>
<p>It is impossible to make <code>s</code> equal to <code>target</code>, so we return -1.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= target.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>1 &lt;= words.length == costs.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>1 &lt;= words[i].length &lt;= target.length</code></li>
<li>The total sum of <code>words[i].length</code> is less than or equal to <code>5 * 10<sup>4</sup></code>.</li>
<li><code>target</code> and <code>words[i]</code> consist only of lowercase English letters.</li>
<li><code>1 &lt;= costs[i] &lt;= 10<sup>4</sup></code></li>
</ul>

@ -0,0 +1,52 @@
<p>Given a 2D character matrix <code>grid</code>, where <code>grid[i][j]</code> is either <code>&#39;X&#39;</code>, <code>&#39;Y&#39;</code>, or <code>&#39;.&#39;</code>, return the number of <span data-keyword="submatrix">submatrices</span> that contain:</p>
<ul>
<li><code>grid[0][0]</code></li>
<li>an <strong>equal</strong> frequency of <code>&#39;X&#39;</code> and <code>&#39;Y&#39;</code>.</li>
<li><strong>at least</strong> one <code>&#39;X&#39;</code>.</li>
</ul>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">grid = [[&quot;X&quot;,&quot;Y&quot;,&quot;.&quot;],[&quot;Y&quot;,&quot;.&quot;,&quot;.&quot;]]</span></p>
<p><strong>Output:</strong> <span class="example-io">3</span></p>
<p><strong>Explanation:</strong></p>
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/06/07/examplems.png" style="padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; width: 175px; height: 350px;" /></strong></p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">grid = [[&quot;X&quot;,&quot;X&quot;],[&quot;X&quot;,&quot;Y&quot;]]</span></p>
<p><strong>Output:</strong> <span class="example-io">0</span></p>
<p><strong>Explanation:</strong></p>
<p>No submatrix has an equal frequency of <code>&#39;X&#39;</code> and <code>&#39;Y&#39;</code>.</p>
</div>
<p><strong class="example">Example 3:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">grid = [[&quot;.&quot;,&quot;.&quot;],[&quot;.&quot;,&quot;.&quot;]]</span></p>
<p><strong>Output:</strong> <span class="example-io">0</span></p>
<p><strong>Explanation:</strong></p>
<p>No submatrix has at least one <code>&#39;X&#39;</code>.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= grid.length, grid[i].length &lt;= 1000</code></li>
<li><code>grid[i][j]</code> is either <code>&#39;X&#39;</code>, <code>&#39;Y&#39;</code>, or <code>&#39;.&#39;</code>.</li>
</ul>

@ -0,0 +1,56 @@
<p>You are given an array of integers <code>nums</code> and the <code>head</code> of a linked list. Return the <code>head</code> of the modified linked list after <strong>removing</strong> all nodes from the linked list that have a value that exists 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 = [1,2,3], head = [1,2,3,4,5]</span></p>
<p><strong>Output:</strong> <span class="example-io">[4,5]</span></p>
<p><strong>Explanation:</strong></p>
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/06/11/linkedlistexample0.png" style="width: 400px; height: 66px;" /></strong></p>
<p>Remove the nodes with values 1, 2, and 3.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [1], head = [1,2,1,2,1,2]</span></p>
<p><strong>Output:</strong> <span class="example-io">[2,2,2]</span></p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/11/linkedlistexample1.png" style="height: 62px; width: 450px;" /></p>
<p>Remove the nodes with value 1.</p>
</div>
<p><strong class="example">Example 3:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [5], head = [1,2,3,4]</span></p>
<p><strong>Output:</strong> <span class="example-io">[1,2,3,4]</span></p>
<p><strong>Explanation:</strong></p>
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/06/11/linkedlistexample2.png" style="width: 400px; height: 83px;" /></strong></p>
<p>No node has value 5.</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>5</sup></code></li>
<li>All elements in <code>nums</code> are unique.</li>
<li>The number of nodes in the given list is in the range <code>[1, 10<sup>5</sup>]</code>.</li>
<li><code>1 &lt;= Node.val &lt;= 10<sup>5</sup></code></li>
<li>The input is generated such that there is at least one node in the linked list that has a value not present in <code>nums</code>.</li>
</ul>

@ -0,0 +1,47 @@
<p>There exist two <strong>undirected </strong>trees with <code>n</code> and <code>m</code> nodes, numbered from <code>0</code> to <code>n - 1</code> and from <code>0</code> to <code>m - 1</code>, respectively. You are given two 2D integer arrays <code>edges1</code> and <code>edges2</code> of lengths <code>n - 1</code> and <code>m - 1</code>, respectively, where <code>edges1[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that there is an edge between nodes <code>a<sub>i</sub></code> and <code>b<sub>i</sub></code> in the first tree and <code>edges2[i] = [u<sub>i</sub>, v<sub>i</sub>]</code> indicates that there is an edge between nodes <code>u<sub>i</sub></code> and <code>v<sub>i</sub></code> in the second tree.</p>
<p>You must connect one node from the first tree with another node from the second tree with an edge.</p>
<p>Return the <strong>minimum </strong>possible <strong>diameter </strong>of the resulting tree.</p>
<p>The <strong>diameter</strong> of a tree is the length of the <em>longest</em> path between any two nodes in the tree.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong><img alt="" src="https://assets.leetcode.com/uploads/2024/04/22/example11-transformed.png" /></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">edges1 = [[0,1],[0,2],[0,3]], edges2 = [[0,1]]</span></p>
<p><strong>Output:</strong> <span class="example-io">3</span></p>
<p><strong>Explanation:</strong></p>
<p>We can obtain a tree of diameter 3 by connecting node 0 from the first tree with any node from the second tree.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2024/04/22/example211.png" />
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">edges1 = [[0,1],[0,2],[0,3],[2,4],[2,5],[3,6],[2,7]], edges2 = [[0,1],[0,2],[0,3],[2,4],[2,5],[3,6],[2,7]]</span></p>
<p><strong>Output:</strong> <span class="example-io">5</span></p>
<p><strong>Explanation:</strong></p>
<p>We can obtain a tree of diameter 5 by connecting node 0 from the first tree with node 0 from the second tree.</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>edges1.length == n - 1</code></li>
<li><code>edges2.length == m - 1</code></li>
<li><code>edges1[i].length == edges2[i].length == 2</code></li>
<li><code>edges1[i] = [a<sub>i</sub>, b<sub>i</sub>]</code></li>
<li><code>0 &lt;= a<sub>i</sub>, b<sub>i</sub> &lt; n</code></li>
<li><code>edges2[i] = [u<sub>i</sub>, v<sub>i</sub>]</code></li>
<li><code>0 &lt;= u<sub>i</sub>, v<sub>i</sub> &lt; m</code></li>
<li>The input is generated such that <code>edges1</code> and <code>edges2</code> represent valid trees.</li>
</ul>

@ -0,0 +1,46 @@
<p>You are given a string <code>s</code> and an integer <code>k</code>. Encrypt the string using the following algorithm:</p>
<ul>
<li>For each character <code>c</code> in <code>s</code>, replace <code>c</code> with the <code>k<sup>th</sup></code> character after <code>c</code> in the string (in a cyclic manner).</li>
</ul>
<p>Return the <em>encrypted string</em>.</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;dart&quot;, k = 3</span></p>
<p><strong>Output:</strong> <span class="example-io">&quot;tdar&quot;</span></p>
<p><strong>Explanation:</strong></p>
<ul>
<li>For <code>i = 0</code>, the 3<sup>rd</sup> character after <code>&#39;d&#39;</code> is <code>&#39;t&#39;</code>.</li>
<li>For <code>i = 1</code>, the 3<sup>rd</sup> character after <code>&#39;a&#39;</code> is <code>&#39;d&#39;</code>.</li>
<li>For <code>i = 2</code>, the 3<sup>rd</sup> character after <code>&#39;r&#39;</code> is <code>&#39;a&#39;</code>.</li>
<li>For <code>i = 3</code>, the 3<sup>rd</sup> character after <code>&#39;t&#39;</code> is <code>&#39;r&#39;</code>.</li>
</ul>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;aaa&quot;, k = 1</span></p>
<p><strong>Output:</strong> <span class="example-io">&quot;aaa&quot;</span></p>
<p><strong>Explanation:</strong></p>
<p>As all the characters are the same, the encrypted string will also be the same.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 100</code></li>
<li><code>1 &lt;= k &lt;= 10<sup>4</sup></code></li>
<li><code>s</code> consists only of lowercase English letters.</li>
</ul>

@ -0,0 +1,55 @@
You are given an integer array <code>nums</code>.
<p>A <span data-keyword="subsequence-array">subsequence</span> <code>sub</code> of <code>nums</code> with length <code>x</code> is called <strong>valid</strong> if it satisfies:</p>
<ul>
<li><code>(sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == ... == (sub[x - 2] + sub[x - 1]) % 2.</code></li>
</ul>
<p>Return the length of the <strong>longest</strong> <strong>valid</strong> subsequence of <code>nums</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 = [1,2,3,4]</span></p>
<p><strong>Output:</strong> <span class="example-io">4</span></p>
<p><strong>Explanation:</strong></p>
<p>The longest valid subsequence is <code>[1, 2, 3, 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 = [1,2,1,1,2,1,2]</span></p>
<p><strong>Output:</strong> 6</p>
<p><strong>Explanation:</strong></p>
<p>The longest valid subsequence is <code>[1, 2, 1, 2, 1, 2]</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,3]</span></p>
<p><strong>Output:</strong> <span class="example-io">2</span></p>
<p><strong>Explanation:</strong></p>
<p>The longest valid subsequence is <code>[1, 3]</code>.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>2 &lt;= nums.length &lt;= 2 * 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>7</sup></code></li>
</ul>

@ -0,0 +1,40 @@
You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.
<p>A <span data-keyword="subsequence-array">subsequence</span> <code>sub</code> of <code>nums</code> with length <code>x</code> is called <strong>valid</strong> if it satisfies:</p>
<ul>
<li><code>(sub[0] + sub[1]) % k == (sub[1] + sub[2]) % k == ... == (sub[x - 2] + sub[x - 1]) % k.</code></li>
</ul>
Return the length of the <strong>longest</strong> <strong>valid</strong> subsequence of <code>nums</code>.
<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,3,4,5], k = 2</span></p>
<p><strong>Output:</strong> <span class="example-io">5</span></p>
<p><strong>Explanation:</strong></p>
<p>The longest valid subsequence is <code>[1, 2, 3, 4, 5]</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,4,2,3,1,4], k = 3</span></p>
<p><strong>Output:</strong> <span class="example-io">4</span></p>
<p><strong>Explanation:</strong></p>
<p>The longest valid subsequence is <code>[1, 4, 1, 4]</code>.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>2 &lt;= nums.length &lt;= 10<sup>3</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>7</sup></code></li>
<li><code>1 &lt;= k &lt;= 10<sup>3</sup></code></li>
</ul>

@ -0,0 +1,37 @@
<p>You are given a positive integer <code>n</code>.</p>
<p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p>
<p>Return all <strong>valid</strong> strings with length <code>n</code><strong>, </strong>in <em>any</em> order.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 3</span></p>
<p><strong>Output:</strong> <span class="example-io">[&quot;010&quot;,&quot;011&quot;,&quot;101&quot;,&quot;110&quot;,&quot;111&quot;]</span></p>
<p><strong>Explanation:</strong></p>
<p>The valid strings of length 3 are: <code>&quot;010&quot;</code>, <code>&quot;011&quot;</code>, <code>&quot;101&quot;</code>, <code>&quot;110&quot;</code>, and <code>&quot;111&quot;</code>.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 1</span></p>
<p><strong>Output:</strong> <span class="example-io">[&quot;0&quot;,&quot;1&quot;]</span></p>
<p><strong>Explanation:</strong></p>
<p>The valid strings of length 1 are: <code>&quot;0&quot;</code> and <code>&quot;1&quot;</code>.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= n &lt;= 18</code></li>
</ul>

@ -0,0 +1,36 @@
<p>Given a string <code>s</code> containing only digits, return the <span data-keyword="lexicographically-smaller-string">lexicographically smallest string</span> that can be obtained after swapping <strong>adjacent</strong> digits in <code>s</code> with the same <strong>parity</strong> at most <strong>once</strong>.</p>
<p>Digits have the same parity if both are odd or both are even. For example, 5 and 9, as well as 2 and 4, have the same parity, while 6 and 9 do not.</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;45320&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">&quot;43520&quot;</span></p>
<p><strong>Explanation: </strong></p>
<p><code>s[1] == &#39;5&#39;</code> and <code>s[2] == &#39;3&#39;</code> both have the same parity, and swapping them results in the lexicographically smallest string.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;001&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">&quot;001&quot;</span></p>
<p><strong>Explanation:</strong></p>
<p>There is no need to perform a swap because <code>s</code> is already the lexicographically smallest.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>2 &lt;= s.length &lt;= 100</code></li>
<li><code>s</code> consists only of digits.</li>
</ul>

@ -0,0 +1,61 @@
<p>You are given two integers <code>red</code> and <code>blue</code> representing the count of red and blue colored balls. You have to arrange these balls to form a triangle such that the 1<sup>st</sup> row will have 1 ball, the 2<sup>nd</sup> row will have 2 balls, the 3<sup>rd</sup> row will have 3 balls, and so on.</p>
<p>All the balls in a particular row should be the <strong>same</strong> color, and adjacent rows should have <strong>different</strong> colors.</p>
<p>Return the <strong>maximum</strong><em> height of the triangle</em> that can be achieved.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">red = 2, blue = 4</span></p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/16/brb.png" style="width: 300px; height: 240px; padding: 10px;" /></p>
<p>The only possible arrangement is shown above.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">red = 2, blue = 1</span></p>
<p><strong>Output:</strong> <span class="example-io">2</span></p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/16/br.png" style="width: 150px; height: 135px; padding: 10px;" /><br />
The only possible arrangement is shown above.</p>
</div>
<p><strong class="example">Example 3:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">red = 1, blue = 1</span></p>
<p><strong>Output:</strong> <span class="example-io">1</span></p>
</div>
<p><strong class="example">Example 4:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">red = 10, blue = 1</span></p>
<p><strong>Output:</strong> <span class="example-io">2</span></p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/16/br.png" style="width: 150px; height: 135px; padding: 10px;" /><br />
The only possible arrangement is shown above.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= red, blue &lt;= 100</code></li>
</ul>

@ -0,0 +1,67 @@
<p>You are given an integer array <code>enemyEnergies</code> denoting the energy values of various enemies.</p>
<p>You are also given an integer <code>currentEnergy</code> denoting the amount of energy you have initially.</p>
<p>You start with 0 points, and all the enemies are unmarked initially.</p>
<p>You can perform <strong>either</strong> of the following operations <strong>zero </strong>or multiple times to gain points:</p>
<ul>
<li>Choose an <strong>unmarked</strong> enemy, <code>i</code>, such that <code>currentEnergy &gt;= enemyEnergies[i]</code>. By choosing this option:
<ul>
<li>You gain 1 point.</li>
<li>Your energy is reduced by the enemy&#39;s energy, i.e. <code>currentEnergy = currentEnergy - enemyEnergies[i]</code>.</li>
</ul>
</li>
<li>If you have <strong>at least</strong> 1 point, you can choose an <strong>unmarked</strong> enemy, <code>i</code>. By choosing this option:
<ul>
<li>Your energy increases by the enemy&#39;s energy, i.e. <code>currentEnergy = currentEnergy + enemyEnergies[i]</code>.</li>
<li>The <font face="monospace">e</font>nemy <code>i</code> is <strong>marked</strong>.</li>
</ul>
</li>
</ul>
<p>Return an integer denoting the <strong>maximum</strong> points you can get in the end by optimally performing operations.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">enemyEnergies = [3,2,2], currentEnergy = 2</span></p>
<p><strong>Output:</strong> <span class="example-io">3</span></p>
<p><strong>Explanation:</strong></p>
<p>The following operations can be performed to get 3 points, which is the maximum:</p>
<ul>
<li>First operation on enemy 1: <code>points</code> increases by 1, and <code>currentEnergy</code> decreases by 2. So, <code>points = 1</code>, and <code>currentEnergy = 0</code>.</li>
<li>Second operation on enemy 0: <code>currentEnergy</code> increases by 3, and enemy 0 is marked. So, <code>points = 1</code>, <code>currentEnergy = 3</code>, and marked enemies = <code>[0]</code>.</li>
<li>First operation on enemy 2: <code>points</code> increases by 1, and <code>currentEnergy</code> decreases by 2. So, <code>points = 2</code>, <code>currentEnergy = 1</code>, and marked enemies = <code>[0]</code>.</li>
<li>Second operation on enemy 2: <code>currentEnergy</code> increases by 2, and enemy 2 is marked. So, <code>points = 2</code>, <code>currentEnergy = 3</code>, and marked enemies = <code>[0, 2]</code>.</li>
<li>First operation on enemy 1: <code>points</code> increases by 1, and <code>currentEnergy</code> decreases by 2. So, <code>points = 3</code>, <code>currentEnergy = 1</code>, and marked enemies = <code>[0, 2]</code>.</li>
</ul>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">enemyEnergies = </span>[2]<span class="example-io">, currentEnergy = 10</span></p>
<p><strong>Output:</strong> <span class="example-io">5</span></p>
<p><strong>Explanation: </strong></p>
<p>Performing the first operation 5 times on enemy 0 results in the maximum number of points.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= enemyEnergies.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= enemyEnergies[i] &lt;= 10<sup>9</sup></code></li>
<li><code>0 &lt;= currentEnergy &lt;= 10<sup>9</sup></code></li>
</ul>

@ -0,0 +1,72 @@
<p>There is an <code>m x n</code> cake that needs to be cut into <code>1 x 1</code> pieces.</p>
<p>You are given integers <code>m</code>, <code>n</code>, and two arrays:</p>
<ul>
<li><code>horizontalCut</code> of size <code>m - 1</code>, where <code>horizontalCut[i]</code> represents the cost to cut along the horizontal line <code>i</code>.</li>
<li><code>verticalCut</code> of size <code>n - 1</code>, where <code>verticalCut[j]</code> represents the cost to cut along the vertical line <code>j</code>.</li>
</ul>
<p>In one operation, you can choose any piece of cake that is not yet a <code>1 x 1</code> square and perform one of the following cuts:</p>
<ol>
<li>Cut along a horizontal line <code>i</code> at a cost of <code>horizontalCut[i]</code>.</li>
<li>Cut along a vertical line <code>j</code> at a cost of <code>verticalCut[j]</code>.</li>
</ol>
<p>After the cut, the piece of cake is divided into two distinct pieces.</p>
<p>The cost of a cut depends only on the initial cost of the line and does not change.</p>
<p>Return the <strong>minimum</strong> total cost to cut the entire cake into <code>1 x 1</code> pieces.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">m = 3, n = 2, horizontalCut = [1,3], verticalCut = [5]</span></p>
<p><strong>Output:</strong> <span class="example-io">13</span></p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/04/ezgifcom-animated-gif-maker-1.gif" style="width: 280px; height: 320px;" /></p>
<ul>
<li>Perform a cut on the vertical line 0 with cost 5, current total cost is 5.</li>
<li>Perform a cut on the horizontal line 0 on <code>3 x 1</code> subgrid with cost 1.</li>
<li>Perform a cut on the horizontal line 0 on <code>3 x 1</code> subgrid with cost 1.</li>
<li>Perform a cut on the horizontal line 1 on <code>2 x 1</code> subgrid with cost 3.</li>
<li>Perform a cut on the horizontal line 1 on <code>2 x 1</code> subgrid with cost 3.</li>
</ul>
<p>The total cost is <code>5 + 1 + 1 + 3 + 3 = 13</code>.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">m = 2, n = 2, horizontalCut = [7], verticalCut = [4]</span></p>
<p><strong>Output:</strong> <span class="example-io">15</span></p>
<p><strong>Explanation:</strong></p>
<ul>
<li>Perform a cut on the horizontal line 0 with cost 7.</li>
<li>Perform a cut on the vertical line 0 on <code>1 x 2</code> subgrid with cost 4.</li>
<li>Perform a cut on the vertical line 0 on <code>1 x 2</code> subgrid with cost 4.</li>
</ul>
<p>The total cost is <code>7 + 4 + 4 = 15</code>.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= m, n &lt;= 20</code></li>
<li><code>horizontalCut.length == m - 1</code></li>
<li><code>verticalCut.length == n - 1</code></li>
<li><code>1 &lt;= horizontalCut[i], verticalCut[i] &lt;= 10<sup>3</sup></code></li>
</ul>

@ -0,0 +1,72 @@
<p>There is an <code>m x n</code> cake that needs to be cut into <code>1 x 1</code> pieces.</p>
<p>You are given integers <code>m</code>, <code>n</code>, and two arrays:</p>
<ul>
<li><code>horizontalCut</code> of size <code>m - 1</code>, where <code>horizontalCut[i]</code> represents the cost to cut along the horizontal line <code>i</code>.</li>
<li><code>verticalCut</code> of size <code>n - 1</code>, where <code>verticalCut[j]</code> represents the cost to cut along the vertical line <code>j</code>.</li>
</ul>
<p>In one operation, you can choose any piece of cake that is not yet a <code>1 x 1</code> square and perform one of the following cuts:</p>
<ol>
<li>Cut along a horizontal line <code>i</code> at a cost of <code>horizontalCut[i]</code>.</li>
<li>Cut along a vertical line <code>j</code> at a cost of <code>verticalCut[j]</code>.</li>
</ol>
<p>After the cut, the piece of cake is divided into two distinct pieces.</p>
<p>The cost of a cut depends only on the initial cost of the line and does not change.</p>
<p>Return the <strong>minimum</strong> total cost to cut the entire cake into <code>1 x 1</code> pieces.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">m = 3, n = 2, horizontalCut = [1,3], verticalCut = [5]</span></p>
<p><strong>Output:</strong> <span class="example-io">13</span></p>
<p><strong>Explanation:</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/06/04/ezgifcom-animated-gif-maker-1.gif" style="width: 280px; height: 320px;" /></p>
<ul>
<li>Perform a cut on the vertical line 0 with cost 5, current total cost is 5.</li>
<li>Perform a cut on the horizontal line 0 on <code>3 x 1</code> subgrid with cost 1.</li>
<li>Perform a cut on the horizontal line 0 on <code>3 x 1</code> subgrid with cost 1.</li>
<li>Perform a cut on the horizontal line 1 on <code>2 x 1</code> subgrid with cost 3.</li>
<li>Perform a cut on the horizontal line 1 on <code>2 x 1</code> subgrid with cost 3.</li>
</ul>
<p>The total cost is <code>5 + 1 + 1 + 3 + 3 = 13</code>.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">m = 2, n = 2, horizontalCut = [7], verticalCut = [4]</span></p>
<p><strong>Output:</strong> <span class="example-io">15</span></p>
<p><strong>Explanation:</strong></p>
<ul>
<li>Perform a cut on the horizontal line 0 with cost 7.</li>
<li>Perform a cut on the vertical line 0 on <code>1 x 2</code> subgrid with cost 4.</li>
<li>Perform a cut on the vertical line 0 on <code>1 x 2</code> subgrid with cost 4.</li>
</ul>
<p>The total cost is <code>7 + 4 + 4 = 15</code>.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= m, n &lt;= 10<sup>5</sup></code></li>
<li><code>horizontalCut.length == m - 1</code></li>
<li><code>verticalCut.length == n - 1</code></li>
<li><code>1 &lt;= horizontalCut[i], verticalCut[i] &lt;= 10<sup>3</sup></code></li>
</ul>

@ -0,0 +1,46 @@
<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</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,1,1], k = 1</span></p>
<p><strong>Output:</strong> <span class="example-io">6</span></p>
<p><strong>Explanation:</strong></p>
<p>All subarrays contain only 1&#39;s.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [1,1,2], k = 1</span></p>
<p><strong>Output:</strong> <span class="example-io">3</span></p>
<p><strong>Explanation:</strong></p>
<p>Subarrays having an <code>AND</code> value of 1 are: <code>[<u><strong>1</strong></u>,1,2]</code>, <code>[1,<u><strong>1</strong></u>,2]</code>, <code>[<u><strong>1,1</strong></u>,2]</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,3], k = 2</span></p>
<p><strong>Output:</strong> <span class="example-io">2</span></p>
<p><strong>Explanation:</strong></p>
<p>Subarrays having an <code>AND</code> value of 2 are: <code>[1,<b><u>2</u></b>,3]</code>, <code>[1,<u><strong>2,3</strong></u>]</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>0 &lt;= nums[i], k &lt;= 10<sup>9</sup></code></li>
</ul>