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
6ba311f0f3
commit
8891b38740
@ -1,6 +1,6 @@
|
||||
# 力扣题库(完整版)
|
||||
|
||||
> 最后更新日期: **2022.06.10**
|
||||
> 最后更新日期: **2022.06.18**
|
||||
>
|
||||
> 使用脚本前请务必仔细完整阅读本 `README.md` 文件
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,58 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2441",
|
||||
"questionFrontendId": "2308",
|
||||
"categoryTitle": "Database",
|
||||
"boundTopicId": 1604217,
|
||||
"title": "Arrange Table by Gender",
|
||||
"titleSlug": "arrange-table-by-gender",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Medium",
|
||||
"likes": 1,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"contributors": [],
|
||||
"langToValidPlayground": null,
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"45\", \"totalSubmission\": \"54\", \"totalAcceptedRaw\": 45, \"totalSubmissionRaw\": 54, \"acRate\": \"83.3%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\": {\"Genders\": [\"user_id\", \"gender\"]}, \"rows\": {\"Genders\": [[4, \"male\"], [7, \"female\"], [2, \"other\"], [5, \"male\"], [3, \"female\"], [8, \"male\"], [6, \"other\"], [1, \"other\"], [9, \"female\"]]}}",
|
||||
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Genders (user_id int, gender ENUM('female', 'other', 'male'))\"\n ],\n \"mssql\": [\n \"Create table Genders (user_id int, gender VARCHAR(6) NOT NULL CHECK (gender IN ('female', 'other', 'male')))\"\n ],\n \"oraclesql\": [\n \"Create table Genders (user_id int, gender VARCHAR(6) NOT NULL CHECK (gender IN ('female', 'other', 'male')))\"\n ],\n \"database\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Create table If Not Exists Genders (user_id int, gender ENUM('female', 'other', 'male'))",
|
||||
"Truncate table Genders",
|
||||
"insert into Genders (user_id, gender) values ('4', 'male')",
|
||||
"insert into Genders (user_id, gender) values ('7', 'female')",
|
||||
"insert into Genders (user_id, gender) values ('2', 'other')",
|
||||
"insert into Genders (user_id, gender) values ('5', 'male')",
|
||||
"insert into Genders (user_id, gender) values ('3', 'female')",
|
||||
"insert into Genders (user_id, gender) values ('8', 'male')",
|
||||
"insert into Genders (user_id, gender) values ('6', 'other')",
|
||||
"insert into Genders (user_id, gender) values ('1', 'other')",
|
||||
"insert into Genders (user_id, gender) values ('9', 'female')"
|
||||
],
|
||||
"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>\"]}",
|
||||
"book": null,
|
||||
"isSubscribed": false,
|
||||
"isDailyQuestion": false,
|
||||
"dailyRecordStatus": null,
|
||||
"editorType": "CKEDITOR",
|
||||
"ugcQuestionId": null,
|
||||
"style": "LEETCODE",
|
||||
"exampleTestcases": "{\"headers\": {\"Genders\": [\"user_id\", \"gender\"]}, \"rows\": {\"Genders\": [[4, \"male\"], [7, \"female\"], [2, \"other\"], [5, \"male\"], [3, \"female\"], [8, \"male\"], [6, \"other\"], [1, \"other\"], [9, \"female\"]]}}",
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,62 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2440",
|
||||
"questionFrontendId": "2298",
|
||||
"categoryTitle": "Database",
|
||||
"boundTopicId": 1593866,
|
||||
"title": "Tasks Count in the Weekend",
|
||||
"titleSlug": "tasks-count-in-the-weekend",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"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\": \"44\", \"totalSubmission\": \"46\", \"totalAcceptedRaw\": 44, \"totalSubmissionRaw\": 46, \"acRate\": \"95.7%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\": {\"Tasks\": [\"task_id\", \"assignee_id\", \"submit_date\"]}, \"rows\": {\"Tasks\": [[1, 1, \"2022-06-13\"], [2, 6, \"2022-06-14\"], [3, 6, \"2022-06-15\"], [4, 3, \"2022-06-18\"], [5, 5, \"2022-06-19\"], [6, 7, \"2022-06-19\"]]}}",
|
||||
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Tasks (task_id int, assignee_id int, submit_date date)\"\n ],\n \"mssql\": [\n \"Create table Tasks (task_id int, assignee_id int, submit_date date)\"\n ],\n \"oraclesql\": [\n \"Create table Tasks (task_id int, assignee_id int, submit_date date)\",\n \"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"\n ],\n \"database\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Create table If Not Exists Tasks (task_id int, assignee_id int, submit_date date)",
|
||||
"Truncate table Tasks",
|
||||
"insert into Tasks (task_id, assignee_id, submit_date) values ('1', '1', '2022-06-13')",
|
||||
"insert into Tasks (task_id, assignee_id, submit_date) values ('2', '6', '2022-06-14')",
|
||||
"insert into Tasks (task_id, assignee_id, submit_date) values ('3', '6', '2022-06-15')",
|
||||
"insert into Tasks (task_id, assignee_id, submit_date) values ('4', '3', '2022-06-18')",
|
||||
"insert into Tasks (task_id, assignee_id, submit_date) values ('5', '5', '2022-06-19')",
|
||||
"insert into Tasks (task_id, assignee_id, submit_date) values ('6', '7', '2022-06-19')"
|
||||
],
|
||||
"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>\"]}",
|
||||
"book": null,
|
||||
"isSubscribed": false,
|
||||
"isDailyQuestion": false,
|
||||
"dailyRecordStatus": null,
|
||||
"editorType": "CKEDITOR",
|
||||
"ugcQuestionId": null,
|
||||
"style": "LEETCODE",
|
||||
"exampleTestcases": "{\"headers\": {\"Tasks\": [\"task_id\", \"assignee_id\", \"submit_date\"]}, \"rows\": {\"Tasks\": [[1, 1, \"2022-06-13\"], [2, 6, \"2022-06-14\"], [3, 6, \"2022-06-15\"], [4, 3, \"2022-06-18\"], [5, 5, \"2022-06-19\"], [6, 7, \"2022-06-19\"]]}}",
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
171
leetcode-cn/originData/calculate-amount-paid-in-taxes.json
Normal file
171
leetcode-cn/originData/calculate-amount-paid-in-taxes.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
189
leetcode-cn/originData/fair-distribution-of-cookies.json
Normal file
189
leetcode-cn/originData/fair-distribution-of-cookies.json
Normal file
File diff suppressed because one or more lines are too long
183
leetcode-cn/originData/match-substring-after-replacement.json
Normal file
183
leetcode-cn/originData/match-substring-after-replacement.json
Normal file
File diff suppressed because one or more lines are too long
177
leetcode-cn/originData/minimum-path-cost-in-a-grid.json
Normal file
177
leetcode-cn/originData/minimum-path-cost-in-a-grid.json
Normal file
File diff suppressed because one or more lines are too long
191
leetcode-cn/originData/naming-a-company.json
Normal file
191
leetcode-cn/originData/naming-a-company.json
Normal file
File diff suppressed because one or more lines are too long
165
leetcode-cn/originData/strong-password-checker-ii.json
Normal file
165
leetcode-cn/originData/strong-password-checker-ii.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
49
leetcode-cn/problem (Chinese)/公司命名 [naming-a-company].html
Normal file
49
leetcode-cn/problem (Chinese)/公司命名 [naming-a-company].html
Normal file
@ -0,0 +1,49 @@
|
||||
<p>给你一个字符串数组 <code>ideas</code> 表示在公司命名过程中使用的名字列表。公司命名流程如下:</p>
|
||||
|
||||
<ol>
|
||||
<li>从 <code>ideas</code> 中选择 2 个 <strong>不同</strong> 名字,称为 <code>idea<sub>A</sub></code> 和 <code>idea<sub>B</sub></code> 。</li>
|
||||
<li>交换 <code>idea<sub>A</sub></code> 和 <code>idea<sub>B</sub></code> 的首字母。</li>
|
||||
<li>如果得到的两个新名字 <strong>都</strong> 不在 <code>ideas</code> 中,那么 <code>idea<sub>A</sub> idea<sub>B</sub></code>(<strong>串联</strong> <code>idea<sub>A</sub></code> 和 <code>idea<sub>B</sub></code> ,中间用一个空格分隔)是一个有效的公司名字。</li>
|
||||
<li>否则,不是一个有效的名字。</li>
|
||||
</ol>
|
||||
|
||||
<p>返回 <strong>不同</strong> 且有效的公司名字的数目。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>ideas = ["coffee","donuts","time","toffee"]
|
||||
<strong>输出:</strong>6
|
||||
<strong>解释:</strong>下面列出一些有效的选择方案:
|
||||
- ("coffee", "donuts"):对应的公司名字是 "doffee conuts" 。
|
||||
- ("donuts", "coffee"):对应的公司名字是 "conuts doffee" 。
|
||||
- ("donuts", "time"):对应的公司名字是 "tonuts dime" 。
|
||||
- ("donuts", "toffee"):对应的公司名字是 "tonuts doffee" 。
|
||||
- ("time", "donuts"):对应的公司名字是 "dime tonuts" 。
|
||||
- ("toffee", "donuts"):对应的公司名字是 "doffee tonuts" 。
|
||||
因此,总共有 6 个不同的公司名字。
|
||||
|
||||
下面列出一些无效的选择方案:
|
||||
- ("coffee", "time"):在原数组中存在交换后形成的名字 "toffee" 。
|
||||
- ("time", "toffee"):在原数组中存在交换后形成的两个名字。
|
||||
- ("coffee", "toffee"):在原数组中存在交换后形成的两个名字。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>ideas = ["lack","back"]
|
||||
<strong>输出:</strong>0
|
||||
<strong>解释:</strong>不存在有效的选择方案。因此,返回 0 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= ideas.length <= 5 * 10<sup>4</sup></code></li>
|
||||
<li><code>1 <= ideas[i].length <= 10</code></li>
|
||||
<li><code>ideas[i]</code> 由小写英文字母组成</li>
|
||||
<li><code>ideas</code> 中的所有字符串 <strong>互不相同</strong></li>
|
||||
</ul>
|
@ -0,0 +1,40 @@
|
||||
<p>给你一个整数数组 <code>cookies</code> ,其中 <code>cookies[i]</code> 表示在第 <code>i</code> 个零食包中的饼干数量。另给你一个整数 <code>k</code> 表示等待分发零食包的孩子数量,<strong>所有</strong> 零食包都需要分发。在同一个零食包中的所有饼干都必须分发给同一个孩子,不能分开。</p>
|
||||
|
||||
<p>分发的 <strong>不公平程度</strong> 定义为单个孩子在分发过程中能够获得饼干的最大总数。</p>
|
||||
|
||||
<p>返回所有分发的最小不公平程度。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>cookies = [8,15,10,20,8], k = 2
|
||||
<strong>输出:</strong>31
|
||||
<strong>解释:</strong>一种最优方案是 [8,15,8] 和 [10,20] 。
|
||||
- 第 1 个孩子分到 [8,15,8] ,总计 8 + 15 + 8 = 31 块饼干。
|
||||
- 第 2 个孩子分到 [10,20] ,总计 10 + 20 = 30 块饼干。
|
||||
分发的不公平程度为 max(31,30) = 31 。
|
||||
可以证明不存在不公平程度小于 31 的分发方案。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>cookies = [6,1,3,2,2,4,1,2], k = 3
|
||||
<strong>输出:</strong>7
|
||||
<strong>解释:</strong>一种最优方案是 [6,1]、[3,2,2] 和 [4,1,2] 。
|
||||
- 第 1 个孩子分到 [6,1] ,总计 6 + 1 = 7 块饼干。
|
||||
- 第 2 个孩子分到 [3,2,2] ,总计 3 + 2 + 2 = 7 块饼干。
|
||||
- 第 3 个孩子分到 [4,1,2] ,总计 4 + 1 + 2 = 7 块饼干。
|
||||
分发的不公平程度为 max(7,7,7) = 7 。
|
||||
可以证明不存在不公平程度小于 7 的分发方案。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= cookies.length <= 8</code></li>
|
||||
<li><code>1 <= cookies[i] <= 10<sup>5</sup></code></li>
|
||||
<li><code>2 <= k <= cookies.length</code></li>
|
||||
</ul>
|
@ -0,0 +1,41 @@
|
||||
<p>给你两个正整数数组 <code>spells</code> 和 <code>potions</code> ,长度分别为 <code>n</code> 和 <code>m</code> ,其中 <code>spells[i]</code> 表示第 <code>i</code> 个咒语的能量强度,<code>potions[j]</code> 表示第 <code>j</code> 瓶药水的能量强度。</p>
|
||||
|
||||
<p>同时给你一个整数 <code>success</code> 。一个咒语和药水的能量强度 <strong>相乘</strong> 如果 <strong>大于等于</strong> <code>success</code> ,那么它们视为一对 <strong>成功</strong> 的组合。</p>
|
||||
|
||||
<p>请你返回一个长度为 <code>n</code> 的整数数组<em> </em><code>pairs</code>,其中<em> </em><code>pairs[i]</code> 是能跟第 <code>i</code> 个咒语成功组合的 <b>药水</b> 数目。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>spells = [5,1,3], potions = [1,2,3,4,5], success = 7
|
||||
<b>输出:</b>[4,0,3]
|
||||
<strong>解释:</strong>
|
||||
- 第 0 个咒语:5 * [1,2,3,4,5] = [5,<em><strong>10</strong></em>,<em><strong>15</strong></em>,<em><strong>20</strong></em>,<em><strong>25</strong></em>] 。总共 4 个成功组合。
|
||||
- 第 1 个咒语:1 * [1,2,3,4,5] = [1,2,3,4,5] 。总共 0 个成功组合。
|
||||
- 第 2 个咒语:3 * [1,2,3,4,5] = [3,6,<em><strong>9</strong></em>,<em><strong>12</strong></em>,<em><strong>15</strong></em>] 。总共 3 个成功组合。
|
||||
所以返回 [4,0,3] 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>spells = [3,1,2], potions = [8,5,8], success = 16
|
||||
<b>输出:</b>[2,0,2]
|
||||
<strong>解释:</strong>
|
||||
- 第 0 个咒语:3 * [8,5,8] = [<em><strong>24</strong></em>,15,<em><strong>24</strong></em>] 。总共 2 个成功组合。
|
||||
- 第 1 个咒语:1 * [8,5,8] = [8,5,8] 。总共 0 个成功组合。
|
||||
- 第 2 个咒语:2 * [8,5,8] = [<em><strong>16</strong></em>,10,<em><strong>16</strong></em>] 。总共 2 个成功组合。
|
||||
所以返回 [2,0,2] 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>n == spells.length</code></li>
|
||||
<li><code>m == potions.length</code></li>
|
||||
<li><code>1 <= n, m <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= spells[i], potions[i] <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= success <= 10<sup>10</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,43 @@
|
||||
<p>如果一个密码满足以下所有条件,我们称它是一个 <strong>强</strong> 密码:</p>
|
||||
|
||||
<ul>
|
||||
<li>它有至少 <code>8</code> 个字符。</li>
|
||||
<li>至少包含 <strong>一个小写英文</strong> 字母。</li>
|
||||
<li>至少包含 <strong>一个大写英文</strong> 字母。</li>
|
||||
<li>至少包含 <strong>一个数字</strong> 。</li>
|
||||
<li>至少包含 <strong>一个特殊字符</strong> 。特殊字符为:<code>"!@#$%^&*()-+"</code> 中的一个。</li>
|
||||
<li>它 <strong>不</strong> 包含 <code>2</code> 个连续相同的字符(比方说 <code>"aab"</code> 不符合该条件,但是 <code>"aba"</code> 符合该条件)。</li>
|
||||
</ul>
|
||||
|
||||
<p>给你一个字符串 <code>password</code> ,如果它是一个 <strong>强</strong> 密码,返回 <code>true</code>,否则返回 <code>false</code> 。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>password = "IloveLe3tcode!"
|
||||
<b>输出:</b>true
|
||||
<b>解释:</b>密码满足所有的要求,所以我们返回 true 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>password = "Me+You--IsMyDream"
|
||||
<b>输出:</b>false
|
||||
<b>解释:</b>密码不包含数字,且包含 2 个连续相同的字符。所以我们返回 false 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>password = "1aB!"
|
||||
<b>输出:</b>false
|
||||
<b>解释:</b>密码不符合长度要求。所以我们返回 false 。</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= password.length <= 100</code></li>
|
||||
<li><code>password</code> 包含字母,数字和 <code>"!@#$%^&*()-+"</code> 这些特殊字符。</li>
|
||||
</ul>
|
@ -0,0 +1,46 @@
|
||||
<p>给你两个字符串 <code>s</code> 和 <code>sub</code> 。同时给你一个二维字符数组 <code>mappings</code> ,其中 <code>mappings[i] = [old<sub>i</sub>, new<sub>i</sub>]</code> 表示你可以将 <code>sub</code> 中任意数目的 <code>old<sub>i</sub></code> 字符替换为 <code>new<sub>i</sub></code> 。<code>sub</code> 中每个字符 <b>不能</b> 被替换超过一次。</p>
|
||||
|
||||
<p>如果使用 <code>mappings</code> 替换 0 个或者若干个字符,可以将 <code>sub</code> 变成 <code>s</code> 的一个子字符串,请你返回 <code>true</code>,否则返回 <code>false</code> 。</p>
|
||||
|
||||
<p>一个 <strong>子字符串</strong> 是字符串中连续非空的字符序列。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>s = "fool3e7bar", sub = "leet", mappings = [["e","3"],["t","7"],["t","8"]]
|
||||
<b>输出:</b>true
|
||||
<b>解释:</b>将 sub 中第一个 'e' 用 '3' 替换,将 't' 用 '7' 替换。
|
||||
现在 sub = "l3e7" ,它是 s 的子字符串,所以我们返回 true 。</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>s = "fooleetbar", sub = "f00l", mappings = [["o","0"]]
|
||||
<b>输出:</b>false
|
||||
<b>解释:</b>字符串 "f00l" 不是 s 的子串且没有可以进行的修改。
|
||||
注意我们不能用 'o' 替换 '0' 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>s = "Fool33tbaR", sub = "leetd", mappings = [["e","3"],["t","7"],["t","8"],["d","b"],["p","b"]]
|
||||
<b>输出:</b>true
|
||||
<b>解释:</b>将 sub 里第一个和第二个 'e' 用 '3' 替换,用 'b' 替换 sub 里的 'd' 。
|
||||
得到 sub = "l33tb" ,它是 s 的子字符串,所以我们返回 true 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= sub.length <= s.length <= 5000</code></li>
|
||||
<li><code>0 <= mappings.length <= 1000</code></li>
|
||||
<li><code>mappings[i].length == 2</code></li>
|
||||
<li><code>old<sub>i</sub> != new<sub>i</sub></code></li>
|
||||
<li><code>s</code> 和 <code>sub</code> 只包含大写和小写英文字母和数字。</li>
|
||||
<li><code>old<sub>i</sub></code> 和 <code>new<sub>i</sub></code> 是大写、小写字母或者是个数字。</li>
|
||||
</ul>
|
@ -0,0 +1,47 @@
|
||||
<p>一个数字的 <strong>分数</strong> 定义为数组之和 <strong>乘以</strong> 数组的长度。</p>
|
||||
|
||||
<ul>
|
||||
<li>比方说,<code>[1, 2, 3, 4, 5]</code> 的分数为 <code>(1 + 2 + 3 + 4 + 5) * 5 = 75</code> 。</li>
|
||||
</ul>
|
||||
|
||||
<p>给你一个正整数数组 <code>nums</code> 和一个整数 <code>k</code> ,请你返回 <code>nums</code> 中分数 <strong>严格小于 </strong><code>k</code> 的 <strong>非空整数子数组数目</strong>。</p>
|
||||
|
||||
<p><strong>子数组</strong> 是数组中的一个连续元素序列。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>nums = [2,1,4,3,5], k = 10
|
||||
<b>输出:</b>6
|
||||
<strong>解释:</strong>
|
||||
有 6 个子数组的分数小于 10 :
|
||||
- [2] 分数为 2 * 1 = 2 。
|
||||
- [1] 分数为 1 * 1 = 1 。
|
||||
- [4] 分数为 4 * 1 = 4 。
|
||||
- [3] 分数为 3 * 1 = 3 。
|
||||
- [5] 分数为 5 * 1 = 5 。
|
||||
- [2,1] 分数为 (2 + 1) * 2 = 6 。
|
||||
注意,子数组 [1,4] 和 [4,3,5] 不符合要求,因为它们的分数分别为 10 和 36,但我们要求子数组的分数严格小于 10 。</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>nums = [1,1,1], k = 5
|
||||
<b>输出:</b>5
|
||||
<strong>解释:</strong>
|
||||
除了 [1,1,1] 以外每个子数组分数都小于 5 。
|
||||
[1,1,1] 分数为 (1 + 1 + 1) * 3 = 9 ,大于 5 。
|
||||
所以总共有 5 个子数组得分小于 5 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= nums[i] <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= k <= 10<sup>15</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,46 @@
|
||||
<p>给你一个下标从 <strong>0</strong> 开始的整数矩阵 <code>grid</code> ,矩阵大小为 <code>m x n</code> ,由从 <code>0</code> 到 <code>m * n - 1</code> 的不同整数组成。你可以在此矩阵中,从一个单元格移动到 <strong>下一行</strong> 的任何其他单元格。如果你位于单元格 <code>(x, y)</code> ,且满足 <code>x < m - 1</code> ,你可以移动到 <code>(x + 1, 0)</code>, <code>(x + 1, 1)</code>, ..., <code>(x + 1, n - 1)</code><strong> </strong>中的任何一个单元格。<strong>注意:</strong> 在最后一行中的单元格不能触发移动。</p>
|
||||
|
||||
<p>每次可能的移动都需要付出对应的代价,代价用一个下标从 <strong>0</strong> 开始的二维数组 <code>moveCost</code> 表示,该数组大小为 <code>(m * n) x n</code> ,其中 <code>moveCost[i][j]</code> 是从值为 <code>i</code> 的单元格移动到下一行第 <code>j</code> 列单元格的代价。从 <code>grid</code> 最后一行的单元格移动的代价可以忽略。</p>
|
||||
|
||||
<p><code>grid</code> 一条路径的代价是:所有路径经过的单元格的 <strong>值之和</strong> 加上 所有移动的 <strong>代价之和 </strong>。从 <strong>第一行</strong> 任意单元格出发,返回到达 <strong>最后一行</strong> 任意单元格的最小路径代价<em>。</em></p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/04/28/griddrawio-2.png" style="width: 301px; height: 281px;" /></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>grid = [[5,3],[4,0],[2,1]], moveCost = [[9,8],[1,5],[10,12],[18,6],[2,4],[14,3]]
|
||||
<strong>输出:</strong>17
|
||||
<strong>解释:</strong>最小代价的路径是 5 -> 0 -> 1 。
|
||||
- 路径途经单元格值之和 5 + 0 + 1 = 6 。
|
||||
- 从 5 移动到 0 的代价为 3 。
|
||||
- 从 0 移动到 1 的代价为 8 。
|
||||
路径总代价为 6 + 3 + 8 = 17 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>grid = [[5,1,2],[4,0,3]], moveCost = [[12,10,15],[20,23,8],[21,7,1],[8,1,13],[9,10,25],[5,3,2]]
|
||||
<strong>输出:</strong>6
|
||||
<strong>解释:</strong>
|
||||
最小代价的路径是 2 -> 3 。
|
||||
- 路径途经单元格值之和 2 + 3 = 5 。
|
||||
- 从 2 移动到 3 的代价为 1 。
|
||||
路径总代价为 5 + 1 = 6 。</pre>
|
||||
|
||||
<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 <= 50</code></li>
|
||||
<li><code>grid</code> 由从 <code>0</code> 到 <code>m * n - 1</code> 的不同整数组成</li>
|
||||
<li><code>moveCost.length == m * n</code></li>
|
||||
<li><code>moveCost[i].length == n</code></li>
|
||||
<li><code>1 <= moveCost[i][j] <= 100</code></li>
|
||||
</ul>
|
@ -0,0 +1,57 @@
|
||||
<p>给你一个下标从 <strong>0</strong> 开始的二维整数数组 <code>brackets</code> ,其中 <code>brackets[i] = [upper<sub>i</sub>, percent<sub>i</sub>]</code> ,表示第 <code>i</code> 个税级的上限是 <code>upper<sub>i</sub></code> ,征收的税率为 <code>percent<sub>i</sub></code> 。税级按上限 <strong>从低到高排序</strong>(在满足 <code>0 < i < brackets.length</code> 的前提下,<code>upper<sub>i-1</sub> < upper<sub>i</sub></code>)。</p>
|
||||
|
||||
<p>税款计算方式如下:</p>
|
||||
|
||||
<ul>
|
||||
<li>不超过 <code>upper<sub>0</sub></code> 的收入按税率 <code>percent<sub>0</sub></code> 缴纳</li>
|
||||
<li>接着 <code>upper<sub>1</sub> - upper<sub>0</sub></code> 的部分按税率 <code>percent<sub>1</sub></code> 缴纳</li>
|
||||
<li>然后 <code>upper<sub>2</sub> - upper<sub>1</sub></code> 的部分按税率 <code>percent<sub>2</sub></code> 缴纳</li>
|
||||
<li>以此类推</li>
|
||||
</ul>
|
||||
|
||||
<p>给你一个整数 <code>income</code> 表示你的总收入。返回你需要缴纳的税款总额。与标准答案误差不超 <code>10<sup>-5</sup></code> 的结果将被视作正确答案。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>brackets = [[3,50],[7,10],[12,25]], income = 10
|
||||
<strong>输出:</strong>2.65000
|
||||
<strong>解释:</strong>
|
||||
前 $3 的税率为 50% 。需要支付税款 $3 * 50% = $1.50 。
|
||||
接下来 $7 - $3 = $4 的税率为 10% 。需要支付税款 $4 * 10% = $0.40 。
|
||||
最后 $10 - $7 = $3 的税率为 25% 。需要支付税款 $3 * 25% = $0.75 。
|
||||
需要支付的税款总计 $1.50 + $0.40 + $0.75 = $2.65 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>brackets = [[1,0],[4,25],[5,50]], income = 2
|
||||
<strong>输出:</strong>0.25000
|
||||
<strong>解释:</strong>
|
||||
前 $1 的税率为 0% 。需要支付税款 $1 * 0% = $0 。
|
||||
剩下 $1 的税率为 25% 。需要支付税款 $1 * 25% = $0.25 。
|
||||
需要支付的税款总计 $0 + $0.25 = $0.25 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>brackets = [[2,50]], income = 0
|
||||
<strong>输出:</strong>0.00000
|
||||
<strong>解释:</strong>
|
||||
没有收入,无需纳税,需要支付的税款总计 $0 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= brackets.length <= 100</code></li>
|
||||
<li><code>1 <= upper<sub>i</sub> <= 1000</code></li>
|
||||
<li><code>0 <= percent<sub>i</sub> <= 100</code></li>
|
||||
<li><code>0 <= income <= 1000</code></li>
|
||||
<li><code>upper<sub>i</sub></code> 按递增顺序排列</li>
|
||||
<li><code>upper<sub>i</sub></code> 中的所有值 <strong>互不相同</strong></li>
|
||||
<li>最后一个税级的上限大于等于 <code>income</code></li>
|
||||
</ul>
|
@ -0,0 +1,49 @@
|
||||
<p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
|
||||
|
||||
<ol>
|
||||
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<sub>B</sub></code>.</li>
|
||||
<li>Swap the first letters of <code>idea<sub>A</sub></code> and <code>idea<sub>B</sub></code> with each other.</li>
|
||||
<li>If <strong>both</strong> of the new names are not found in the original <code>ideas</code>, then the name <code>idea<sub>A</sub> idea<sub>B</sub></code> (the <strong>concatenation</strong> of <code>idea<sub>A</sub></code> and <code>idea<sub>B</sub></code>, separated by a space) is a valid company name.</li>
|
||||
<li>Otherwise, it is not a valid name.</li>
|
||||
</ol>
|
||||
|
||||
<p>Return <em>the number of <strong>distinct</strong> valid names for the company</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> ideas = ["coffee","donuts","time","toffee"]
|
||||
<strong>Output:</strong> 6
|
||||
<strong>Explanation:</strong> The following selections are valid:
|
||||
- ("coffee", "donuts"): The company name created is "doffee conuts".
|
||||
- ("donuts", "coffee"): The company name created is "conuts doffee".
|
||||
- ("donuts", "time"): The company name created is "tonuts dime".
|
||||
- ("donuts", "toffee"): The company name created is "tonuts doffee".
|
||||
- ("time", "donuts"): The company name created is "dime tonuts".
|
||||
- ("toffee", "donuts"): The company name created is "doffee tonuts".
|
||||
Therefore, there are a total of 6 distinct company names.
|
||||
|
||||
The following are some examples of invalid selections:
|
||||
- ("coffee", "time"): The name "toffee" formed after swapping already exists in the original array.
|
||||
- ("time", "toffee"): Both names are still the same after swapping and exist in the original array.
|
||||
- ("coffee", "toffee"): Both names formed after swapping already exist in the original array.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> ideas = ["lack","back"]
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong> There are no valid selections. Therefore, 0 is returned.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= ideas.length <= 5 * 10<sup>4</sup></code></li>
|
||||
<li><code>1 <= ideas[i].length <= 10</code></li>
|
||||
<li><code>ideas[i]</code> consists of lowercase English letters.</li>
|
||||
<li>All the strings in <code>ideas</code> are <strong>unique</strong>.</li>
|
||||
</ul>
|
@ -0,0 +1,40 @@
|
||||
<p>You are given an integer array <code>cookies</code>, where <code>cookies[i]</code> denotes the number of cookies in the <code>i<sup>th</sup></code> bag. You are also given an integer <code>k</code> that denotes the number of children to distribute <strong>all</strong> the bags of cookies to. All the cookies in the same bag must go to the same child and cannot be split up.</p>
|
||||
|
||||
<p>The <strong>unfairness</strong> of a distribution is defined as the <strong>maximum</strong> <strong>total</strong> cookies obtained by a single child in the distribution.</p>
|
||||
|
||||
<p>Return <em>the <strong>minimum</strong> unfairness of all distributions</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> cookies = [8,15,10,20,8], k = 2
|
||||
<strong>Output:</strong> 31
|
||||
<strong>Explanation:</strong> One optimal distribution is [8,15,8] and [10,20]
|
||||
- The 1<sup>st</sup> child receives [8,15,8] which has a total of 8 + 15 + 8 = 31 cookies.
|
||||
- The 2<sup>nd</sup> child receives [10,20] which has a total of 10 + 20 = 30 cookies.
|
||||
The unfairness of the distribution is max(31,30) = 31.
|
||||
It can be shown that there is no distribution with an unfairness less than 31.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> cookies = [6,1,3,2,2,4,1,2], k = 3
|
||||
<strong>Output:</strong> 7
|
||||
<strong>Explanation:</strong> One optimal distribution is [6,1], [3,2,2], and [4,1,2]
|
||||
- The 1<sup>st</sup> child receives [6,1] which has a total of 6 + 1 = 7 cookies.
|
||||
- The 2<sup>nd</sup> child receives [3,2,2] which has a total of 3 + 2 + 2 = 7 cookies.
|
||||
- The 3<sup>rd</sup> child receives [4,1,2] which has a total of 4 + 1 + 2 = 7 cookies.
|
||||
The unfairness of the distribution is max(7,7,7) = 7.
|
||||
It can be shown that there is no distribution with an unfairness less than 7.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= cookies.length <= 8</code></li>
|
||||
<li><code>1 <= cookies[i] <= 10<sup>5</sup></code></li>
|
||||
<li><code>2 <= k <= cookies.length</code></li>
|
||||
</ul>
|
@ -0,0 +1,41 @@
|
||||
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</sup></code> potion.</p>
|
||||
|
||||
<p>You are also given an integer <code>success</code>. A spell and potion pair is considered <strong>successful</strong> if the <strong>product</strong> of their strengths is <strong>at least</strong> <code>success</code>.</p>
|
||||
|
||||
<p>Return <em>an integer array </em><code>pairs</code><em> of length </em><code>n</code><em> where </em><code>pairs[i]</code><em> is the number of <strong>potions</strong> that will form a successful pair with the </em><code>i<sup>th</sup></code><em> spell.</em></p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> spells = [5,1,3], potions = [1,2,3,4,5], success = 7
|
||||
<strong>Output:</strong> [4,0,3]
|
||||
<strong>Explanation:</strong>
|
||||
- 0<sup>th</sup> spell: 5 * [1,2,3,4,5] = [5,<u><strong>10</strong></u>,<u><strong>15</strong></u>,<u><strong>20</strong></u>,<u><strong>25</strong></u>]. 4 pairs are successful.
|
||||
- 1<sup>st</sup> spell: 1 * [1,2,3,4,5] = [1,2,3,4,5]. 0 pairs are successful.
|
||||
- 2<sup>nd</sup> spell: 3 * [1,2,3,4,5] = [3,6,<u><strong>9</strong></u>,<u><strong>12</strong></u>,<u><strong>15</strong></u>]. 3 pairs are successful.
|
||||
Thus, [4,0,3] is returned.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> spells = [3,1,2], potions = [8,5,8], success = 16
|
||||
<strong>Output:</strong> [2,0,2]
|
||||
<strong>Explanation:</strong>
|
||||
- 0<sup>th</sup> spell: 3 * [8,5,8] = [<u><strong>24</strong></u>,15,<u><strong>24</strong></u>]. 2 pairs are successful.
|
||||
- 1<sup>st</sup> spell: 1 * [8,5,8] = [8,5,8]. 0 pairs are successful.
|
||||
- 2<sup>nd</sup> spell: 2 * [8,5,8] = [<strong><u>16</u></strong>,10,<u><strong>16</strong></u>]. 2 pairs are successful.
|
||||
Thus, [2,0,2] is returned.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>n == spells.length</code></li>
|
||||
<li><code>m == potions.length</code></li>
|
||||
<li><code>1 <= n, m <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= spells[i], potions[i] <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= success <= 10<sup>10</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,44 @@
|
||||
<p>A password is said to be <strong>strong</strong> if it satisfies all the following criteria:</p>
|
||||
|
||||
<ul>
|
||||
<li>It has at least <code>8</code> characters.</li>
|
||||
<li>It contains at least <strong>one lowercase</strong> letter.</li>
|
||||
<li>It contains at least <strong>one uppercase</strong> letter.</li>
|
||||
<li>It contains at least <strong>one digit</strong>.</li>
|
||||
<li>It contains at least <strong>one special character</strong>. The special characters are the characters in the following string: <code>"!@#$%^&*()-+"</code>.</li>
|
||||
<li>It does <strong>not</strong> contain <code>2</code> of the same character in adjacent positions (i.e., <code>"aab"</code> violates this condition, but <code>"aba"</code> does not).</li>
|
||||
</ul>
|
||||
|
||||
<p>Given a string <code>password</code>, return <code>true</code><em> if it is a <strong>strong</strong> password</em>. Otherwise, return <code>false</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> password = "IloveLe3tcode!"
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong> The password meets all the requirements. Therefore, we return true.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> password = "Me+You--IsMyDream"
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation:</strong> The password does not contain a digit and also contains 2 of the same character in adjacent positions. Therefore, we return false.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> password = "1aB!"
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation:</strong> The password does not meet the length requirement. Therefore, we return false.</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= password.length <= 100</code></li>
|
||||
<li><code>password</code> consists of letters, digits, and special characters: <code>"!@#$%^&*()-+"</code>.</li>
|
||||
</ul>
|
@ -0,0 +1,45 @@
|
||||
<p>You are given two strings <code>s</code> and <code>sub</code>. You are also given a 2D character array <code>mappings</code> where <code>mappings[i] = [old<sub>i</sub>, new<sub>i</sub>]</code> indicates that you may <strong>replace</strong> any number of <code>old<sub>i</sub></code> characters of <code>sub</code> with <code>new<sub>i</sub></code>. Each character in <code>sub</code> <strong>cannot</strong> be replaced more than once.</p>
|
||||
|
||||
<p>Return <code>true</code><em> if it is possible to make </em><code>sub</code><em> a substring of </em><code>s</code><em> by replacing zero or more characters according to </em><code>mappings</code>. Otherwise, return <code>false</code>.</p>
|
||||
|
||||
<p>A <strong>substring</strong> is a contiguous non-empty sequence of characters within a string.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "fool3e7bar", sub = "leet", mappings = [["e","3"],["t","7"],["t","8"]]
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong> Replace the first 'e' in sub with '3' and 't' in sub with '7'.
|
||||
Now sub = "l3e7" is a substring of s, so we return true.</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "fooleetbar", sub = "f00l", mappings = [["o","0"]]
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation:</strong> The string "f00l" is not a substring of s and no replacements can be made.
|
||||
Note that we cannot replace '0' with 'o'.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "Fool33tbaR", sub = "leetd", mappings = [["e","3"],["t","7"],["t","8"],["d","b"],["p","b"]]
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong> Replace the first and second 'e' in sub with '3' and 'd' in sub with 'b'.
|
||||
Now sub = "l33tb" is a substring of s, so we return true.
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= sub.length <= s.length <= 5000</code></li>
|
||||
<li><code>0 <= mappings.length <= 1000</code></li>
|
||||
<li><code>mappings[i].length == 2</code></li>
|
||||
<li><code>old<sub>i</sub> != new<sub>i</sub></code></li>
|
||||
<li><code>s</code> and <code>sub</code> consist of uppercase and lowercase English letters and digits.</li>
|
||||
<li><code>old<sub>i</sub></code> and <code>new<sub>i</sub></code> are either uppercase or lowercase English letters or digits.</li>
|
||||
</ul>
|
@ -0,0 +1,45 @@
|
||||
<p>The <strong>score</strong> of an array is defined as the <strong>product</strong> of its sum and its length.</p>
|
||||
|
||||
<ul>
|
||||
<li>For example, the score of <code>[1, 2, 3, 4, 5]</code> is <code>(1 + 2 + 3 + 4 + 5) * 5 = 75</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Given a positive integer array <code>nums</code> and an integer <code>k</code>, return <em>the <strong>number of non-empty subarrays</strong> of</em> <code>nums</code> <em>whose score is <strong>strictly less</strong> than</em> <code>k</code>.</p>
|
||||
|
||||
<p>A <strong>subarray</strong> is a contiguous sequence of elements within an array.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [2,1,4,3,5], k = 10
|
||||
<strong>Output:</strong> 6
|
||||
<strong>Explanation:</strong>
|
||||
The 6 subarrays having scores less than 10 are:
|
||||
- [2] with score 2 * 1 = 2.
|
||||
- [1] with score 1 * 1 = 1.
|
||||
- [4] with score 4 * 1 = 4.
|
||||
- [3] with score 3 * 1 = 3.
|
||||
- [5] with score 5 * 1 = 5.
|
||||
- [2,1] with score (2 + 1) * 2 = 6.
|
||||
Note that subarrays such as [1,4] and [4,3,5] are not considered because their scores are 10 and 36 respectively, while we need scores strictly less than 10.</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,1,1], k = 5
|
||||
<strong>Output:</strong> 5
|
||||
<strong>Explanation:</strong>
|
||||
Every subarray except [1,1,1] has a score less than 5.
|
||||
[1,1,1] has a score (1 + 1 + 1) * 3 = 9, which is greater than 5.
|
||||
Thus, there are 5 subarrays having scores less than 5.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= nums[i] <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= k <= 10<sup>15</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,42 @@
|
||||
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> integer matrix <code>grid</code> consisting of <strong>distinct</strong> integers from <code>0</code> to <code>m * n - 1</code>. You can move in this matrix from a cell to any other cell in the <strong>next</strong> row. That is, if you are in cell <code>(x, y)</code> such that <code>x < m - 1</code>, you can move to any of the cells <code>(x + 1, 0)</code>, <code>(x + 1, 1)</code>, ..., <code>(x + 1, n - 1)</code>. <strong>Note</strong> that it is not possible to move from cells in the last row.</p>
|
||||
|
||||
<p>Each possible move has a cost given by a <strong>0-indexed</strong> 2D array <code>moveCost</code> of size <code>(m * n) x n</code>, where <code>moveCost[i][j]</code> is the cost of moving from a cell with value <code>i</code> to a cell in column <code>j</code> of the next row. The cost of moving from cells in the last row of <code>grid</code> can be ignored.</p>
|
||||
|
||||
<p>The cost of a path in <code>grid</code> is the <strong>sum</strong> of all values of cells visited plus the <strong>sum</strong> of costs of all the moves made. Return <em>the <strong>minimum</strong> cost of a path that starts from any cell in the <strong>first</strong> row and ends at any cell in the <strong>last</strong> row.</em></p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/04/28/griddrawio-2.png" style="width: 301px; height: 281px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> grid = [[5,3],[4,0],[2,1]], moveCost = [[9,8],[1,5],[10,12],[18,6],[2,4],[14,3]]
|
||||
<strong>Output:</strong> 17
|
||||
<strong>Explanation: </strong>The path with the minimum possible cost is the path 5 -> 0 -> 1.
|
||||
- The sum of the values of cells visited is 5 + 0 + 1 = 6.
|
||||
- The cost of moving from 5 to 0 is 3.
|
||||
- The cost of moving from 0 to 1 is 8.
|
||||
So the total cost of the path is 6 + 3 + 8 = 17.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> grid = [[5,1,2],[4,0,3]], moveCost = [[12,10,15],[20,23,8],[21,7,1],[8,1,13],[9,10,25],[5,3,2]]
|
||||
<strong>Output:</strong> 6
|
||||
<strong>Explanation:</strong> The path with the minimum possible cost is the path 2 -> 3.
|
||||
- The sum of the values of cells visited is 2 + 3 = 5.
|
||||
- The cost of moving from 2 to 3 is 1.
|
||||
So the total cost of this path is 5 + 1 = 6.
|
||||
</pre>
|
||||
|
||||
<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 <= 50</code></li>
|
||||
<li><code>grid</code> consists of distinct integers from <code>0</code> to <code>m * n - 1</code>.</li>
|
||||
<li><code>moveCost.length == m * n</code></li>
|
||||
<li><code>moveCost[i].length == n</code></li>
|
||||
<li><code>1 <= moveCost[i][j] <= 100</code></li>
|
||||
</ul>
|
@ -0,0 +1,57 @@
|
||||
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>brackets</code> where <code>brackets[i] = [upper<sub>i</sub>, percent<sub>i</sub>]</code> means that the <code>i<sup>th</sup></code> tax bracket has an upper bound of <code>upper<sub>i</sub></code> and is taxed at a rate of <code>percent<sub>i</sub></code>. The brackets are <strong>sorted</strong> by upper bound (i.e. <code>upper<sub>i-1</sub> < upper<sub>i</sub></code> for <code>0 < i < brackets.length</code>).</p>
|
||||
|
||||
<p>Tax is calculated as follows:</p>
|
||||
|
||||
<ul>
|
||||
<li>The first <code>upper<sub>0</sub></code> dollars earned are taxed at a rate of <code>percent<sub>0</sub></code>.</li>
|
||||
<li>The next <code>upper<sub>1</sub> - upper<sub>0</sub></code> dollars earned are taxed at a rate of <code>percent<sub>1</sub></code>.</li>
|
||||
<li>The next <code>upper<sub>2</sub> - upper<sub>1</sub></code> dollars earned are taxed at a rate of <code>percent<sub>2</sub></code>.</li>
|
||||
<li>And so on.</li>
|
||||
</ul>
|
||||
|
||||
<p>You are given an integer <code>income</code> representing the amount of money you earned. Return <em>the amount of money that you have to pay in taxes.</em> Answers within <code>10<sup>-5</sup></code> of the actual answer will be accepted.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> brackets = [[3,50],[7,10],[12,25]], income = 10
|
||||
<strong>Output:</strong> 2.65000
|
||||
<strong>Explanation:</strong>
|
||||
Based on your income, you have 3 dollars in the 1<sup>st</sup> tax bracket, 4 dollars in the 2<sup>nd</sup> tax bracket, and 3 dollars in the 3<sup>rd</sup> tax bracket.
|
||||
The tax rate for the three tax brackets is 50%, 10%, and 25%, respectively.
|
||||
In total, you pay $3 * 50% + $4 * 10% + $3 * 25% = $2.65 in taxes.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> brackets = [[1,0],[4,25],[5,50]], income = 2
|
||||
<strong>Output:</strong> 0.25000
|
||||
<strong>Explanation:</strong>
|
||||
Based on your income, you have 1 dollar in the 1<sup>st</sup> tax bracket and 1 dollar in the 2<sup>nd</sup> tax bracket.
|
||||
The tax rate for the two tax brackets is 0% and 25%, respectively.
|
||||
In total, you pay $1 * 0% + $1 * 25% = $0.25 in taxes.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> brackets = [[2,50]], income = 0
|
||||
<strong>Output:</strong> 0.00000
|
||||
<strong>Explanation:</strong>
|
||||
You have no income to tax, so you have to pay a total of $0 in taxes.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= brackets.length <= 100</code></li>
|
||||
<li><code>1 <= upper<sub>i</sub> <= 1000</code></li>
|
||||
<li><code>0 <= percent<sub>i</sub> <= 100</code></li>
|
||||
<li><code>0 <= income <= 1000</code></li>
|
||||
<li><code>upper<sub>i</sub></code> is sorted in ascending order.</li>
|
||||
<li>All the values of <code>upper<sub>i</sub></code> are <strong>unique</strong>.</li>
|
||||
<li>The upper bound of the last tax bracket is greater than or equal to <code>income</code>.</li>
|
||||
</ul>
|
File diff suppressed because it is too large
Load Diff
55
leetcode/originData/[no content]arrange-table-by-gender.json
Normal file
55
leetcode/originData/[no content]arrange-table-by-gender.json
Normal file
@ -0,0 +1,55 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2441",
|
||||
"questionFrontendId": "2308",
|
||||
"boundTopicId": null,
|
||||
"title": "Arrange Table by Gender",
|
||||
"titleSlug": "arrange-table-by-gender",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Medium",
|
||||
"likes": 7,
|
||||
"dislikes": 4,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"exampleTestcases": null,
|
||||
"categoryTitle": "Database",
|
||||
"contributors": [],
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"123\", \"totalSubmission\": \"162\", \"totalAcceptedRaw\": 123, \"totalSubmissionRaw\": 162, \"acRate\": \"75.9%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\": {\"Genders\": [\"user_id\", \"gender\"]}, \"rows\": {\"Genders\": [[4, \"male\"], [7, \"female\"], [2, \"other\"], [5, \"male\"], [3, \"female\"], [8, \"male\"], [6, \"other\"], [1, \"other\"], [9, \"female\"]]}}",
|
||||
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Genders (user_id int, gender ENUM('female', 'other', 'male'))\"\n ],\n \"mssql\": [\n \"Create table Genders (user_id int, gender VARCHAR(6) NOT NULL CHECK (gender IN ('female', 'other', 'male')))\"\n ],\n \"oraclesql\": [\n \"Create table Genders (user_id int, gender VARCHAR(6) NOT NULL CHECK (gender IN ('female', 'other', 'male')))\"\n ],\n \"database\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Create table If Not Exists Genders (user_id int, gender ENUM('female', 'other', 'male'))",
|
||||
"Truncate table Genders",
|
||||
"insert into Genders (user_id, gender) values ('4', 'male')",
|
||||
"insert into Genders (user_id, gender) values ('7', 'female')",
|
||||
"insert into Genders (user_id, gender) values ('2', 'other')",
|
||||
"insert into Genders (user_id, gender) values ('5', 'male')",
|
||||
"insert into Genders (user_id, gender) values ('3', 'female')",
|
||||
"insert into Genders (user_id, gender) values ('8', 'male')",
|
||||
"insert into Genders (user_id, gender) values ('6', 'other')",
|
||||
"insert into Genders (user_id, gender) values ('1', 'other')",
|
||||
"insert into Genders (user_id, gender) values ('9', 'female')"
|
||||
],
|
||||
"enableRunCode": true,
|
||||
"enableTestMode": false,
|
||||
"enableDebugger": false,
|
||||
"envInfo": "{\"mysql\": [\"MySQL\", \"<p><code>MySQL 8.0</code>.</p>\"], \"mssql\": [\"MS SQL Server\", \"<p><code>mssql server 2019</code>.</p>\"], \"oraclesql\": [\"Oracle\", \"<p><code>Oracle Sql 11.2</code>.</p>\"]}",
|
||||
"libraryUrl": null,
|
||||
"adminUrl": null,
|
||||
"challengeQuestion": null,
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
84
leetcode/originData/[no content]jump-game-viii.json
Normal file
84
leetcode/originData/[no content]jump-game-viii.json
Normal file
File diff suppressed because one or more lines are too long
@ -0,0 +1,59 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2440",
|
||||
"questionFrontendId": "2298",
|
||||
"boundTopicId": null,
|
||||
"title": "Tasks Count in the Weekend",
|
||||
"titleSlug": "tasks-count-in-the-weekend",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Medium",
|
||||
"likes": 6,
|
||||
"dislikes": 2,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"exampleTestcases": null,
|
||||
"categoryTitle": "Database",
|
||||
"contributors": [],
|
||||
"topicTags": [
|
||||
{
|
||||
"name": "Database",
|
||||
"slug": "database",
|
||||
"translatedName": null,
|
||||
"__typename": "TopicTagNode"
|
||||
}
|
||||
],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"255\", \"totalSubmission\": \"314\", \"totalAcceptedRaw\": 255, \"totalSubmissionRaw\": 314, \"acRate\": \"81.2%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\": {\"Tasks\": [\"task_id\", \"assignee_id\", \"submit_date\"]}, \"rows\": {\"Tasks\": [[1, 1, \"2022-06-13\"], [2, 6, \"2022-06-14\"], [3, 6, \"2022-06-15\"], [4, 3, \"2022-06-18\"], [5, 5, \"2022-06-19\"], [6, 7, \"2022-06-19\"]]}}",
|
||||
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Tasks (task_id int, assignee_id int, submit_date date)\"\n ],\n \"mssql\": [\n \"Create table Tasks (task_id int, assignee_id int, submit_date date)\"\n ],\n \"oraclesql\": [\n \"Create table Tasks (task_id int, assignee_id int, submit_date date)\",\n \"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"\n ],\n \"database\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Create table If Not Exists Tasks (task_id int, assignee_id int, submit_date date)",
|
||||
"Truncate table Tasks",
|
||||
"insert into Tasks (task_id, assignee_id, submit_date) values ('1', '1', '2022-06-13')",
|
||||
"insert into Tasks (task_id, assignee_id, submit_date) values ('2', '6', '2022-06-14')",
|
||||
"insert into Tasks (task_id, assignee_id, submit_date) values ('3', '6', '2022-06-15')",
|
||||
"insert into Tasks (task_id, assignee_id, submit_date) values ('4', '3', '2022-06-18')",
|
||||
"insert into Tasks (task_id, assignee_id, submit_date) values ('5', '5', '2022-06-19')",
|
||||
"insert into Tasks (task_id, assignee_id, submit_date) values ('6', '7', '2022-06-19')"
|
||||
],
|
||||
"enableRunCode": true,
|
||||
"enableTestMode": false,
|
||||
"enableDebugger": false,
|
||||
"envInfo": "{\"mysql\": [\"MySQL\", \"<p><code>MySQL 8.0</code>.</p>\"], \"mssql\": [\"MS SQL Server\", \"<p><code>mssql server 2019</code>.</p>\"], \"oraclesql\": [\"Oracle\", \"<p><code>Oracle Sql 11.2</code>.</p>\"]}",
|
||||
"libraryUrl": null,
|
||||
"adminUrl": null,
|
||||
"challengeQuestion": null,
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
168
leetcode/originData/calculate-amount-paid-in-taxes.json
Normal file
168
leetcode/originData/calculate-amount-paid-in-taxes.json
Normal file
File diff suppressed because one or more lines are too long
181
leetcode/originData/count-subarrays-with-score-less-than-k.json
Normal file
181
leetcode/originData/count-subarrays-with-score-less-than-k.json
Normal file
File diff suppressed because one or more lines are too long
186
leetcode/originData/fair-distribution-of-cookies.json
Normal file
186
leetcode/originData/fair-distribution-of-cookies.json
Normal file
File diff suppressed because one or more lines are too long
180
leetcode/originData/match-substring-after-replacement.json
Normal file
180
leetcode/originData/match-substring-after-replacement.json
Normal file
File diff suppressed because one or more lines are too long
174
leetcode/originData/minimum-path-cost-in-a-grid.json
Normal file
174
leetcode/originData/minimum-path-cost-in-a-grid.json
Normal file
File diff suppressed because one or more lines are too long
188
leetcode/originData/naming-a-company.json
Normal file
188
leetcode/originData/naming-a-company.json
Normal file
File diff suppressed because one or more lines are too long
162
leetcode/originData/strong-password-checker-ii.json
Normal file
162
leetcode/originData/strong-password-checker-ii.json
Normal file
File diff suppressed because one or more lines are too long
181
leetcode/originData/successful-pairs-of-spells-and-potions.json
Normal file
181
leetcode/originData/successful-pairs-of-spells-and-potions.json
Normal file
File diff suppressed because one or more lines are too long
57
leetcode/problem/calculate-amount-paid-in-taxes.html
Normal file
57
leetcode/problem/calculate-amount-paid-in-taxes.html
Normal file
@ -0,0 +1,57 @@
|
||||
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>brackets</code> where <code>brackets[i] = [upper<sub>i</sub>, percent<sub>i</sub>]</code> means that the <code>i<sup>th</sup></code> tax bracket has an upper bound of <code>upper<sub>i</sub></code> and is taxed at a rate of <code>percent<sub>i</sub></code>. The brackets are <strong>sorted</strong> by upper bound (i.e. <code>upper<sub>i-1</sub> < upper<sub>i</sub></code> for <code>0 < i < brackets.length</code>).</p>
|
||||
|
||||
<p>Tax is calculated as follows:</p>
|
||||
|
||||
<ul>
|
||||
<li>The first <code>upper<sub>0</sub></code> dollars earned are taxed at a rate of <code>percent<sub>0</sub></code>.</li>
|
||||
<li>The next <code>upper<sub>1</sub> - upper<sub>0</sub></code> dollars earned are taxed at a rate of <code>percent<sub>1</sub></code>.</li>
|
||||
<li>The next <code>upper<sub>2</sub> - upper<sub>1</sub></code> dollars earned are taxed at a rate of <code>percent<sub>2</sub></code>.</li>
|
||||
<li>And so on.</li>
|
||||
</ul>
|
||||
|
||||
<p>You are given an integer <code>income</code> representing the amount of money you earned. Return <em>the amount of money that you have to pay in taxes.</em> Answers within <code>10<sup>-5</sup></code> of the actual answer will be accepted.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> brackets = [[3,50],[7,10],[12,25]], income = 10
|
||||
<strong>Output:</strong> 2.65000
|
||||
<strong>Explanation:</strong>
|
||||
Based on your income, you have 3 dollars in the 1<sup>st</sup> tax bracket, 4 dollars in the 2<sup>nd</sup> tax bracket, and 3 dollars in the 3<sup>rd</sup> tax bracket.
|
||||
The tax rate for the three tax brackets is 50%, 10%, and 25%, respectively.
|
||||
In total, you pay $3 * 50% + $4 * 10% + $3 * 25% = $2.65 in taxes.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> brackets = [[1,0],[4,25],[5,50]], income = 2
|
||||
<strong>Output:</strong> 0.25000
|
||||
<strong>Explanation:</strong>
|
||||
Based on your income, you have 1 dollar in the 1<sup>st</sup> tax bracket and 1 dollar in the 2<sup>nd</sup> tax bracket.
|
||||
The tax rate for the two tax brackets is 0% and 25%, respectively.
|
||||
In total, you pay $1 * 0% + $1 * 25% = $0.25 in taxes.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> brackets = [[2,50]], income = 0
|
||||
<strong>Output:</strong> 0.00000
|
||||
<strong>Explanation:</strong>
|
||||
You have no income to tax, so you have to pay a total of $0 in taxes.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= brackets.length <= 100</code></li>
|
||||
<li><code>1 <= upper<sub>i</sub> <= 1000</code></li>
|
||||
<li><code>0 <= percent<sub>i</sub> <= 100</code></li>
|
||||
<li><code>0 <= income <= 1000</code></li>
|
||||
<li><code>upper<sub>i</sub></code> is sorted in ascending order.</li>
|
||||
<li>All the values of <code>upper<sub>i</sub></code> are <strong>unique</strong>.</li>
|
||||
<li>The upper bound of the last tax bracket is greater than or equal to <code>income</code>.</li>
|
||||
</ul>
|
45
leetcode/problem/count-subarrays-with-score-less-than-k.html
Normal file
45
leetcode/problem/count-subarrays-with-score-less-than-k.html
Normal file
@ -0,0 +1,45 @@
|
||||
<p>The <strong>score</strong> of an array is defined as the <strong>product</strong> of its sum and its length.</p>
|
||||
|
||||
<ul>
|
||||
<li>For example, the score of <code>[1, 2, 3, 4, 5]</code> is <code>(1 + 2 + 3 + 4 + 5) * 5 = 75</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Given a positive integer array <code>nums</code> and an integer <code>k</code>, return <em>the <strong>number of non-empty subarrays</strong> of</em> <code>nums</code> <em>whose score is <strong>strictly less</strong> than</em> <code>k</code>.</p>
|
||||
|
||||
<p>A <strong>subarray</strong> is a contiguous sequence of elements within an array.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [2,1,4,3,5], k = 10
|
||||
<strong>Output:</strong> 6
|
||||
<strong>Explanation:</strong>
|
||||
The 6 subarrays having scores less than 10 are:
|
||||
- [2] with score 2 * 1 = 2.
|
||||
- [1] with score 1 * 1 = 1.
|
||||
- [4] with score 4 * 1 = 4.
|
||||
- [3] with score 3 * 1 = 3.
|
||||
- [5] with score 5 * 1 = 5.
|
||||
- [2,1] with score (2 + 1) * 2 = 6.
|
||||
Note that subarrays such as [1,4] and [4,3,5] are not considered because their scores are 10 and 36 respectively, while we need scores strictly less than 10.</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,1,1], k = 5
|
||||
<strong>Output:</strong> 5
|
||||
<strong>Explanation:</strong>
|
||||
Every subarray except [1,1,1] has a score less than 5.
|
||||
[1,1,1] has a score (1 + 1 + 1) * 3 = 9, which is greater than 5.
|
||||
Thus, there are 5 subarrays having scores less than 5.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= nums[i] <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= k <= 10<sup>15</sup></code></li>
|
||||
</ul>
|
40
leetcode/problem/fair-distribution-of-cookies.html
Normal file
40
leetcode/problem/fair-distribution-of-cookies.html
Normal file
@ -0,0 +1,40 @@
|
||||
<p>You are given an integer array <code>cookies</code>, where <code>cookies[i]</code> denotes the number of cookies in the <code>i<sup>th</sup></code> bag. You are also given an integer <code>k</code> that denotes the number of children to distribute <strong>all</strong> the bags of cookies to. All the cookies in the same bag must go to the same child and cannot be split up.</p>
|
||||
|
||||
<p>The <strong>unfairness</strong> of a distribution is defined as the <strong>maximum</strong> <strong>total</strong> cookies obtained by a single child in the distribution.</p>
|
||||
|
||||
<p>Return <em>the <strong>minimum</strong> unfairness of all distributions</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> cookies = [8,15,10,20,8], k = 2
|
||||
<strong>Output:</strong> 31
|
||||
<strong>Explanation:</strong> One optimal distribution is [8,15,8] and [10,20]
|
||||
- The 1<sup>st</sup> child receives [8,15,8] which has a total of 8 + 15 + 8 = 31 cookies.
|
||||
- The 2<sup>nd</sup> child receives [10,20] which has a total of 10 + 20 = 30 cookies.
|
||||
The unfairness of the distribution is max(31,30) = 31.
|
||||
It can be shown that there is no distribution with an unfairness less than 31.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> cookies = [6,1,3,2,2,4,1,2], k = 3
|
||||
<strong>Output:</strong> 7
|
||||
<strong>Explanation:</strong> One optimal distribution is [6,1], [3,2,2], and [4,1,2]
|
||||
- The 1<sup>st</sup> child receives [6,1] which has a total of 6 + 1 = 7 cookies.
|
||||
- The 2<sup>nd</sup> child receives [3,2,2] which has a total of 3 + 2 + 2 = 7 cookies.
|
||||
- The 3<sup>rd</sup> child receives [4,1,2] which has a total of 4 + 1 + 2 = 7 cookies.
|
||||
The unfairness of the distribution is max(7,7,7) = 7.
|
||||
It can be shown that there is no distribution with an unfairness less than 7.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= cookies.length <= 8</code></li>
|
||||
<li><code>1 <= cookies[i] <= 10<sup>5</sup></code></li>
|
||||
<li><code>2 <= k <= cookies.length</code></li>
|
||||
</ul>
|
45
leetcode/problem/match-substring-after-replacement.html
Normal file
45
leetcode/problem/match-substring-after-replacement.html
Normal file
@ -0,0 +1,45 @@
|
||||
<p>You are given two strings <code>s</code> and <code>sub</code>. You are also given a 2D character array <code>mappings</code> where <code>mappings[i] = [old<sub>i</sub>, new<sub>i</sub>]</code> indicates that you may <strong>replace</strong> any number of <code>old<sub>i</sub></code> characters of <code>sub</code> with <code>new<sub>i</sub></code>. Each character in <code>sub</code> <strong>cannot</strong> be replaced more than once.</p>
|
||||
|
||||
<p>Return <code>true</code><em> if it is possible to make </em><code>sub</code><em> a substring of </em><code>s</code><em> by replacing zero or more characters according to </em><code>mappings</code>. Otherwise, return <code>false</code>.</p>
|
||||
|
||||
<p>A <strong>substring</strong> is a contiguous non-empty sequence of characters within a string.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "fool3e7bar", sub = "leet", mappings = [["e","3"],["t","7"],["t","8"]]
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong> Replace the first 'e' in sub with '3' and 't' in sub with '7'.
|
||||
Now sub = "l3e7" is a substring of s, so we return true.</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "fooleetbar", sub = "f00l", mappings = [["o","0"]]
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation:</strong> The string "f00l" is not a substring of s and no replacements can be made.
|
||||
Note that we cannot replace '0' with 'o'.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "Fool33tbaR", sub = "leetd", mappings = [["e","3"],["t","7"],["t","8"],["d","b"],["p","b"]]
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong> Replace the first and second 'e' in sub with '3' and 'd' in sub with 'b'.
|
||||
Now sub = "l33tb" is a substring of s, so we return true.
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= sub.length <= s.length <= 5000</code></li>
|
||||
<li><code>0 <= mappings.length <= 1000</code></li>
|
||||
<li><code>mappings[i].length == 2</code></li>
|
||||
<li><code>old<sub>i</sub> != new<sub>i</sub></code></li>
|
||||
<li><code>s</code> and <code>sub</code> consist of uppercase and lowercase English letters and digits.</li>
|
||||
<li><code>old<sub>i</sub></code> and <code>new<sub>i</sub></code> are either uppercase or lowercase English letters or digits.</li>
|
||||
</ul>
|
42
leetcode/problem/minimum-path-cost-in-a-grid.html
Normal file
42
leetcode/problem/minimum-path-cost-in-a-grid.html
Normal file
@ -0,0 +1,42 @@
|
||||
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> integer matrix <code>grid</code> consisting of <strong>distinct</strong> integers from <code>0</code> to <code>m * n - 1</code>. You can move in this matrix from a cell to any other cell in the <strong>next</strong> row. That is, if you are in cell <code>(x, y)</code> such that <code>x < m - 1</code>, you can move to any of the cells <code>(x + 1, 0)</code>, <code>(x + 1, 1)</code>, ..., <code>(x + 1, n - 1)</code>. <strong>Note</strong> that it is not possible to move from cells in the last row.</p>
|
||||
|
||||
<p>Each possible move has a cost given by a <strong>0-indexed</strong> 2D array <code>moveCost</code> of size <code>(m * n) x n</code>, where <code>moveCost[i][j]</code> is the cost of moving from a cell with value <code>i</code> to a cell in column <code>j</code> of the next row. The cost of moving from cells in the last row of <code>grid</code> can be ignored.</p>
|
||||
|
||||
<p>The cost of a path in <code>grid</code> is the <strong>sum</strong> of all values of cells visited plus the <strong>sum</strong> of costs of all the moves made. Return <em>the <strong>minimum</strong> cost of a path that starts from any cell in the <strong>first</strong> row and ends at any cell in the <strong>last</strong> row.</em></p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/04/28/griddrawio-2.png" style="width: 301px; height: 281px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> grid = [[5,3],[4,0],[2,1]], moveCost = [[9,8],[1,5],[10,12],[18,6],[2,4],[14,3]]
|
||||
<strong>Output:</strong> 17
|
||||
<strong>Explanation: </strong>The path with the minimum possible cost is the path 5 -> 0 -> 1.
|
||||
- The sum of the values of cells visited is 5 + 0 + 1 = 6.
|
||||
- The cost of moving from 5 to 0 is 3.
|
||||
- The cost of moving from 0 to 1 is 8.
|
||||
So the total cost of the path is 6 + 3 + 8 = 17.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> grid = [[5,1,2],[4,0,3]], moveCost = [[12,10,15],[20,23,8],[21,7,1],[8,1,13],[9,10,25],[5,3,2]]
|
||||
<strong>Output:</strong> 6
|
||||
<strong>Explanation:</strong> The path with the minimum possible cost is the path 2 -> 3.
|
||||
- The sum of the values of cells visited is 2 + 3 = 5.
|
||||
- The cost of moving from 2 to 3 is 1.
|
||||
So the total cost of this path is 5 + 1 = 6.
|
||||
</pre>
|
||||
|
||||
<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 <= 50</code></li>
|
||||
<li><code>grid</code> consists of distinct integers from <code>0</code> to <code>m * n - 1</code>.</li>
|
||||
<li><code>moveCost.length == m * n</code></li>
|
||||
<li><code>moveCost[i].length == n</code></li>
|
||||
<li><code>1 <= moveCost[i][j] <= 100</code></li>
|
||||
</ul>
|
49
leetcode/problem/naming-a-company.html
Normal file
49
leetcode/problem/naming-a-company.html
Normal file
@ -0,0 +1,49 @@
|
||||
<p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
|
||||
|
||||
<ol>
|
||||
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<sub>B</sub></code>.</li>
|
||||
<li>Swap the first letters of <code>idea<sub>A</sub></code> and <code>idea<sub>B</sub></code> with each other.</li>
|
||||
<li>If <strong>both</strong> of the new names are not found in the original <code>ideas</code>, then the name <code>idea<sub>A</sub> idea<sub>B</sub></code> (the <strong>concatenation</strong> of <code>idea<sub>A</sub></code> and <code>idea<sub>B</sub></code>, separated by a space) is a valid company name.</li>
|
||||
<li>Otherwise, it is not a valid name.</li>
|
||||
</ol>
|
||||
|
||||
<p>Return <em>the number of <strong>distinct</strong> valid names for the company</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> ideas = ["coffee","donuts","time","toffee"]
|
||||
<strong>Output:</strong> 6
|
||||
<strong>Explanation:</strong> The following selections are valid:
|
||||
- ("coffee", "donuts"): The company name created is "doffee conuts".
|
||||
- ("donuts", "coffee"): The company name created is "conuts doffee".
|
||||
- ("donuts", "time"): The company name created is "tonuts dime".
|
||||
- ("donuts", "toffee"): The company name created is "tonuts doffee".
|
||||
- ("time", "donuts"): The company name created is "dime tonuts".
|
||||
- ("toffee", "donuts"): The company name created is "doffee tonuts".
|
||||
Therefore, there are a total of 6 distinct company names.
|
||||
|
||||
The following are some examples of invalid selections:
|
||||
- ("coffee", "time"): The name "toffee" formed after swapping already exists in the original array.
|
||||
- ("time", "toffee"): Both names are still the same after swapping and exist in the original array.
|
||||
- ("coffee", "toffee"): Both names formed after swapping already exist in the original array.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> ideas = ["lack","back"]
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong> There are no valid selections. Therefore, 0 is returned.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= ideas.length <= 5 * 10<sup>4</sup></code></li>
|
||||
<li><code>1 <= ideas[i].length <= 10</code></li>
|
||||
<li><code>ideas[i]</code> consists of lowercase English letters.</li>
|
||||
<li>All the strings in <code>ideas</code> are <strong>unique</strong>.</li>
|
||||
</ul>
|
44
leetcode/problem/strong-password-checker-ii.html
Normal file
44
leetcode/problem/strong-password-checker-ii.html
Normal file
@ -0,0 +1,44 @@
|
||||
<p>A password is said to be <strong>strong</strong> if it satisfies all the following criteria:</p>
|
||||
|
||||
<ul>
|
||||
<li>It has at least <code>8</code> characters.</li>
|
||||
<li>It contains at least <strong>one lowercase</strong> letter.</li>
|
||||
<li>It contains at least <strong>one uppercase</strong> letter.</li>
|
||||
<li>It contains at least <strong>one digit</strong>.</li>
|
||||
<li>It contains at least <strong>one special character</strong>. The special characters are the characters in the following string: <code>"!@#$%^&*()-+"</code>.</li>
|
||||
<li>It does <strong>not</strong> contain <code>2</code> of the same character in adjacent positions (i.e., <code>"aab"</code> violates this condition, but <code>"aba"</code> does not).</li>
|
||||
</ul>
|
||||
|
||||
<p>Given a string <code>password</code>, return <code>true</code><em> if it is a <strong>strong</strong> password</em>. Otherwise, return <code>false</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> password = "IloveLe3tcode!"
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong> The password meets all the requirements. Therefore, we return true.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> password = "Me+You--IsMyDream"
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation:</strong> The password does not contain a digit and also contains 2 of the same character in adjacent positions. Therefore, we return false.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> password = "1aB!"
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation:</strong> The password does not meet the length requirement. Therefore, we return false.</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= password.length <= 100</code></li>
|
||||
<li><code>password</code> consists of letters, digits, and special characters: <code>"!@#$%^&*()-+"</code>.</li>
|
||||
</ul>
|
41
leetcode/problem/successful-pairs-of-spells-and-potions.html
Normal file
41
leetcode/problem/successful-pairs-of-spells-and-potions.html
Normal file
@ -0,0 +1,41 @@
|
||||
<p>You are given two positive integer arrays <code>spells</code> and <code>potions</code>, of length <code>n</code> and <code>m</code> respectively, where <code>spells[i]</code> represents the strength of the <code>i<sup>th</sup></code> spell and <code>potions[j]</code> represents the strength of the <code>j<sup>th</sup></code> potion.</p>
|
||||
|
||||
<p>You are also given an integer <code>success</code>. A spell and potion pair is considered <strong>successful</strong> if the <strong>product</strong> of their strengths is <strong>at least</strong> <code>success</code>.</p>
|
||||
|
||||
<p>Return <em>an integer array </em><code>pairs</code><em> of length </em><code>n</code><em> where </em><code>pairs[i]</code><em> is the number of <strong>potions</strong> that will form a successful pair with the </em><code>i<sup>th</sup></code><em> spell.</em></p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> spells = [5,1,3], potions = [1,2,3,4,5], success = 7
|
||||
<strong>Output:</strong> [4,0,3]
|
||||
<strong>Explanation:</strong>
|
||||
- 0<sup>th</sup> spell: 5 * [1,2,3,4,5] = [5,<u><strong>10</strong></u>,<u><strong>15</strong></u>,<u><strong>20</strong></u>,<u><strong>25</strong></u>]. 4 pairs are successful.
|
||||
- 1<sup>st</sup> spell: 1 * [1,2,3,4,5] = [1,2,3,4,5]. 0 pairs are successful.
|
||||
- 2<sup>nd</sup> spell: 3 * [1,2,3,4,5] = [3,6,<u><strong>9</strong></u>,<u><strong>12</strong></u>,<u><strong>15</strong></u>]. 3 pairs are successful.
|
||||
Thus, [4,0,3] is returned.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> spells = [3,1,2], potions = [8,5,8], success = 16
|
||||
<strong>Output:</strong> [2,0,2]
|
||||
<strong>Explanation:</strong>
|
||||
- 0<sup>th</sup> spell: 3 * [8,5,8] = [<u><strong>24</strong></u>,15,<u><strong>24</strong></u>]. 2 pairs are successful.
|
||||
- 1<sup>st</sup> spell: 1 * [8,5,8] = [8,5,8]. 0 pairs are successful.
|
||||
- 2<sup>nd</sup> spell: 2 * [8,5,8] = [<strong><u>16</u></strong>,10,<u><strong>16</strong></u>]. 2 pairs are successful.
|
||||
Thus, [2,0,2] is returned.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>n == spells.length</code></li>
|
||||
<li><code>m == potions.length</code></li>
|
||||
<li><code>1 <= n, m <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= spells[i], potions[i] <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= success <= 10<sup>10</sup></code></li>
|
||||
</ul>
|
Loading…
Reference in New Issue
Block a user