mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
update
This commit is contained in:
parent
59e97714b1
commit
a8fcd060a2
@ -1,6 +1,6 @@
|
|||||||
# 力扣题库(完整版)
|
# 力扣题库(完整版)
|
||||||
|
|
||||||
> 最后更新日期: **2024.04.30**
|
> 最后更新日期: **2024.05.16**
|
||||||
>
|
>
|
||||||
> 使用脚本前请务必仔细完整阅读本 `README.md` 文件
|
> 使用脚本前请务必仔细完整阅读本 `README.md` 文件
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,61 @@
|
|||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"question": {
|
||||||
|
"questionId": "3448",
|
||||||
|
"questionFrontendId": "3140",
|
||||||
|
"categoryTitle": "Database",
|
||||||
|
"boundTopicId": 2766869,
|
||||||
|
"title": "Consecutive Available Seats II",
|
||||||
|
"titleSlug": "consecutive-available-seats-ii",
|
||||||
|
"content": null,
|
||||||
|
"translatedTitle": "连续空余座位 II",
|
||||||
|
"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\": \"51\", \"totalSubmission\": \"80\", \"totalAcceptedRaw\": 51, \"totalSubmissionRaw\": 80, \"acRate\": \"63.7%\"}",
|
||||||
|
"hints": [],
|
||||||
|
"solution": null,
|
||||||
|
"status": null,
|
||||||
|
"sampleTestCase": "{\"headers\":{\"Cinema\":[\"seat_id\",\"free\"]},\"rows\":{\"Cinema\":[[1,1],[2,0],[3,1],[4,1],[5,1]]}}",
|
||||||
|
"metaData": "{\"mysql\":[\"CREATE TABLE if Not exists Cinema (\\n seat_id INT PRIMARY KEY AUTO_INCREMENT,\\n free BOOLEAN\\n)\\n\"],\"mssql\":[\"Create table Cinema (seat_id int primary key, free BIT)\\n\"],\"oraclesql\":[\"CREATE TABLE Cinema (\\n seat_id INT PRIMARY KEY,\\n free NUMBER(1,0)\\n)\\n\"],\"database\":true,\"name\":\"consecutive_available_seats\",\"postgresql\":[\"CREATE TABLE Cinema (\\n seat_id INT PRIMARY KEY,\\n free INT CHECK (free IN (0, 1))\\n);\"],\"pythondata\":[\"Cinema = pd.DataFrame({'seat_id': pd.Series(dtype='int'), 'free': pd.Series(dtype='bool')})\"],\"database_schema\":{\"Cinema\":{\"seat_id\":\"INT\",\"free\":\"BOOLEAN\"}}}",
|
||||||
|
"judgerAvailable": true,
|
||||||
|
"judgeType": "large",
|
||||||
|
"mysqlSchemas": [
|
||||||
|
"CREATE TABLE if Not exists Cinema (\n seat_id INT PRIMARY KEY AUTO_INCREMENT,\n free BOOLEAN\n)\n",
|
||||||
|
"Truncate table Cinema",
|
||||||
|
"insert into Cinema (seat_id, free) values ('1', '1')",
|
||||||
|
"insert into Cinema (seat_id, free) values ('2', '0')",
|
||||||
|
"insert into Cinema (seat_id, free) values ('3', '1')",
|
||||||
|
"insert into Cinema (seat_id, free) values ('4', '1')",
|
||||||
|
"insert into Cinema (seat_id, free) values ('5', '1')"
|
||||||
|
],
|
||||||
|
"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\":{\"Cinema\":[\"seat_id\",\"free\"]},\"rows\":{\"Cinema\":[[1,1],[2,0],[3,1],[4,1],[5,1]]}}",
|
||||||
|
"__typename": "QuestionNode"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
72
leetcode-cn/originData/[no content]invalid-tweets-ii.json
Normal file
72
leetcode-cn/originData/[no content]invalid-tweets-ii.json
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"question": {
|
||||||
|
"questionId": "3457",
|
||||||
|
"questionFrontendId": "3150",
|
||||||
|
"categoryTitle": "Database",
|
||||||
|
"boundTopicId": 2775397,
|
||||||
|
"title": "Invalid Tweets II",
|
||||||
|
"titleSlug": "invalid-tweets-ii",
|
||||||
|
"content": null,
|
||||||
|
"translatedTitle": "无效的推文 II",
|
||||||
|
"translatedContent": null,
|
||||||
|
"isPaidOnly": true,
|
||||||
|
"difficulty": "Easy",
|
||||||
|
"likes": 0,
|
||||||
|
"dislikes": 0,
|
||||||
|
"isLiked": null,
|
||||||
|
"similarQuestions": "[]",
|
||||||
|
"contributors": [],
|
||||||
|
"langToValidPlayground": null,
|
||||||
|
"topicTags": [
|
||||||
|
{
|
||||||
|
"name": "Database",
|
||||||
|
"slug": "database",
|
||||||
|
"translatedName": "数据库",
|
||||||
|
"__typename": "TopicTagNode"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"companyTagStats": null,
|
||||||
|
"codeSnippets": null,
|
||||||
|
"stats": "{\"totalAccepted\": \"43\", \"totalSubmission\": \"51\", \"totalAcceptedRaw\": 43, \"totalSubmissionRaw\": 51, \"acRate\": \"84.3%\"}",
|
||||||
|
"hints": [],
|
||||||
|
"solution": null,
|
||||||
|
"status": null,
|
||||||
|
"sampleTestCase": "{\"headers\": {\"Tweets\": [\"tweet_id\", \"content\"]}, \"rows\": {\"Tweets\": [[1, \"What an amazing meal @MaxPower @AlexJones @JohnDoe #Learning #Fitness #Love\"], [2, \"Learning something new every day @AnnaWilson #Learning #Foodie\"], [3, \"Never been happier about today's achievements @SaraJohnson @JohnDoe @AnnaWilson #Fashion\"], [4, \"Traveling, exploring, and living my best life @JaneSmith @JohnDoe @ChrisAnderson @AlexJones #WorkLife #Travel\"], [5, \"Work hard, play hard, and cherish every moment @AlexJones #Fashion #Foodie\"], [6, \"Never been happier about today's achievements @ChrisAnderson #Fashion #WorkLife\"], [7, \"So grateful for today's experiences @AnnaWilson @LisaTaylor @ChrisAnderson @MikeBrown #Fashion #HappyDay #WorkLife #Nature\"], [8, \"What an amazing meal @EmilyClark @AlexJones @MikeBrown #Fitness\"], [9, \"Learning something new every day @EmilyClark @AnnaWilson @MaxPower #Travel\"], [10, \"So grateful for today's experiences @ChrisAnderson #Nature\"], [11, \"So grateful for today's experiences @AlexJones #Art #WorkLife\"], [12, \"Learning something new every day @JaneSmith @MikeBrown #Travel\"], [13, \"What an amazing meal @EmilyClark @JohnDoe @LisaTaylor @MaxPower #Foodie #Fitness\"], [14, \"Work hard, play hard, and cherish every moment @LisaTaylor @SaraJohnson @MaxPower @ChrisAnderson #TechLife #Nature #Music\"], [15, \"What a beautiful day it is @EmilyClark @MaxPower @SaraJohnson #Fashion\"], [16, \"What a beautiful day it is @AnnaWilson @JaneSmith #Fashion #Love #TechLife\"]]}}",
|
||||||
|
"metaData": "{\"mysql\":[\"Create table If Not Exists Tweets(tweet_id int, content varchar(500))\"],\"mssql\":[\"Create table Tweets(tweet_id int, content varchar(500))\"],\"oraclesql\":[\"Create table Tweets(tweet_id int, content varchar(500))\"],\"database\":true,\"name\":\"find_invalid_tweets\",\"pythondata\":[\"Tweets = pd.DataFrame([], columns=['tweet_id', 'content']).astype({'tweet_id':'Int64', 'content':'object'})\"],\"postgresql\":[\"Create table If Not Exists Tweets(tweet_id int, content varchar(500))\"],\"database_schema\":{\"Tweets\":{\"tweet_id\":\"INT\",\"content\":\"VARCHAR(500)\"}}}",
|
||||||
|
"judgerAvailable": true,
|
||||||
|
"judgeType": "large",
|
||||||
|
"mysqlSchemas": [
|
||||||
|
"Create table If Not Exists Tweets(tweet_id int, content varchar(500))",
|
||||||
|
"Truncate table Tweets",
|
||||||
|
"insert into Tweets (tweet_id, content) values ('1', 'What an amazing meal @MaxPower @AlexJones @JohnDoe #Learning #Fitness #Love')",
|
||||||
|
"insert into Tweets (tweet_id, content) values ('2', 'Learning something new every day @AnnaWilson #Learning #Foodie')",
|
||||||
|
"insert into Tweets (tweet_id, content) values ('3', 'Never been happier about today's achievements @SaraJohnson @JohnDoe @AnnaWilson #Fashion')",
|
||||||
|
"insert into Tweets (tweet_id, content) values ('4', 'Traveling, exploring, and living my best life @JaneSmith @JohnDoe @ChrisAnderson @AlexJones #WorkLife #Travel')",
|
||||||
|
"insert into Tweets (tweet_id, content) values ('5', 'Work hard, play hard, and cherish every moment @AlexJones #Fashion #Foodie')",
|
||||||
|
"insert into Tweets (tweet_id, content) values ('6', 'Never been happier about today's achievements @ChrisAnderson #Fashion #WorkLife')",
|
||||||
|
"insert into Tweets (tweet_id, content) values ('7', 'So grateful for today's experiences @AnnaWilson @LisaTaylor @ChrisAnderson @MikeBrown #Fashion #HappyDay #WorkLife #Nature')",
|
||||||
|
"insert into Tweets (tweet_id, content) values ('8', 'What an amazing meal @EmilyClark @AlexJones @MikeBrown #Fitness')",
|
||||||
|
"insert into Tweets (tweet_id, content) values ('9', 'Learning something new every day @EmilyClark @AnnaWilson @MaxPower #Travel')",
|
||||||
|
"insert into Tweets (tweet_id, content) values ('10', 'So grateful for today's experiences @ChrisAnderson #Nature')",
|
||||||
|
"insert into Tweets (tweet_id, content) values ('11', 'So grateful for today's experiences @AlexJones #Art #WorkLife')",
|
||||||
|
"insert into Tweets (tweet_id, content) values ('12', 'Learning something new every day @JaneSmith @MikeBrown #Travel')",
|
||||||
|
"insert into Tweets (tweet_id, content) values ('13', 'What an amazing meal @EmilyClark @JohnDoe @LisaTaylor @MaxPower #Foodie #Fitness')",
|
||||||
|
"insert into Tweets (tweet_id, content) values ('14', 'Work hard, play hard, and cherish every moment @LisaTaylor @SaraJohnson @MaxPower @ChrisAnderson #TechLife #Nature #Music')",
|
||||||
|
"insert into Tweets (tweet_id, content) values ('15', 'What a beautiful day it is @EmilyClark @MaxPower @SaraJohnson #Fashion')",
|
||||||
|
"insert into Tweets (tweet_id, content) values ('16', 'What a beautiful day it is @AnnaWilson @JaneSmith #Fashion #Love #TechLife')"
|
||||||
|
],
|
||||||
|
"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\": {\"Tweets\": [\"tweet_id\", \"content\"]}, \"rows\": {\"Tweets\": [[1, \"What an amazing meal @MaxPower @AlexJones @JohnDoe #Learning #Fitness #Love\"], [2, \"Learning something new every day @AnnaWilson #Learning #Foodie\"], [3, \"Never been happier about today's achievements @SaraJohnson @JohnDoe @AnnaWilson #Fashion\"], [4, \"Traveling, exploring, and living my best life @JaneSmith @JohnDoe @ChrisAnderson @AlexJones #WorkLife #Travel\"], [5, \"Work hard, play hard, and cherish every moment @AlexJones #Fashion #Foodie\"], [6, \"Never been happier about today's achievements @ChrisAnderson #Fashion #WorkLife\"], [7, \"So grateful for today's experiences @AnnaWilson @LisaTaylor @ChrisAnderson @MikeBrown #Fashion #HappyDay #WorkLife #Nature\"], [8, \"What an amazing meal @EmilyClark @AlexJones @MikeBrown #Fitness\"], [9, \"Learning something new every day @EmilyClark @AnnaWilson @MaxPower #Travel\"], [10, \"So grateful for today's experiences @ChrisAnderson #Nature\"], [11, \"So grateful for today's experiences @AlexJones #Art #WorkLife\"], [12, \"Learning something new every day @JaneSmith @MikeBrown #Travel\"], [13, \"What an amazing meal @EmilyClark @JohnDoe @LisaTaylor @MaxPower #Foodie #Fitness\"], [14, \"Work hard, play hard, and cherish every moment @LisaTaylor @SaraJohnson @MaxPower @ChrisAnderson #TechLife #Nature #Music\"], [15, \"What a beautiful day it is @EmilyClark @MaxPower @SaraJohnson #Fashion\"], [16, \"What a beautiful day it is @AnnaWilson @JaneSmith #Fashion #Love #TechLife\"]]}}",
|
||||||
|
"__typename": "QuestionNode"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
177
leetcode-cn/originData/check-if-grid-satisfies-conditions.json
Normal file
177
leetcode-cn/originData/check-if-grid-satisfies-conditions.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
183
leetcode-cn/originData/maximum-difference-score-in-a-grid.json
Normal file
183
leetcode-cn/originData/maximum-difference-score-in-a-grid.json
Normal file
File diff suppressed because one or more lines are too long
195
leetcode-cn/originData/maximum-points-inside-the-square.json
Normal file
195
leetcode-cn/originData/maximum-points-inside-the-square.json
Normal file
File diff suppressed because one or more lines are too long
186
leetcode-cn/originData/minimum-cost-to-equalize-array.json
Normal file
186
leetcode-cn/originData/minimum-cost-to-equalize-array.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
170
leetcode-cn/originData/valid-word.json
Normal file
170
leetcode-cn/originData/valid-word.json
Normal file
File diff suppressed because one or more lines are too long
@ -0,0 +1,92 @@
|
|||||||
|
<p>给你一个长度为 <code>n</code> 的字符串 <code>word</code> 和一个整数 <code>k</code> ,其中 <code>k</code> 是 <code>n</code> 的因数。</p>
|
||||||
|
|
||||||
|
<p>在一次操作中,你可以选择任意两个下标 <code>i</code> 和 <code>j</code>,其中 <code>0 <= i, j < n</code> ,且这两个下标都可以被 <code>k</code> 整除,然后用从 <code>j</code> 开始的长度为 <code>k</code> 的子串替换从 <code>i</code> 开始的长度为 <code>k</code> 的子串。也就是说,将子串 <code>word[i..i + k - 1]</code> 替换为子串 <code>word[j..j + k - 1]</code> 。</p>
|
||||||
|
|
||||||
|
<p>返回使 <code>word</code> 成为 <strong>K 周期字符串</strong> 所需的<strong> 最少</strong> 操作次数。</p>
|
||||||
|
|
||||||
|
<p>如果存在某个长度为 <code>k</code> 的字符串 <code>s</code>,使得 <code>word</code> 可以表示为任意次数连接 <code>s</code> ,则称字符串 <code>word</code> 是 <strong>K 周期字符串</strong> 。例如,如果 <code>word == "ababab"</code>,那么 <code>word</code> 就是 <code>s = "ab"</code> 时的 2 周期字符串 。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong class="example">示例 1:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block" style="
|
||||||
|
border-color: var(--border-tertiary);
|
||||||
|
border-left-width: 2px;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
font-size: .875rem;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
margin-top: 1rem;
|
||||||
|
overflow: visible;
|
||||||
|
padding-left: 1rem;
|
||||||
|
">
|
||||||
|
<p><strong>输入:</strong><span class="example-io" style="
|
||||||
|
font-family: Menlo,sans-serif;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
">word = "leetcodeleet", k = 4</span></p>
|
||||||
|
|
||||||
|
<p><strong>输出:</strong><span class="example-io" style="
|
||||||
|
font-family: Menlo,sans-serif;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
">1</span></p>
|
||||||
|
|
||||||
|
<p><strong>解释:</strong>可以选择 i = 4 和 j = 0 获得一个 4 周期字符串。这次操作后,word 变为 "leetleetleet" 。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><strong class="example">示例 2:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block" style="
|
||||||
|
border-color: var(--border-tertiary);
|
||||||
|
border-left-width: 2px;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
font-size: .875rem;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
margin-top: 1rem;
|
||||||
|
overflow: visible;
|
||||||
|
padding-left: 1rem;
|
||||||
|
">
|
||||||
|
<p><strong>输入:</strong><span class="example-io" style="
|
||||||
|
font-family: Menlo,sans-serif;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
">word = "leetcoleet", k = 2</span></p>
|
||||||
|
|
||||||
|
<p><strong>输出:</strong>3</p>
|
||||||
|
|
||||||
|
<p><strong>解释:</strong>可以执行以下操作获得一个 2 周期字符串。</p>
|
||||||
|
|
||||||
|
<table border="1" bordercolor="#ccc" cellpadding="5" cellspacing="0" height="146" style="border-collapse:collapse; text-align: center; vertical-align: middle;">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th>i</th>
|
||||||
|
<th>j</th>
|
||||||
|
<th>word</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td style="padding: 5px 15px;">0</td>
|
||||||
|
<td style="padding: 5px 15px;">2</td>
|
||||||
|
<td style="padding: 5px 15px;">etetcoleet</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td style="padding: 5px 15px;">4</td>
|
||||||
|
<td style="padding: 5px 15px;">0</td>
|
||||||
|
<td style="padding: 5px 15px;">etetetleet</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td style="padding: 5px 15px;">6</td>
|
||||||
|
<td style="padding: 5px 15px;">0</td>
|
||||||
|
<td style="padding: 5px 15px;">etetetetet</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= n == word.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>1 <= k <= word.length</code></li>
|
||||||
|
<li><code>k</code> 能整除 <code>word.length</code> 。</li>
|
||||||
|
<li><code>word</code> 仅由小写英文字母组成。</li>
|
||||||
|
</ul>
|
@ -0,0 +1,48 @@
|
|||||||
|
<p>给你两个字符串 <code>s</code> 和 <code>t</code>,每个字符串中的字符都不重复,且 <code>t</code> 是 <code>s</code> 的一个排列。</p>
|
||||||
|
|
||||||
|
<p><strong>排列差</strong> 定义为 <code>s</code> 和 <code>t</code> 中每个字符在两个字符串中位置的绝对差值之和。</p>
|
||||||
|
|
||||||
|
<p>返回 <code>s</code> 和 <code>t</code> 之间的<strong> 排列差 </strong>。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong class="example">示例 1:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>输入:</strong><span class="example-io">s = "abc", t = "bac"</span></p>
|
||||||
|
|
||||||
|
<p><strong>输出:</strong><span class="example-io">2</span></p>
|
||||||
|
|
||||||
|
<p><strong>解释:</strong></p>
|
||||||
|
|
||||||
|
<p>对于 <code>s = "abc"</code> 和 <code>t = "bac"</code>,排列差是:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>"a"</code> 在 <code>s</code> 中的位置与在 <code>t</code> 中的位置之差的绝对值。</li>
|
||||||
|
<li><code>"b"</code> 在 <code>s</code> 中的位置与在 <code>t</code> 中的位置之差的绝对值。</li>
|
||||||
|
<li><code>"c"</code> 在 <code>s</code> 中的位置与在 <code>t</code> 中的位置之差的绝对值。</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>即,<code>s</code> 和 <code>t</code> 的排列差等于 <code>|0 - 1| + |2 - 2| + |1 - 0| = 2</code>。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><strong class="example">示例 2:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>输入:</strong><span class="example-io">s = "abcde", t = "edbac"</span></p>
|
||||||
|
|
||||||
|
<p><strong>输出:</strong><span class="example-io">12</span></p>
|
||||||
|
|
||||||
|
<p><strong>解释:</strong> <code>s</code> 和 <code>t</code> 的排列差等于 <code>|0 - 3| + |1 - 2| + |2 - 4| + |3 - 1| + |4 - 0| = 12</code>。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= s.length <= 26</code></li>
|
||||||
|
<li>每个字符在 <code>s</code> 中最多出现一次。</li>
|
||||||
|
<li><code>t</code> 是 <code>s</code> 的一个排列。</li>
|
||||||
|
<li><code>s</code> 仅由小写英文字母组成。</li>
|
||||||
|
</ul>
|
@ -0,0 +1,71 @@
|
|||||||
|
<p>在神秘的地牢中,<code>n</code> 个魔法师站成一排。每个魔法师都拥有一个属性,这个属性可以给你提供能量。有些魔法师可能会给你负能量,即从你身上吸取能量。</p>
|
||||||
|
|
||||||
|
<p>你被施加了一种诅咒,当你从魔法师 <code>i</code> 处吸收能量后,你将被立即传送到魔法师 <code>(i + k)</code> 处。这一过程将重复进行,直到你到达一个不存在 <code>(i + k)</code> 的魔法师为止。</p>
|
||||||
|
|
||||||
|
<p>换句话说,你将选择一个起点,然后以 <code>k</code> 为间隔跳跃,直到到达魔法师序列的末端,<strong>在过程中吸收所有的能量</strong>。</p>
|
||||||
|
|
||||||
|
<p>给定一个数组 <code>energy</code> 和一个整数<code>k</code>,返回你能获得的<strong> 最大 </strong>能量。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong class="example">示例 1:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block" style="
|
||||||
|
border-color: var(--border-tertiary);
|
||||||
|
border-left-width: 2px;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
font-size: .875rem;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
margin-top: 1rem;
|
||||||
|
overflow: visible;
|
||||||
|
padding-left: 1rem;
|
||||||
|
">
|
||||||
|
<p><strong>输入:</strong><span class="example-io" style="
|
||||||
|
font-family: Menlo,sans-serif;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
"> energy = [5,2,-10,-5,1], k = 3</span></p>
|
||||||
|
|
||||||
|
<p><strong>输出:</strong><span class="example-io" style="
|
||||||
|
font-family: Menlo,sans-serif;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
"> 3</span></p>
|
||||||
|
|
||||||
|
<p><strong>解释:</strong>可以从魔法师 1 开始,吸收能量 2 + 1 = 3。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><strong class="example">示例 2:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block" style="
|
||||||
|
border-color: var(--border-tertiary);
|
||||||
|
border-left-width: 2px;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
font-size: .875rem;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
margin-top: 1rem;
|
||||||
|
overflow: visible;
|
||||||
|
padding-left: 1rem;
|
||||||
|
">
|
||||||
|
<p><strong>输入:</strong><span class="example-io" style="
|
||||||
|
font-family: Menlo,sans-serif;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
"> energy = [-2,-3,-1], k = 2</span></p>
|
||||||
|
|
||||||
|
<p><strong>输出:</strong><span class="example-io" style="
|
||||||
|
font-family: Menlo,sans-serif;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
"> -1</span></p>
|
||||||
|
|
||||||
|
<p><strong>解释:</strong>可以从魔法师 2 开始,吸收能量 -1。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= energy.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>-1000 <= energy[i] <= 1000</code></li>
|
||||||
|
<li><code>1 <= k <= energy.length - 1</code></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p> </p>
|
@ -0,0 +1,86 @@
|
|||||||
|
<p>给你一个整数数组 <code>nums</code> 和两个整数 <code>cost1</code> 和 <code>cost2</code> 。你可以执行以下 <strong>任一</strong> 操作 <strong>任意</strong> 次:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>从 <code>nums</code> 中选择下标 <code>i</code> 并且将 <code>nums[i]</code> <strong>增加</strong> <code>1</code> ,开销为 <code>cost1</code>。</li>
|
||||||
|
<li>选择 <code>nums</code> 中两个 <strong>不同</strong> 下标 <code>i</code> 和 <code>j</code> ,并且将 <code>nums[i]</code> 和 <code>nums[j]</code> 都 <strong>增加</strong> <code>1</code> ,开销为 <code>cost2</code> 。</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>你的目标是使数组中所有元素都 <strong>相等</strong> ,请你返回需要的 <strong>最小开销</strong> 之和。</p>
|
||||||
|
|
||||||
|
<p>由于答案可能会很大,请你将它对 <code>10<sup>9</sup> + 7</code> <strong>取余</strong> 后返回。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong class="example">示例 1:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><span class="example-io"><b>输入:</b>nums = [4,1], cost1 = 5, cost2 = 2</span></p>
|
||||||
|
|
||||||
|
<p><span class="example-io"><b>输出:</b>15</span></p>
|
||||||
|
|
||||||
|
<p><strong>解释:</strong></p>
|
||||||
|
|
||||||
|
<p>执行以下操作可以使数组中所有元素相等:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>将 <code>nums[1]</code> 增加 1 ,开销为 5 ,<code>nums</code> 变为 <code>[4,2]</code> 。</li>
|
||||||
|
<li>将 <code>nums[1]</code> 增加 1 ,开销为 5 ,<code>nums</code> 变为 <code>[4,3]</code> 。</li>
|
||||||
|
<li>将 <code>nums[1]</code> 增加 1 ,开销为 5 ,<code>nums</code> 变为 <code>[4,4]</code> 。</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>总开销为 15 。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><strong class="example">示例 2:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>输入:</strong><span class="example-io">nums = [2,3,3,3,5], cost1 = 2, cost2 = 1</span></p>
|
||||||
|
|
||||||
|
<p><span class="example-io"><b>输出:</b>6</span></p>
|
||||||
|
|
||||||
|
<p><b>解释:</b></p>
|
||||||
|
|
||||||
|
<p>执行以下操作可以使数组中所有元素相等:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>将 <code>nums[0]</code> 和 <code>nums[1]</code> 同时增加 1 ,开销为 1 ,<code>nums</code> 变为 <code>[3,4,3,3,5]</code> 。</li>
|
||||||
|
<li>将 <code>nums[0]</code> 和 <code>nums[2]</code> 同时增加 1 ,开销为 1 ,<code>nums</code> 变为 <code>[4,4,4,3,5]</code> 。</li>
|
||||||
|
<li>将 <code>nums[0]</code> 和 <code>nums[3]</code> 同时增加 1 ,开销为 1 ,<code>nums</code> 变为 <code>[5,4,4,4,5]</code> 。</li>
|
||||||
|
<li>将 <code>nums[1]</code> 和 <code>nums[2]</code> 同时增加 1 ,开销为 1 ,<code>nums</code> 变为 <code>[5,5,5,4,5]</code> 。</li>
|
||||||
|
<li>将 <code>nums[3]</code> 增加 1 ,开销为 2 ,<code>nums</code> 变为 <code>[5,5,5,5,5]</code> 。</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>总开销为 6 。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><strong class="example">示例 3:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><span class="example-io"><b>输入:</b>nums = [3,5,3], cost1 = 1, cost2 = 3</span></p>
|
||||||
|
|
||||||
|
<p><span class="example-io"><b>输出:</b>4</span></p>
|
||||||
|
|
||||||
|
<p><strong>解释:</strong></p>
|
||||||
|
|
||||||
|
<p>执行以下操作可以使数组中所有元素相等:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>将 <code>nums[0]</code> 增加 1 ,开销为 1 ,<code>nums</code> 变为 <code>[4,5,3]</code> 。</li>
|
||||||
|
<li>将 <code>nums[0]</code> 增加 1 ,开销为 1 ,<code>nums</code> 变为 <code>[5,5,3]</code> 。</li>
|
||||||
|
<li>将 <code>nums[2]</code> 增加 1 ,开销为 1 ,<code>nums</code> 变为 <code>[5,5,4]</code> 。</li>
|
||||||
|
<li>将 <code>nums[2]</code> 增加 1 ,开销为 1 ,<code>nums</code> 变为 <code>[5,5,5]</code> 。</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>总开销为 4 。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>1 <= nums[i] <= 10<sup>6</sup></code></li>
|
||||||
|
<li><code>1 <= cost1 <= 10<sup>6</sup></code></li>
|
||||||
|
<li><code>1 <= cost2 <= 10<sup>6</sup></code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,40 @@
|
|||||||
|
<p>给你一个字符串 <code>s</code> ,你需要将它分割成一个或者更多的 <strong>平衡</strong> 子字符串。比方说,<code>s == "ababcc"</code> 那么 <code>("abab", "c", "c")</code> ,<code>("ab", "abc", "c")</code> 和 <code>("ababcc")</code> 都是合法分割,但是 <code>("a", <strong>"bab"</strong>, "cc")</code> ,<code>(<strong>"aba"</strong>, "bc", "c")</code> 和 <code>("ab", <strong>"abcc"</strong>)</code> 不是,不平衡的子字符串用粗体表示。</p>
|
||||||
|
|
||||||
|
<p>请你返回 <code>s</code> <strong>最少</strong> 能分割成多少个平衡子字符串。</p>
|
||||||
|
|
||||||
|
<p><b>注意:</b>一个 <strong>平衡</strong> 字符串指的是字符串中所有字符出现的次数都相同。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong class="example">示例 1:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><span class="example-io"><b>输入:</b>s = "fabccddg"</span></p>
|
||||||
|
|
||||||
|
<p><span class="example-io"><b>输出:</b>3</span></p>
|
||||||
|
|
||||||
|
<p><strong>解释:</strong></p>
|
||||||
|
|
||||||
|
<p>我们可以将 <code>s</code> 分割成 3 个子字符串:<code>("fab, "ccdd", "g")</code> 或者 <code>("fabc", "cd", "dg")</code> 。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><strong class="example">示例 2:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><span class="example-io"><b>输入:</b>s = "abababaccddb"</span></p>
|
||||||
|
|
||||||
|
<p><span class="example-io"><b>输出:</b>2</span></p>
|
||||||
|
|
||||||
|
<p><strong>解释:</strong></p>
|
||||||
|
|
||||||
|
<p>我们可以将 <code>s</code> 分割成 2 个子字符串:<code>("abab", "abaccddb")</code> 。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= s.length <= 1000</code></li>
|
||||||
|
<li><code>s</code> 只包含小写英文字母。</li>
|
||||||
|
</ul>
|
@ -0,0 +1,61 @@
|
|||||||
|
<p>给你一个大小为 <code>m x n</code> 的二维矩阵 <code>grid</code> 。你需要判断每一个格子 <code>grid[i][j]</code> 是否满足:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>如果它下面的格子存在,那么它需要等于它下面的格子,也就是 <code>grid[i][j] == grid[i + 1][j]</code> 。</li>
|
||||||
|
<li>如果它右边的格子存在,那么它需要不等于它右边的格子,也就是 <code>grid[i][j] != grid[i][j + 1]</code> 。</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>如果 <strong>所有</strong> 格子都满足以上条件,那么返回 <code>true</code> ,否则返回 <code>false</code> 。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong class="example">示例 1:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><span class="example-io"><b>输入:</b>grid = [[1,0,2],[1,0,2]]</span></p>
|
||||||
|
|
||||||
|
<p><span class="example-io"><b>输出:</b>true</span></p>
|
||||||
|
|
||||||
|
<p><strong>解释:</strong></p>
|
||||||
|
|
||||||
|
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/04/15/examplechanged.png" style="width: 254px; height: 186px;padding: 10px; background: #fff; border-radius: .5rem;" /></strong></p>
|
||||||
|
|
||||||
|
<p>网格图中所有格子都符合条件。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><strong class="example">示例 2:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><span class="example-io"><b>输入:</b>grid = [[1,1,1],[0,0,0]]</span></p>
|
||||||
|
|
||||||
|
<p><span class="example-io"><b>输出:</b>false</span></p>
|
||||||
|
|
||||||
|
<p><b>解释:</b></p>
|
||||||
|
|
||||||
|
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/03/27/example21.png" style="width: 254px; height: 186px;padding: 10px; background: #fff; border-radius: .5rem;" /></strong></p>
|
||||||
|
|
||||||
|
<p>同一行中的格子值都相等。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><strong class="example">示例 3:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><span class="example-io"><b>输入:</b>grid = [[1],[2],[3]]</span></p>
|
||||||
|
|
||||||
|
<p><span class="example-io"><b>输出:</b>false</span></p>
|
||||||
|
|
||||||
|
<p><strong>解释:</strong></p>
|
||||||
|
|
||||||
|
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/03/31/changed.png" style="width: 86px; height: 277px;padding: 10px; background: #fff; border-radius: .5rem;" /></p>
|
||||||
|
|
||||||
|
<p>同一列中的格子值不相等。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= n, m <= 10</code></li>
|
||||||
|
<li><code>0 <= grid[i][j] <= 9</code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,40 @@
|
|||||||
|
<p>给你一个字符串 <code>s</code> ,它由某个字符串 <code>t</code> 和若干 <code>t</code> 的 <strong>同位字符串</strong> 连接而成。</p>
|
||||||
|
|
||||||
|
<p>请你返回字符串 <code>t</code> 的 <strong>最小</strong> 可能长度。</p>
|
||||||
|
|
||||||
|
<p><strong>同位字符串</strong> 指的是重新排列一个单词得到的另外一个字符串,原来字符串中的每个字符在新字符串中都恰好只使用一次。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong class="example">示例 1:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><span class="example-io"><b>输入:</b>s = "abba"</span></p>
|
||||||
|
|
||||||
|
<p><span class="example-io"><b>输出:</b>2</span></p>
|
||||||
|
|
||||||
|
<p><strong>解释:</strong></p>
|
||||||
|
|
||||||
|
<p>一个可能的字符串 <code>t</code> 为 <code>"ba"</code> 。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><strong class="example">示例 2:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><span class="example-io"><b>输入:</b>s = "cdef"</span></p>
|
||||||
|
|
||||||
|
<p><span class="example-io"><b>输出:</b>4</span></p>
|
||||||
|
|
||||||
|
<p><strong>解释:</strong></p>
|
||||||
|
|
||||||
|
<p>一个可能的字符串 <code>t</code> 为 <code>"cdef"</code> ,注意 <code>t</code> 可能等于 <code>s</code> 。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= s.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>s</code> 只包含小写英文字母。</li>
|
||||||
|
</ul>
|
@ -0,0 +1,50 @@
|
|||||||
|
<p>一个整数 <code>x</code> 的 <strong>强数组</strong> 指的是满足和为 <code>x</code> 的二的幂的最短有序数组。比方说,11 的强数组为 <code>[1, 2, 8]</code> 。</p>
|
||||||
|
|
||||||
|
<p>我们将每一个正整数 <code>i</code> (即1,2,3等等)的 <strong>强数组</strong> 连接得到数组 <code>big_nums</code> ,<code>big_nums</code> 开始部分为 <code>[<u>1</u>, <u>2</u>, <u>1, 2</u>, <u>4</u>, <u>1, 4</u>, <u>2, 4</u>, <u>1, 2, 4</u>, <u>8</u>, ...]</code> 。</p>
|
||||||
|
|
||||||
|
<p>给你一个二维整数数组 <code>queries</code> ,其中 <code>queries[i] = [from<sub>i</sub>, to<sub>i</sub>, mod<sub>i</sub>]</code> ,你需要计算 <code>(big_nums[from<sub>i</sub>] * big_nums[from<sub>i</sub> + 1] * ... * big_nums[to<sub>i</sub>]) % mod<sub>i</sub></code> 。</p>
|
||||||
|
|
||||||
|
<p>请你返回一个整数数组 <code>answer</code> ,其中 <code>answer[i]</code> 是第 <code>i</code> 个查询的答案。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong class="example">示例 1:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><span class="example-io"><b>输入:</b>queries = [[1,3,7]]</span></p>
|
||||||
|
|
||||||
|
<p><span class="example-io"><b>输出:</b>[4]</span></p>
|
||||||
|
|
||||||
|
<p><strong>解释:</strong></p>
|
||||||
|
|
||||||
|
<p>只有一个查询。</p>
|
||||||
|
|
||||||
|
<p><code>big_nums[1..3] = [2,1,2]</code> 。它们的乘积为 4 ,4 对 7 取余数得到 4 。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><strong class="example">示例 2:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><span class="example-io"><b>输入:</b>queries = [[2,5,3],[7,7,4]]</span></p>
|
||||||
|
|
||||||
|
<p><span class="example-io"><b>输出:</b>[2,2]</span></p>
|
||||||
|
|
||||||
|
<p><strong>解释:</strong></p>
|
||||||
|
|
||||||
|
<p>有两个查询。</p>
|
||||||
|
|
||||||
|
<p>第一个查询:<code>big_nums[2..5] = [1,2,4,1]</code> 。它们的乘积为 8 ,8 对 3 取余数得到 2 。</p>
|
||||||
|
|
||||||
|
<p>第二个查询:<code>big_nums[7] = 2</code> ,2 对 4 取余数得到 2 。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= queries.length <= 500</code></li>
|
||||||
|
<li><code>queries[i].length == 3</code></li>
|
||||||
|
<li><code>0 <= queries[i][0] <= queries[i][1] <= 10<sup>15</sup></code></li>
|
||||||
|
<li><code>1 <= queries[i][2] <= 10<sup>5</sup></code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,44 @@
|
|||||||
|
<p>给你一个数组 <code>nums</code> ,它是 <code>[0, 1, 2, ..., n - 1]</code> 的一个<span data-keyword="permutation">排列</span> 。对于任意一个 <code>[0, 1, 2, ..., n - 1]</code> 的排列 <code>perm</code> ,其 <strong>分数 </strong>定义为:</p>
|
||||||
|
|
||||||
|
<p><code>score(perm) = |perm[0] - nums[perm[1]]| + |perm[1] - nums[perm[2]]| + ... + |perm[n - 1] - nums[perm[0]]|</code></p>
|
||||||
|
|
||||||
|
<p>返回具有<strong> 最低</strong> 分数的排列 <code>perm</code> 。如果存在多个满足题意且分数相等的排列,则返回其中<span data-keyword="lexicographically-smaller-array">字典序最小</span>的一个。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong class="example">示例 1:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>输入:</strong><span class="example-io">nums = [1,0,2]</span></p>
|
||||||
|
|
||||||
|
<p><strong>输出:</strong><span class="example-io">[0,1,2]</span></p>
|
||||||
|
|
||||||
|
<p><strong>解释:</strong></p>
|
||||||
|
|
||||||
|
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/04/04/example0gif.gif" style="width: 235px; height: 235px;" /></strong></p>
|
||||||
|
|
||||||
|
<p>字典序最小且分数最低的排列是 <code>[0,1,2]</code>。这个排列的分数是 <code>|0 - 0| + |1 - 2| + |2 - 1| = 2</code> 。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><strong class="example">示例 2:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>输入:</strong><span class="example-io">nums = [0,2,1]</span></p>
|
||||||
|
|
||||||
|
<p><strong>输出:</strong><span class="example-io">[0,2,1]</span></p>
|
||||||
|
|
||||||
|
<p><strong>解释:</strong></p>
|
||||||
|
|
||||||
|
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/04/04/example1gif.gif" style="width: 235px; height: 235px;" /></strong></p>
|
||||||
|
|
||||||
|
<p>字典序最小且分数最低的排列是 <code>[0,2,1]</code>。这个排列的分数是 <code>|0 - 1| + |2 - 2| + |1 - 0| = 2</code> 。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>2 <= n == nums.length <= 14</code></li>
|
||||||
|
<li><code>nums</code> 是 <code>[0, 1, 2, ..., n - 1]</code> 的一个排列。</li>
|
||||||
|
</ul>
|
64
leetcode-cn/problem (Chinese)/有效单词 [valid-word].html
Normal file
64
leetcode-cn/problem (Chinese)/有效单词 [valid-word].html
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
<p><strong>有效单词</strong> 需要满足以下几个条件:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><strong>至少 </strong>包含 3 个字符。</li>
|
||||||
|
<li>由数字 0-9 和英文大小写字母组成。(不必包含所有这类字符。)</li>
|
||||||
|
<li><strong>至少</strong> 包含一个 <strong>元音字母 </strong>。</li>
|
||||||
|
<li><strong>至少</strong> 包含一个 <strong>辅音字母 </strong>。</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>给你一个字符串 <code>word</code> 。如果 <code>word</code> 是一个有效单词,则返回 <code>true</code> ,否则返回 <code>false</code> 。</p>
|
||||||
|
|
||||||
|
<p><strong>注意:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>'a'</code>、<code>'e'</code>、<code>'i'</code>、<code>'o'</code>、<code>'u'</code> 及其大写形式都属于<strong> 元音字母 </strong>。</li>
|
||||||
|
<li>英文中的 <strong>辅音字母 </strong>是指那些除元音字母之外的字母。</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong class="example">示例 1:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>输入:</strong><span class="example-io">word = "234Adas"</span></p>
|
||||||
|
|
||||||
|
<p><strong>输出:</strong><span class="example-io">true</span></p>
|
||||||
|
|
||||||
|
<p><strong>解释:</strong></p>
|
||||||
|
|
||||||
|
<p>这个单词满足所有条件。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><strong class="example">示例 2:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>输入:</strong><span class="example-io">word = "b3"</span></p>
|
||||||
|
|
||||||
|
<p><strong>输出:</strong><span class="example-io">false</span></p>
|
||||||
|
|
||||||
|
<p><strong>解释:</strong></p>
|
||||||
|
|
||||||
|
<p>这个单词的长度少于 3 且没有包含元音字母。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><strong class="example">示例 3:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>输入:</strong><span class="example-io">word = "a3$e"</span></p>
|
||||||
|
|
||||||
|
<p><strong>输出:</strong><span class="example-io">false</span></p>
|
||||||
|
|
||||||
|
<p><strong>解释:</strong></p>
|
||||||
|
|
||||||
|
<p>这个单词包含了 <code>'$'</code> 字符且没有包含辅音字母。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= word.length <= 20</code></li>
|
||||||
|
<li><code>word</code> 由英文大写和小写字母、数字、<code>'@'</code>、<code>'#'</code> 和 <code>'$'</code> 组成。</li>
|
||||||
|
</ul>
|
@ -0,0 +1,67 @@
|
|||||||
|
<p>给你一个二维数组 <code>points</code> 和一个字符串 <code>s</code> ,其中 <code>points[i]</code> 表示第 <code>i</code> 个点的坐标,<code>s[i]</code> 表示第 <code>i</code> 个点的 <strong>标签</strong> 。</p>
|
||||||
|
|
||||||
|
<p>如果一个正方形的中心在 <code>(0, 0)</code> ,所有边都平行于坐标轴,且正方形内 <strong>不</strong> 存在标签相同的两个点,那么我们称这个正方形是 <strong>合法</strong> 的。</p>
|
||||||
|
|
||||||
|
<p>请你返回 <strong>合法</strong> 正方形中可以包含的 <strong>最多</strong> 点数。</p>
|
||||||
|
|
||||||
|
<p><strong>注意:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>如果一个点位于正方形的边上或者在边以内,则认为该点位于正方形内。</li>
|
||||||
|
<li>正方形的边长可以为零。</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong class="example">示例 1:</strong></p>
|
||||||
|
|
||||||
|
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/03/29/3708-tc1.png" style="width: 303px; height: 303px;" /></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><span class="example-io"><b>输入:</b>points = [[2,2],[-1,-2],[-4,4],[-3,1],[3,-3]], s = "abdca"</span></p>
|
||||||
|
|
||||||
|
<p><span class="example-io"><b>输出:</b>2</span></p>
|
||||||
|
|
||||||
|
<p><strong>解释:</strong></p>
|
||||||
|
|
||||||
|
<p>边长为 4 的正方形包含两个点 <code>points[0]</code> 和 <code>points[1]</code> 。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><strong class="example">示例 2:</strong></p>
|
||||||
|
|
||||||
|
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/03/29/3708-tc2.png" style="width: 302px; height: 302px;" /></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><span class="example-io"><b>输入:</b>points = [[1,1],[-2,-2],[-2,2]], s = "abb"</span></p>
|
||||||
|
|
||||||
|
<p><span class="example-io"><b>输出:</b>1</span></p>
|
||||||
|
|
||||||
|
<p><strong>解释:</strong></p>
|
||||||
|
|
||||||
|
<p>边长为 2 的正方形包含 1 个点 <code>points[0]</code> 。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><strong class="example">示例 3:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><span class="example-io"><b>输入:</b>points = [[1,1],[-1,-1],[2,-2]], s = "ccd"</span></p>
|
||||||
|
|
||||||
|
<p><span class="example-io"><b>输出:</b>0</span></p>
|
||||||
|
|
||||||
|
<p><strong>解释:</strong></p>
|
||||||
|
|
||||||
|
<p>任何正方形都无法只包含 <code>points[0]</code> 和 <code>points[1]</code> 中的一个点,所以合法正方形中都不包含任何点。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= s.length, points.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>points[i].length == 2</code></li>
|
||||||
|
<li><code>-10<sup>9</sup> <= points[i][0], points[i][1] <= 10<sup>9</sup></code></li>
|
||||||
|
<li><code>s.length == points.length</code></li>
|
||||||
|
<li><code>points</code> 中的点坐标互不相同。</li>
|
||||||
|
<li><code>s</code> 只包含小写英文字母。</li>
|
||||||
|
</ul>
|
@ -0,0 +1,44 @@
|
|||||||
|
<p>给你一个由 <strong>正整数</strong> 组成、大小为 <code>m x n</code> 的矩阵 <code>grid</code>。你可以从矩阵中的任一单元格移动到另一个位于正下方或正右侧的任意单元格(不必相邻)。从值为 <code>c1</code> 的单元格移动到值为 <code>c2</code> 的单元格的得分为 <code>c2 - c1</code> 。</p>
|
||||||
|
|
||||||
|
<p>你可以从<strong> 任一</strong> 单元格开始,并且必须至少移动一次。</p>
|
||||||
|
|
||||||
|
<p>返回你能得到的 <strong>最大 </strong>总得分。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong class="example">示例 1:</strong></p>
|
||||||
|
<img alt="" src="https://assets.leetcode.com/uploads/2024/03/14/grid1.png" style="width: 240px; height: 240px;" />
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>输入:</strong><span class="example-io">grid = [[9,5,7,3],[8,9,6,1],[6,7,14,3],[2,5,3,1]]</span></p>
|
||||||
|
|
||||||
|
<p><strong>输出:</strong><span class="example-io">9</span></p>
|
||||||
|
|
||||||
|
<p><strong>解释:</strong>从单元格 <code>(0, 1)</code> 开始,并执行以下移动:<br />
|
||||||
|
- 从单元格 <code>(0, 1)</code> 移动到 <code>(2, 1)</code>,得分为 <code>7 - 5 = 2</code> 。<br />
|
||||||
|
- 从单元格 <code>(2, 1)</code> 移动到 <code>(2, 2)</code>,得分为 <code>14 - 7 = 7</code> 。<br />
|
||||||
|
总得分为 <code>2 + 7 = 9</code> 。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><strong class="example">示例 2:</strong></p>
|
||||||
|
|
||||||
|
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/04/08/moregridsdrawio-1.png" style="width: 180px; height: 116px;" /></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>输入:</strong><span class="example-io">grid = [[4,3,2],[3,2,1]]</span></p>
|
||||||
|
|
||||||
|
<p><strong>输出:</strong><span class="example-io">-1</span></p>
|
||||||
|
|
||||||
|
<p><strong>解释:</strong>从单元格 <code>(0, 0)</code> 开始,执行一次移动:从 <code>(0, 0)</code> 到 <code>(0, 1)</code> 。得分为 <code>3 - 4 = -1</code> 。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>m == grid.length</code></li>
|
||||||
|
<li><code>n == grid[i].length</code></li>
|
||||||
|
<li><code>2 <= m, n <= 1000</code></li>
|
||||||
|
<li><code>4 <= m * n <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>1 <= grid[i][j] <= 10<sup>5</sup></code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,83 @@
|
|||||||
|
<p>You are given a string <code>word</code> of size <code>n</code>, and an integer <code>k</code> such that <code>k</code> divides <code>n</code>.</p>
|
||||||
|
|
||||||
|
<p>In one operation, you can pick any two indices <code>i</code> and <code>j</code>, that are divisible by <code>k</code>, then replace the <span data-keyword="substring">substring</span> of length <code>k</code> starting at <code>i</code> with the substring of length <code>k</code> starting at <code>j</code>. That is, replace the substring <code>word[i..i + k - 1]</code> with the substring <code>word[j..j + k - 1]</code>.<!-- notionvc: 49ac84f7-0724-452a-ab43-0c5e53f1db33 --></p>
|
||||||
|
|
||||||
|
<p>Return <em>the <strong>minimum</strong> number of operations required to make</em> <code>word</code> <em><strong>k-periodic</strong></em>.</p>
|
||||||
|
|
||||||
|
<p>We say that <code>word</code> is <strong>k-periodic</strong> if there is some string <code>s</code> of length <code>k</code> such that <code>word</code> can be obtained by concatenating <code>s</code> an arbitrary number of times. For example, if <code>word == “ababab”</code>, then <code>word</code> is 2-periodic for <code>s = "ab"</code>.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>Input:</strong> <span class="example-io" style="
|
||||||
|
font-family: Menlo,sans-serif;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
">word = "leetcodeleet", k = 4</span></p>
|
||||||
|
|
||||||
|
<p><strong>Output:</strong> <span class="example-io" style="
|
||||||
|
font-family: Menlo,sans-serif;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
">1</span></p>
|
||||||
|
|
||||||
|
<p><strong>Explanation:</strong></p>
|
||||||
|
|
||||||
|
<p>We can obtain a 4-periodic string by picking i = 4 and j = 0. After this operation, word becomes equal to "leetleetleet".</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>Input:</strong> <span class="example-io" style="
|
||||||
|
font-family: Menlo,sans-serif;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
">word = "</span>leetcoleet<span class="example-io" style="
|
||||||
|
font-family: Menlo,sans-serif;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
">", k = 2</span></p>
|
||||||
|
|
||||||
|
<p><strong>Output:</strong> 3</p>
|
||||||
|
|
||||||
|
<p><strong>Explanation:</strong></p>
|
||||||
|
|
||||||
|
<p>We can obtain a 2-periodic string by applying the operations in the table below.</p>
|
||||||
|
|
||||||
|
<table border="1" bordercolor="#ccc" cellpadding="5" cellspacing="0" height="146" style="border-collapse:collapse; text-align: center; vertical-align: middle;">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th>i</th>
|
||||||
|
<th>j</th>
|
||||||
|
<th>word</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td style="padding: 5px 15px;">0</td>
|
||||||
|
<td style="padding: 5px 15px;">2</td>
|
||||||
|
<td style="padding: 5px 15px;">etetcoleet</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td style="padding: 5px 15px;">4</td>
|
||||||
|
<td style="padding: 5px 15px;">0</td>
|
||||||
|
<td style="padding: 5px 15px;">etetetleet</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td style="padding: 5px 15px;">6</td>
|
||||||
|
<td style="padding: 5px 15px;">0</td>
|
||||||
|
<td style="padding: 5px 15px;">etetetetet</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="gtx-trans" style="position: absolute; left: 107px; top: 238.5px;">
|
||||||
|
<div class="gtx-trans-icon"> </div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= n == word.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>1 <= k <= word.length</code></li>
|
||||||
|
<li><code>k</code> divides <code>word.length</code>.</li>
|
||||||
|
<li><code>word</code> consists only of lowercase English letters.</li>
|
||||||
|
</ul>
|
@ -0,0 +1,46 @@
|
|||||||
|
<p>You are given two strings <code>s</code> and <code>t</code> such that every character occurs at most once in <code>s</code> and <code>t</code> is a permutation of <code>s</code>.</p>
|
||||||
|
|
||||||
|
<p>The <strong>permutation difference</strong> between <code>s</code> and <code>t</code> is defined as the <strong>sum</strong> of the absolute difference between the index of the occurrence of each character in <code>s</code> and the index of the occurrence of the same character in <code>t</code>.</p>
|
||||||
|
|
||||||
|
<p>Return the <strong>permutation difference</strong> between <code>s</code> and <code>t</code>.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>Input:</strong> <span class="example-io">s = "abc", t = "bac"</span></p>
|
||||||
|
|
||||||
|
<p><strong>Output:</strong> <span class="example-io">2</span></p>
|
||||||
|
|
||||||
|
<p><strong>Explanation:</strong></p>
|
||||||
|
|
||||||
|
<p>For <code>s = "abc"</code> and <code>t = "bac"</code>, the permutation difference of <code>s</code> and <code>t</code> is equal to the sum of:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>The absolute difference between the index of the occurrence of <code>"a"</code> in <code>s</code> and the index of the occurrence of <code>"a"</code> in <code>t</code>.</li>
|
||||||
|
<li>The absolute difference between the index of the occurrence of <code>"b"</code> in <code>s</code> and the index of the occurrence of <code>"b"</code> in <code>t</code>.</li>
|
||||||
|
<li>The absolute difference between the index of the occurrence of <code>"c"</code> in <code>s</code> and the index of the occurrence of <code>"c"</code> in <code>t</code>.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>That is, the permutation difference between <code>s</code> and <code>t</code> is equal to <code>|0 - 1| + |2 - 2| + |1 - 0| = 2</code>.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>Input:</strong> <span class="example-io">s = "abcde", t = "edbac"</span></p>
|
||||||
|
|
||||||
|
<p><strong>Output:</strong> <span class="example-io">12</span></p>
|
||||||
|
|
||||||
|
<p><strong>Explanation:</strong> The permutation difference between <code>s</code> and <code>t</code> is equal to <code>|0 - 3| + |1 - 2| + |2 - 4| + |3 - 1| + |4 - 0| = 12</code>.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= s.length <= 26</code></li>
|
||||||
|
<li>Each character occurs at most once in <code>s</code>.</li>
|
||||||
|
<li><code>t</code> is a permutation of <code>s</code>.</li>
|
||||||
|
<li><code>s</code> consists only of lowercase English letters.</li>
|
||||||
|
</ul>
|
@ -0,0 +1,70 @@
|
|||||||
|
<p>In a mystic dungeon, <code>n</code> magicians are standing in a line. Each magician has an attribute that gives you energy. Some magicians can give you negative energy, which means taking energy from you.</p>
|
||||||
|
|
||||||
|
<p>You have been cursed in such a way that after absorbing energy from magician <code>i</code>, you will be instantly transported to magician <code>(i + k)</code>. This process will be repeated until you reach the magician where <code>(i + k)</code> does not exist.</p>
|
||||||
|
|
||||||
|
<p>In other words, you will choose a starting point and then teleport with <code>k</code> jumps until you reach the end of the magicians' sequence, <strong>absorbing all the energy</strong> during the journey.</p>
|
||||||
|
|
||||||
|
<p>You are given an array <code>energy</code> and an integer <code>k</code>. Return the <strong>maximum</strong> possible energy you can gain.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block" style="
|
||||||
|
border-color: var(--border-tertiary);
|
||||||
|
border-left-width: 2px;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
font-size: .875rem;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
margin-top: 1rem;
|
||||||
|
overflow: visible;
|
||||||
|
padding-left: 1rem;
|
||||||
|
">
|
||||||
|
<p><strong>Input:</strong> <span class="example-io" style="
|
||||||
|
font-family: Menlo,sans-serif;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
"> energy = [5,2,-10,-5,1], k = 3</span></p>
|
||||||
|
|
||||||
|
<p><strong>Output:</strong><span class="example-io" style="
|
||||||
|
font-family: Menlo,sans-serif;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
"> 3</span></p>
|
||||||
|
|
||||||
|
<p><strong>Explanation:</strong> We can gain a total energy of 3 by starting from magician 1 absorbing 2 + 1 = 3.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block" style="
|
||||||
|
border-color: var(--border-tertiary);
|
||||||
|
border-left-width: 2px;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
font-size: .875rem;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
margin-top: 1rem;
|
||||||
|
overflow: visible;
|
||||||
|
padding-left: 1rem;
|
||||||
|
">
|
||||||
|
<p><strong>Input:</strong><span class="example-io" style="
|
||||||
|
font-family: Menlo,sans-serif;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
"> energy = [-2,-3,-1], k = 2</span></p>
|
||||||
|
|
||||||
|
<p><strong>Output:</strong><span class="example-io" style="
|
||||||
|
font-family: Menlo,sans-serif;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
"> -1</span></p>
|
||||||
|
|
||||||
|
<p><strong>Explanation:</strong> We can gain a total energy of -1 by starting from magician 2.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= energy.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>-1000 <= energy[i] <= 1000</code></li>
|
||||||
|
<li><code>1 <= k <= energy.length - 1</code></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
@ -0,0 +1,84 @@
|
|||||||
|
<p>You are given an integer array <code>nums</code> and two integers <code>cost1</code> and <code>cost2</code>. You are allowed to perform <strong>either</strong> of the following operations <strong>any</strong> number of times:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>Choose an index <code>i</code> from <code>nums</code> and <strong>increase</strong> <code>nums[i]</code> by <code>1</code> for a cost of <code>cost1</code>.</li>
|
||||||
|
<li>Choose two <strong>different</strong> indices <code>i</code>, <code>j</code>, from <code>nums</code> and <strong>increase</strong> <code>nums[i]</code> and <code>nums[j]</code> by <code>1</code> for a cost of <code>cost2</code>.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Return the <strong>minimum</strong> <strong>cost</strong> required to make all elements in the array <strong>equal</strong><em>. </em></p>
|
||||||
|
|
||||||
|
<p>Since the answer may be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>Input:</strong> <span class="example-io">nums = [4,1], cost1 = 5, cost2 = 2</span></p>
|
||||||
|
|
||||||
|
<p><strong>Output:</strong> <span class="example-io">15</span></p>
|
||||||
|
|
||||||
|
<p><strong>Explanation: </strong></p>
|
||||||
|
|
||||||
|
<p>The following operations can be performed to make the values equal:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>Increase <code>nums[1]</code> by 1 for a cost of 5. <code>nums</code> becomes <code>[4,2]</code>.</li>
|
||||||
|
<li>Increase <code>nums[1]</code> by 1 for a cost of 5. <code>nums</code> becomes <code>[4,3]</code>.</li>
|
||||||
|
<li>Increase <code>nums[1]</code> by 1 for a cost of 5. <code>nums</code> becomes <code>[4,4]</code>.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>The total cost is 15.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>Input:</strong> <span class="example-io">nums = [2,3,3,3,5], cost1 = 2, cost2 = 1</span></p>
|
||||||
|
|
||||||
|
<p><strong>Output:</strong> <span class="example-io">6</span></p>
|
||||||
|
|
||||||
|
<p><strong>Explanation: </strong></p>
|
||||||
|
|
||||||
|
<p>The following operations can be performed to make the values equal:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>Increase <code>nums[0]</code> and <code>nums[1]</code> by 1 for a cost of 1. <code>nums</code> becomes <code>[3,4,3,3,5]</code>.</li>
|
||||||
|
<li>Increase <code>nums[0]</code> and <code>nums[2]</code> by 1 for a cost of 1. <code>nums</code> becomes <code>[4,4,4,3,5]</code>.</li>
|
||||||
|
<li>Increase <code>nums[0]</code> and <code>nums[3]</code> by 1 for a cost of 1. <code>nums</code> becomes <code>[5,4,4,4,5]</code>.</li>
|
||||||
|
<li>Increase <code>nums[1]</code> and <code>nums[2]</code> by 1 for a cost of 1. <code>nums</code> becomes <code>[5,5,5,4,5]</code>.</li>
|
||||||
|
<li>Increase <code>nums[3]</code> by 1 for a cost of 2. <code>nums</code> becomes <code>[5,5,5,5,5]</code>.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>The total cost is 6.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 3:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>Input:</strong> <span class="example-io">nums = [3,5,3], cost1 = 1, cost2 = 3</span></p>
|
||||||
|
|
||||||
|
<p><strong>Output:</strong> <span class="example-io">4</span></p>
|
||||||
|
|
||||||
|
<p><strong>Explanation:</strong></p>
|
||||||
|
|
||||||
|
<p>The following operations can be performed to make the values equal:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>Increase <code>nums[0]</code> by 1 for a cost of 1. <code>nums</code> becomes <code>[4,5,3]</code>.</li>
|
||||||
|
<li>Increase <code>nums[0]</code> by 1 for a cost of 1. <code>nums</code> becomes <code>[5,5,3]</code>.</li>
|
||||||
|
<li>Increase <code>nums[2]</code> by 1 for a cost of 1. <code>nums</code> becomes <code>[5,5,4]</code>.</li>
|
||||||
|
<li>Increase <code>nums[2]</code> by 1 for a cost of 1. <code>nums</code> becomes <code>[5,5,5]</code>.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>The total cost is 4.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>1 <= nums[i] <= 10<sup>6</sup></code></li>
|
||||||
|
<li><code>1 <= cost1 <= 10<sup>6</sup></code></li>
|
||||||
|
<li><code>1 <= cost2 <= 10<sup>6</sup></code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,38 @@
|
|||||||
|
<p>Given a string <code>s</code>, you need to partition it into one or more <strong>balanced</strong> <span data-keyword="substring">substrings</span>. For example, if <code>s == "ababcc"</code> then <code>("abab", "c", "c")</code>, <code>("ab", "abc", "c")</code>, and <code>("ababcc")</code> are all valid partitions, but <code>("a", <strong>"bab"</strong>, "cc")</code>, <code>(<strong>"aba"</strong>, "bc", "c")</code>, and <code>("ab", <strong>"abcc"</strong>)</code> are not. The unbalanced substrings are bolded.</p>
|
||||||
|
|
||||||
|
<p>Return the <strong>minimum</strong> number of substrings that you can partition <code>s</code> into.</p>
|
||||||
|
|
||||||
|
<p><strong>Note:</strong> A <strong>balanced</strong> string is a string where each character in the string occurs the same number of times.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>Input:</strong> <span class="example-io">s = "fabccddg"</span></p>
|
||||||
|
|
||||||
|
<p><strong>Output:</strong> <span class="example-io">3</span></p>
|
||||||
|
|
||||||
|
<p><strong>Explanation:</strong></p>
|
||||||
|
|
||||||
|
<p>We can partition the string <code>s</code> into 3 substrings in one of the following ways: <code>("fab, "ccdd", "g")</code>, or <code>("fabc", "cd", "dg")</code>.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>Input:</strong> <span class="example-io">s = "abababaccddb"</span></p>
|
||||||
|
|
||||||
|
<p><strong>Output:</strong> <span class="example-io">2</span></p>
|
||||||
|
|
||||||
|
<p><strong>Explanation:</strong></p>
|
||||||
|
|
||||||
|
<p>We can partition the string <code>s</code> into 2 substrings like so: <code>("abab", "abaccddb")</code>.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= s.length <= 1000</code></li>
|
||||||
|
<li><code>s</code> consists only of English lowercase letters.</li>
|
||||||
|
</ul>
|
@ -0,0 +1,59 @@
|
|||||||
|
<p>You are given a 2D matrix <code>grid</code> of size <code>m x n</code>. You need to check if each cell <code>grid[i][j]</code> is:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>Equal to the cell below it, i.e. <code>grid[i][j] == grid[i + 1][j]</code> (if it exists).</li>
|
||||||
|
<li>Different from the cell to its right, i.e. <code>grid[i][j] != grid[i][j + 1]</code> (if it exists).</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Return <code>true</code> if <strong>all</strong> the cells satisfy these conditions, otherwise, return <code>false</code>.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>Input:</strong> <span class="example-io">grid = [[1,0,2],[1,0,2]]</span></p>
|
||||||
|
|
||||||
|
<p><strong>Output:</strong> <span class="example-io">true</span></p>
|
||||||
|
|
||||||
|
<p><strong>Explanation:</strong></p>
|
||||||
|
|
||||||
|
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/04/15/examplechanged.png" style="width: 254px; height: 186px;padding: 10px; background: #fff; border-radius: .5rem;" /></strong></p>
|
||||||
|
|
||||||
|
<p>All the cells in the grid satisfy the conditions.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>Input:</strong> <span class="example-io">grid = [[1,1,1],[0,0,0]]</span></p>
|
||||||
|
|
||||||
|
<p><strong>Output:</strong> <span class="example-io">false</span></p>
|
||||||
|
|
||||||
|
<p><strong>Explanation:</strong></p>
|
||||||
|
|
||||||
|
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/03/27/example21.png" style="width: 254px; height: 186px;padding: 10px; background: #fff; border-radius: .5rem;" /></strong></p>
|
||||||
|
|
||||||
|
<p>All cells in the first row are equal.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 3:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>Input:</strong> <span class="example-io">grid = [[1],[2],[3]]</span></p>
|
||||||
|
|
||||||
|
<p><strong>Output:</strong> <span class="example-io">false</span></p>
|
||||||
|
|
||||||
|
<p><strong>Explanation:</strong></p>
|
||||||
|
|
||||||
|
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/03/31/changed.png" style="width: 86px; height: 277px;padding: 10px; background: #fff; border-radius: .5rem;" /></p>
|
||||||
|
|
||||||
|
<p>Cells in the first column have different values.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= n, m <= 10</code></li>
|
||||||
|
<li><code>0 <= grid[i][j] <= 9</code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,38 @@
|
|||||||
|
<p>You are given a string <code>s</code>, which is known to be a concatenation of <strong>anagrams</strong> of some string <code>t</code>.</p>
|
||||||
|
|
||||||
|
<p>Return the <strong>minimum</strong> possible length of the string <code>t</code>.</p>
|
||||||
|
|
||||||
|
<p>An <strong>anagram</strong> is formed by rearranging the letters of a string. For example, "aab", "aba", and, "baa" are anagrams of "aab".</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>Input:</strong> <span class="example-io">s = "abba"</span></p>
|
||||||
|
|
||||||
|
<p><strong>Output:</strong> <span class="example-io">2</span></p>
|
||||||
|
|
||||||
|
<p><strong>Explanation:</strong></p>
|
||||||
|
|
||||||
|
<p>One possible string <code>t</code> could be <code>"ba"</code>.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>Input:</strong> <span class="example-io">s = "cdef"</span></p>
|
||||||
|
|
||||||
|
<p><strong>Output:</strong> <span class="example-io">4</span></p>
|
||||||
|
|
||||||
|
<p><strong>Explanation:</strong></p>
|
||||||
|
|
||||||
|
<p>One possible string <code>t</code> could be <code>"cdef"</code>, notice that <code>t</code> can be equal to <code>s</code>.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= s.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>s</code> consist only of lowercase English letters.</li>
|
||||||
|
</ul>
|
@ -0,0 +1,48 @@
|
|||||||
|
<p>A <strong>powerful array</strong> for an integer <code>x</code> is the shortest sorted array of powers of two that sum up to <code>x</code>. For example, the powerful array for 11 is <code>[1, 2, 8]</code>.</p>
|
||||||
|
|
||||||
|
<p>The array <code>big_nums</code> is created by concatenating the <strong>powerful</strong> arrays for every positive integer <code>i</code> in ascending order: 1, 2, 3, and so forth. Thus, <code>big_nums</code> starts as <code>[<u>1</u>, <u>2</u>, <u>1, 2</u>, <u>4</u>, <u>1, 4</u>, <u>2, 4</u>, <u>1, 2, 4</u>, <u>8</u>, ...]</code>.</p>
|
||||||
|
|
||||||
|
<p>You are given a 2D integer matrix <code>queries</code>, where for <code>queries[i] = [from<sub>i</sub>, to<sub>i</sub>, mod<sub>i</sub>]</code> you should calculate <code>(big_nums[from<sub>i</sub>] * big_nums[from<sub>i</sub> + 1] * ... * big_nums[to<sub>i</sub>]) % mod<sub>i</sub></code><!-- notionvc: a71131cc-7b52-4786-9a4b-660d6d864f89 -->.</p>
|
||||||
|
|
||||||
|
<p>Return an integer array <code>answer</code> such that <code>answer[i]</code> is the answer to the <code>i<sup>th</sup></code> query.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>Input:</strong> <span class="example-io">queries = [[1,3,7]]</span></p>
|
||||||
|
|
||||||
|
<p><strong>Output:</strong> <span class="example-io">[4]</span></p>
|
||||||
|
|
||||||
|
<p><strong>Explanation:</strong></p>
|
||||||
|
|
||||||
|
<p>There is one query.</p>
|
||||||
|
|
||||||
|
<p><code>big_nums[1..3] = [2,1,2]</code>. The product of them is 4. The remainder of 4 under 7 is 4.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>Input:</strong> <span class="example-io">queries = [[2,5,3],[7,7,4]]</span></p>
|
||||||
|
|
||||||
|
<p><strong>Output:</strong> <span class="example-io">[2,2]</span></p>
|
||||||
|
|
||||||
|
<p><strong>Explanation:</strong></p>
|
||||||
|
|
||||||
|
<p>There are two queries.</p>
|
||||||
|
|
||||||
|
<p>First query: <code>big_nums[2..5] = [1,2,4,1]</code>. The product of them is 8. The remainder of 8 under 3 is 2.</p>
|
||||||
|
|
||||||
|
<p>Second query: <code>big_nums[7] = 2</code>. The remainder of 2 under 4 is 2.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= queries.length <= 500</code></li>
|
||||||
|
<li><code>queries[i].length == 3</code></li>
|
||||||
|
<li><code>0 <= queries[i][0] <= queries[i][1] <= 10<sup>15</sup></code></li>
|
||||||
|
<li><code>1 <= queries[i][2] <= 10<sup>5</sup></code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,42 @@
|
|||||||
|
<p>You are given an array <code>nums</code> which is a <span data-keyword="permutation">permutation</span> of <code>[0, 1, 2, ..., n - 1]</code>. The <strong>score</strong> of any permutation of <code>[0, 1, 2, ..., n - 1]</code> named <code>perm</code> is defined as:</p>
|
||||||
|
|
||||||
|
<p><code>score(perm) = |perm[0] - nums[perm[1]]| + |perm[1] - nums[perm[2]]| + ... + |perm[n - 1] - nums[perm[0]]|</code></p>
|
||||||
|
|
||||||
|
<p>Return the permutation <code>perm</code> which has the <strong>minimum</strong> possible score. If <em>multiple</em> permutations exist with this score, return the one that is <span data-keyword="lexicographically-smaller-array">lexicographically smallest</span> among them.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>Input:</strong> <span class="example-io">nums = [1,0,2]</span></p>
|
||||||
|
|
||||||
|
<p><strong>Output:</strong> <span class="example-io">[0,1,2]</span></p>
|
||||||
|
|
||||||
|
<p><strong>Explanation:</strong></p>
|
||||||
|
|
||||||
|
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/04/04/example0gif.gif" style="width: 235px; height: 235px;" /></strong></p>
|
||||||
|
|
||||||
|
<p>The lexicographically smallest permutation with minimum cost is <code>[0,1,2]</code>. The cost of this permutation is <code>|0 - 0| + |1 - 2| + |2 - 1| = 2</code>.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>Input:</strong> <span class="example-io">nums = [0,2,1]</span></p>
|
||||||
|
|
||||||
|
<p><strong>Output:</strong> <span class="example-io">[0,2,1]</span></p>
|
||||||
|
|
||||||
|
<p><strong>Explanation:</strong></p>
|
||||||
|
|
||||||
|
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/04/04/example1gif.gif" style="width: 235px; height: 235px;" /></strong></p>
|
||||||
|
|
||||||
|
<p>The lexicographically smallest permutation with minimum cost is <code>[0,2,1]</code>. The cost of this permutation is <code>|0 - 1| + |2 - 2| + |1 - 0| = 2</code>.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>2 <= n == nums.length <= 14</code></li>
|
||||||
|
<li><code>nums</code> is a permutation of <code>[0, 1, 2, ..., n - 1]</code>.</li>
|
||||||
|
</ul>
|
@ -0,0 +1,64 @@
|
|||||||
|
<p>A word is considered <strong>valid</strong> if:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>It contains a <strong>minimum</strong> of 3 characters.</li>
|
||||||
|
<li>It contains only digits (0-9), and English letters (uppercase and lowercase).</li>
|
||||||
|
<li>It includes <strong>at least</strong> one <strong>vowel</strong>.</li>
|
||||||
|
<li>It includes <strong>at least</strong> one <strong>consonant</strong>.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>You are given a string <code>word</code>.</p>
|
||||||
|
|
||||||
|
<p>Return <code>true</code> if <code>word</code> is valid, otherwise, return <code>false</code>.</p>
|
||||||
|
|
||||||
|
<p><strong>Notes:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'</code>, and their uppercases are <strong>vowels</strong>.</li>
|
||||||
|
<li>A <strong>consonant</strong> is an English letter that is not a vowel.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>Input:</strong> <span class="example-io">word = "234Adas"</span></p>
|
||||||
|
|
||||||
|
<p><strong>Output:</strong> <span class="example-io">true</span></p>
|
||||||
|
|
||||||
|
<p><strong>Explanation:</strong></p>
|
||||||
|
|
||||||
|
<p>This word satisfies the conditions.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>Input:</strong> <span class="example-io">word = "b3"</span></p>
|
||||||
|
|
||||||
|
<p><strong>Output:</strong> <span class="example-io">false</span></p>
|
||||||
|
|
||||||
|
<p><strong>Explanation:</strong></p>
|
||||||
|
|
||||||
|
<p>The length of this word is fewer than 3, and does not have a vowel.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 3:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>Input:</strong> <span class="example-io">word = "a3$e"</span></p>
|
||||||
|
|
||||||
|
<p><strong>Output:</strong> <span class="example-io">false</span></p>
|
||||||
|
|
||||||
|
<p><strong>Explanation:</strong></p>
|
||||||
|
|
||||||
|
<p>This word contains a <code>'$'</code> character and does not have a consonant.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= word.length <= 20</code></li>
|
||||||
|
<li><code>word</code> consists of English uppercase and lowercase letters, digits, <code>'@'</code>, <code>'#'</code>, and <code>'$'</code>.</li>
|
||||||
|
</ul>
|
@ -0,0 +1,65 @@
|
|||||||
|
<p>You are given a 2D<strong> </strong>array <code>points</code> and a string <code>s</code> where, <code>points[i]</code> represents the coordinates of point <code>i</code>, and <code>s[i]</code> represents the <strong>tag</strong> of point <code>i</code>.</p>
|
||||||
|
|
||||||
|
<p>A <strong>valid</strong> square is a square centered at the origin <code>(0, 0)</code>, has edges parallel to the axes, and <strong>does not</strong> contain two points with the same tag.</p>
|
||||||
|
|
||||||
|
<p>Return the <strong>maximum</strong> number of points contained in a <strong>valid</strong> square.</p>
|
||||||
|
|
||||||
|
<p>Note:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>A point is considered to be inside the square if it lies on or within the square's boundaries.</li>
|
||||||
|
<li>The side length of the square can be zero.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
|
||||||
|
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/03/29/3708-tc1.png" style="width: 303px; height: 303px;" /></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>Input:</strong> <span class="example-io">points = [[2,2],[-1,-2],[-4,4],[-3,1],[3,-3]], s = "abdca"</span></p>
|
||||||
|
|
||||||
|
<p><strong>Output:</strong> <span class="example-io">2</span></p>
|
||||||
|
|
||||||
|
<p><strong>Explanation:</strong></p>
|
||||||
|
|
||||||
|
<p>The square of side length 4 covers two points <code>points[0]</code> and <code>points[1]</code>.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/03/29/3708-tc2.png" style="width: 302px; height: 302px;" /></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>Input:</strong> <span class="example-io">points = [[1,1],[-2,-2],[-2,2]], s = "abb"</span></p>
|
||||||
|
|
||||||
|
<p><strong>Output:</strong> <span class="example-io">1</span></p>
|
||||||
|
|
||||||
|
<p><strong>Explanation:</strong></p>
|
||||||
|
|
||||||
|
<p>The square of side length 2 covers one point, which is <code>points[0]</code>.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 3:</strong></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>Input:</strong> <span class="example-io">points = [[1,1],[-1,-1],[2,-2]], s = "ccd"</span></p>
|
||||||
|
|
||||||
|
<p><strong>Output:</strong> <span class="example-io">0</span></p>
|
||||||
|
|
||||||
|
<p><strong>Explanation:</strong></p>
|
||||||
|
|
||||||
|
<p>It's impossible to make any valid squares centered at the origin such that it covers only one point among <code>points[0]</code> and <code>points[1]</code>.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= s.length, points.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>points[i].length == 2</code></li>
|
||||||
|
<li><code>-10<sup>9</sup> <= points[i][0], points[i][1] <= 10<sup>9</sup></code></li>
|
||||||
|
<li><code>s.length == points.length</code></li>
|
||||||
|
<li><code>points</code> consists of distinct coordinates.</li>
|
||||||
|
<li><code>s</code> consists only of lowercase English letters.</li>
|
||||||
|
</ul>
|
@ -0,0 +1,42 @@
|
|||||||
|
<p>You are given an <code>m x n</code> matrix <code>grid</code> consisting of <strong>positive</strong> integers. You can move from a cell in the matrix to <strong>any</strong> other cell that is either to the bottom or to the right (not necessarily adjacent). The score of a move from a cell with the value <code>c1</code> to a cell with the value <code>c2</code> is <code>c2 - c1</code>.<!-- notionvc: 8819ca04-8606-4ecf-815b-fb77bc63b851 --></p>
|
||||||
|
|
||||||
|
<p>You can start at <strong>any</strong> cell, and you have to make <strong>at least</strong> one move.</p>
|
||||||
|
|
||||||
|
<p>Return the <strong>maximum</strong> total score you can achieve.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong class="example">Example 1:</strong></p>
|
||||||
|
<img alt="" src="https://assets.leetcode.com/uploads/2024/03/14/grid1.png" style="width: 240px; height: 240px;" />
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>Input:</strong> <span class="example-io">grid = [[9,5,7,3],[8,9,6,1],[6,7,14,3],[2,5,3,1]]</span></p>
|
||||||
|
|
||||||
|
<p><strong>Output:</strong> <span class="example-io">9</span></p>
|
||||||
|
|
||||||
|
<p><strong>Explanation:</strong> We start at the cell <code>(0, 1)</code>, and we perform the following moves:<br />
|
||||||
|
- Move from the cell <code>(0, 1)</code> to <code>(2, 1)</code> with a score of <code>7 - 5 = 2</code>.<br />
|
||||||
|
- Move from the cell <code>(2, 1)</code> to <code>(2, 2)</code> with a score of <code>14 - 7 = 7</code>.<br />
|
||||||
|
The total score is <code>2 + 7 = 9</code>.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><strong class="example">Example 2:</strong></p>
|
||||||
|
|
||||||
|
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/04/08/moregridsdrawio-1.png" style="width: 180px; height: 116px;" /></p>
|
||||||
|
|
||||||
|
<div class="example-block">
|
||||||
|
<p><strong>Input:</strong> <span class="example-io">grid = [[4,3,2],[3,2,1]]</span></p>
|
||||||
|
|
||||||
|
<p><strong>Output:</strong> <span class="example-io">-1</span></p>
|
||||||
|
|
||||||
|
<p><strong>Explanation:</strong> We start at the cell <code>(0, 0)</code>, and we perform one move: <code>(0, 0)</code> to <code>(0, 1)</code>. The score is <code>3 - 4 = -1</code>.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>m == grid.length</code></li>
|
||||||
|
<li><code>n == grid[i].length</code></li>
|
||||||
|
<li><code>2 <= m, n <= 1000</code></li>
|
||||||
|
<li><code>4 <= m * n <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>1 <= grid[i][j] <= 10<sup>5</sup></code></li>
|
||||||
|
</ul>
|
Loading…
Reference in New Issue
Block a user