mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-04-18 16:49:41 +08:00
更新国内版新增题目
This commit is contained in:
parent
7deedf5990
commit
74598d1cf8
leetcode-cn
originData
[no content]design-video-sharing-platform.json[no content]dynamic-pivoting-of-a-table.json[no content]dynamic-unpivoting-of-a-table.jsoncount-prefixes-of-a-given-string.jsoncount-unguarded-cells-in-the-grid.jsonescape-the-spreading-fire.jsonk-divisible-elements-subarrays.jsonminimum-average-difference.jsonminimum-consecutive-cards-to-pick-up.jsonremove-digit-from-number-to-maximize-result.jsontotal-appeal-of-a-string.json
problem (Chinese)
含最多 K 个可整除元素的子数组 [k-divisible-elements-subarrays].html字符串的总引力 [total-appeal-of-a-string].html必须拿起的最小连续卡牌数 [minimum-consecutive-cards-to-pick-up].html最小平均差 [minimum-average-difference].html移除指定数字得到的最大结果 [remove-digit-from-number-to-maximize-result].html统计各位数字都不同的数字个数 [count-numbers-with-unique-digits].html统计是给定字符串前缀的字符串数目 [count-prefixes-of-a-given-string].html统计网格图中没有被保卫的格子数 [count-unguarded-cells-in-the-grid].html逃离火灾 [escape-the-spreading-fire].html
problem (English)
含最多 K 个可整除元素的子数组(English) [k-divisible-elements-subarrays].html字符串的总引力(English) [total-appeal-of-a-string].html必须拿起的最小连续卡牌数(English) [minimum-consecutive-cards-to-pick-up].html最小平均差(English) [minimum-average-difference].html移除指定数字得到的最大结果(English) [remove-digit-from-number-to-maximize-result].html统计各位数字都不同的数字个数(English) [count-numbers-with-unique-digits].html统计是给定字符串前缀的字符串数目(English) [count-prefixes-of-a-given-string].html统计网格图中没有被保卫的格子数(English) [count-unguarded-cells-in-the-grid].html逃离火灾(English) [escape-the-spreading-fire].html
leetcode/originData
[no content]design-video-sharing-platform.json[no content]dynamic-pivoting-of-a-table.json[no content]dynamic-unpivoting-of-a-table.jsoncount-unguarded-cells-in-the-grid.jsonescape-the-spreading-fire.jsonintersection-of-multiple-arrays.jsonk-divisible-elements-subarrays.jsonminimum-average-difference.jsonminimum-consecutive-cards-to-pick-up.json
File diff suppressed because one or more lines are too long
@ -0,0 +1,55 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2381",
|
||||
"questionFrontendId": "2252",
|
||||
"categoryTitle": "Database",
|
||||
"boundTopicId": 1447354,
|
||||
"title": "Dynamic Pivoting of a Table",
|
||||
"titleSlug": "dynamic-pivoting-of-a-table",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Hard",
|
||||
"likes": 0,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"contributors": [],
|
||||
"langToValidPlayground": null,
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"16\", \"totalSubmission\": \"32\", \"totalAcceptedRaw\": 16, \"totalSubmissionRaw\": 32, \"acRate\": \"50.0%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\":{\"Products\":[\"product_id\",\"store\",\"price\"]},\"rows\":{\"Products\":[[1,\"Shop\",110],[1,\"LC_Store\",100],[2,\"Nozama\",200],[2,\"Souq\",190],[3,\"Shop\",1000],[3,\"Souq\",1900]]}}",
|
||||
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Products (product_id int, store varchar(7), price int)\"\n ],\n \"mssql\": [\n \"Create table Products (product_id int, store varchar(7), price int)\"\n ],\n \"oraclesql\": [\n \"Create table Products (product_id int, store varchar(7), price int)\"\n ],\n \"database\": true,\n \"manual\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Create table If Not Exists Products (product_id int, store varchar(7), price int)",
|
||||
"Truncate table Products",
|
||||
"insert into Products (product_id, store, price) values ('1', 'Shop', '110')",
|
||||
"insert into Products (product_id, store, price) values ('1', 'LC_Store', '100')",
|
||||
"insert into Products (product_id, store, price) values ('2', 'Nozama', '200')",
|
||||
"insert into Products (product_id, store, price) values ('2', 'Souq', '190')",
|
||||
"insert into Products (product_id, store, price) values ('3', 'Shop', '1000')",
|
||||
"insert into Products (product_id, store, price) values ('3', 'Souq', '1900')"
|
||||
],
|
||||
"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\":{\"Products\":[\"product_id\",\"store\",\"price\"]},\"rows\":{\"Products\":[[1,\"Shop\",110],[1,\"LC_Store\",100],[2,\"Nozama\",200],[2,\"Souq\",190],[3,\"Shop\",1000],[3,\"Souq\",1900]]}}",
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2382",
|
||||
"questionFrontendId": "2253",
|
||||
"categoryTitle": "Database",
|
||||
"boundTopicId": 1447404,
|
||||
"title": "Dynamic Unpivoting of a Table",
|
||||
"titleSlug": "dynamic-unpivoting-of-a-table",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Hard",
|
||||
"likes": 0,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"contributors": [],
|
||||
"langToValidPlayground": null,
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"9\", \"totalSubmission\": \"15\", \"totalAcceptedRaw\": 9, \"totalSubmissionRaw\": 15, \"acRate\": \"60.0%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\": {\"Products\": [\"product_id\", \"LC_Store\", \"Nozama\", \"Shop\", \"Souq\"]}, \"rows\": {\"Products\": [[1, 100, null, 110, null], [2, null, 200, null, 190], [3, null, null, 1000, 1900]]}}",
|
||||
"metaData": "{\n \"mysql\": [],\n \"mssql\": [],\n \"oraclesql\": [],\n \"database\": true,\n \"manual\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Truncate table Products",
|
||||
"insert into Products (product_id, LC_Store, Nozama, Shop, Souq) values ('1', '100', 'None', '110', 'None')",
|
||||
"insert into Products (product_id, LC_Store, Nozama, Shop, Souq) values ('2', 'None', '200', 'None', '190')",
|
||||
"insert into Products (product_id, LC_Store, Nozama, Shop, Souq) values ('3', 'None', 'None', '1000', '1900')"
|
||||
],
|
||||
"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\": {\"Products\": [\"product_id\", \"LC_Store\", \"Nozama\", \"Shop\", \"Souq\"]}, \"rows\": {\"Products\": [[1, 100, null, 110, null], [2, null, 200, null, 190], [3, null, null, 1000, 1900]]}}",
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
157
leetcode-cn/originData/count-prefixes-of-a-given-string.json
Normal file
157
leetcode-cn/originData/count-prefixes-of-a-given-string.json
Normal file
File diff suppressed because one or more lines are too long
158
leetcode-cn/originData/count-unguarded-cells-in-the-grid.json
Normal file
158
leetcode-cn/originData/count-unguarded-cells-in-the-grid.json
Normal file
File diff suppressed because one or more lines are too long
160
leetcode-cn/originData/escape-the-spreading-fire.json
Normal file
160
leetcode-cn/originData/escape-the-spreading-fire.json
Normal file
File diff suppressed because one or more lines are too long
158
leetcode-cn/originData/k-divisible-elements-subarrays.json
Normal file
158
leetcode-cn/originData/k-divisible-elements-subarrays.json
Normal file
File diff suppressed because one or more lines are too long
158
leetcode-cn/originData/minimum-average-difference.json
Normal file
158
leetcode-cn/originData/minimum-average-difference.json
Normal file
File diff suppressed because one or more lines are too long
158
leetcode-cn/originData/minimum-consecutive-cards-to-pick-up.json
Normal file
158
leetcode-cn/originData/minimum-consecutive-cards-to-pick-up.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
160
leetcode-cn/originData/total-appeal-of-a-string.json
Normal file
160
leetcode-cn/originData/total-appeal-of-a-string.json
Normal file
File diff suppressed because one or more lines are too long
@ -0,0 +1,46 @@
|
||||
<p>给你一个整数数组 <code>nums</code> 和两个整数 <code>k</code> 和 <code>p</code> ,找出并返回满足要求的不同的子数组数,要求子数组中最多 <code>k</code> 个可被 <code>p</code> 整除的元素。</p>
|
||||
|
||||
<p>如果满足下述条件之一,则认为数组 <code>nums1</code> 和 <code>nums2</code> 是 <strong>不同</strong> 数组:</p>
|
||||
|
||||
<ul>
|
||||
<li>两数组长度 <strong>不同</strong> ,或者</li>
|
||||
<li>存在 <strong>至少 </strong>一个下标 <code>i</code> 满足 <code>nums1[i] != nums2[i]</code> 。</li>
|
||||
</ul>
|
||||
|
||||
<p><strong>子数组</strong> 定义为:数组中的连续元素组成的一个 <strong>非空</strong> 序列。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>nums = [<em><strong>2</strong></em>,3,3,<em><strong>2</strong></em>,<em><strong>2</strong></em>], k = 2, p = 2
|
||||
<strong>输出:</strong>11
|
||||
<strong>解释:</strong>
|
||||
位于下标 0、3 和 4 的元素都可以被 p = 2 整除。
|
||||
共计 11 个不同子数组都满足最多含 k = 2 个可以被 2 整除的元素:
|
||||
[2]、[2,3]、[2,3,3]、[2,3,3,2]、[3]、[3,3]、[3,3,2]、[3,3,2,2]、[3,2]、[3,2,2] 和 [2,2] 。
|
||||
注意,尽管子数组 [2] 和 [3] 在 nums 中出现不止一次,但统计时只计数一次。
|
||||
子数组 [2,3,3,2,2] 不满足条件,因为其中有 3 个元素可以被 2 整除。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>nums = [1,2,3,4], k = 4, p = 1
|
||||
<strong>输出:</strong>10
|
||||
<strong>解释:</strong>
|
||||
nums 中的所有元素都可以被 p = 1 整除。
|
||||
此外,nums 中的每个子数组都满足最多 4 个元素可以被 1 整除。
|
||||
因为所有子数组互不相同,因此满足所有限制条件的子数组总数为 10 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 200</code></li>
|
||||
<li><code>1 <= nums[i], p <= 200</code></li>
|
||||
<li><code>1 <= k <= nums.length</code></li>
|
||||
</ul>
|
@ -0,0 +1,45 @@
|
||||
<p>字符串的 <strong>引力</strong> 定义为:字符串中 <strong>不同</strong> 字符的数量。</p>
|
||||
|
||||
<ul>
|
||||
<li>例如,<code>"abbca"</code> 的引力为 <code>3</code> ,因为其中有 <code>3</code> 个不同字符 <code>'a'</code>、<code>'b'</code> 和 <code>'c'</code> 。</li>
|
||||
</ul>
|
||||
|
||||
<p>给你一个字符串 <code>s</code> ,返回 <strong>其所有子字符串的总引力</strong> <strong>。</strong></p>
|
||||
|
||||
<p><strong>子字符串</strong> 定义为:字符串中的一个连续字符序列。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>s = "abbca"
|
||||
<strong>输出:</strong>28
|
||||
<strong>解释:</strong>"abbca" 的子字符串有:
|
||||
- 长度为 1 的子字符串:"a"、"b"、"b"、"c"、"a" 的引力分别为 1、1、1、1、1,总和为 5 。
|
||||
- 长度为 2 的子字符串:"ab"、"bb"、"bc"、"ca" 的引力分别为 2、1、2、2 ,总和为 7 。
|
||||
- 长度为 3 的子字符串:"abb"、"bbc"、"bca" 的引力分别为 2、2、3 ,总和为 7 。
|
||||
- 长度为 4 的子字符串:"abbc"、"bbca" 的引力分别为 3、3 ,总和为 6 。
|
||||
- 长度为 5 的子字符串:"abbca" 的引力为 3 ,总和为 3 。
|
||||
引力总和为 5 + 7 + 7 + 6 + 3 = 28 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>s = "code"
|
||||
<strong>输出:</strong>20
|
||||
<strong>解释:</strong>"code" 的子字符串有:
|
||||
- 长度为 1 的子字符串:"c"、"o"、"d"、"e" 的引力分别为 1、1、1、1 ,总和为 4 。
|
||||
- 长度为 2 的子字符串:"co"、"od"、"de" 的引力分别为 2、2、2 ,总和为 6 。
|
||||
- 长度为 3 的子字符串:"cod"、"ode" 的引力分别为 3、3 ,总和为 6 。
|
||||
- 长度为 4 的子字符串:"code" 的引力为 4 ,总和为 4 。
|
||||
引力总和为 4 + 6 + 6 + 4 = 20 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= s.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>s</code> 由小写英文字母组成</li>
|
||||
</ul>
|
26
leetcode-cn/problem (Chinese)/必须拿起的最小连续卡牌数 [minimum-consecutive-cards-to-pick-up].html
Normal file
26
leetcode-cn/problem (Chinese)/必须拿起的最小连续卡牌数 [minimum-consecutive-cards-to-pick-up].html
Normal file
@ -0,0 +1,26 @@
|
||||
<p>给你一个整数数组 <code>cards</code> ,其中 <code>cards[i]</code> 表示第 <code>i</code> 张卡牌的 <strong>值</strong> 。如果两张卡牌的值相同,则认为这一对卡牌 <strong>匹配</strong> 。</p>
|
||||
|
||||
<p>返回你必须拿起的最小连续卡牌数,以使在拿起的卡牌中有一对匹配的卡牌。如果无法得到一对匹配的卡牌,返回 <code>-1</code> 。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>cards = [3,4,2,3,4,7]
|
||||
<strong>输出:</strong>4
|
||||
<strong>解释:</strong>拿起卡牌 [3,4,2,3] 将会包含一对值为 3 的匹配卡牌。注意,拿起 [4,2,3,4] 也是最优方案。</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>cards = [1,0,5,3]
|
||||
<strong>输出:</strong>-1
|
||||
<strong>解释:</strong>无法找出含一对匹配卡牌的一组连续卡牌。</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= cards.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>0 <= cards[i] <= 10<sup>6</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,47 @@
|
||||
<p>给你一个下标从 <strong>0</strong> 开始长度为 <code>n</code> 的整数数组 <code>nums</code> 。</p>
|
||||
|
||||
<p>下标 <code>i</code> 处的 <strong>平均差</strong> 指的是 <code>nums</code> 中 <strong>前</strong> <code>i + 1</code> 个元素平均值和 <strong>后</strong> <code>n - i - 1</code> 个元素平均值的 <strong>绝对差</strong> 。两个平均值都需要 <strong>向下取整</strong> 到最近的整数。</p>
|
||||
|
||||
<p>请你返回产生 <strong>最小平均差</strong> 的下标。如果有多个下标最小平均差相等,请你返回 <strong>最小</strong> 的一个下标。</p>
|
||||
|
||||
<p><strong>注意:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>两个数的<strong> 绝对差</strong> 是两者差的绝对值。</li>
|
||||
<li> <code>n</code> 个元素的平均值是 <code>n</code> 个元素之 <strong>和</strong> 除以(整数除法) <code>n</code> 。</li>
|
||||
<li><code>0</code> 个元素的平均值视为 <code>0</code> 。</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>nums = [2,5,3,9,5,3]
|
||||
<b>输出:</b>3
|
||||
<strong>解释:</strong>
|
||||
- 下标 0 处的平均差为:|2 / 1 - (5 + 3 + 9 + 5 + 3) / 5| = |2 / 1 - 25 / 5| = |2 - 5| = 3 。
|
||||
- 下标 1 处的平均差为:|(2 + 5) / 2 - (3 + 9 + 5 + 3) / 4| = |7 / 2 - 20 / 4| = |3 - 5| = 2 。
|
||||
- 下标 2 处的平均差为:|(2 + 5 + 3) / 3 - (9 + 5 + 3) / 3| = |10 / 3 - 17 / 3| = |3 - 5| = 2 。
|
||||
- 下标 3 处的平均差为:|(2 + 5 + 3 + 9) / 4 - (5 + 3) / 2| = |19 / 4 - 8 / 2| = |4 - 4| = 0 。
|
||||
- 下标 4 处的平均差为:|(2 + 5 + 3 + 9 + 5) / 5 - 3 / 1| = |24 / 5 - 3 / 1| = |4 - 3| = 1 。
|
||||
- 下标 5 处的平均差为:|(2 + 5 + 3 + 9 + 5 + 3) / 6 - 0| = |27 / 6 - 0| = |4 - 0| = 4 。
|
||||
下标 3 处的平均差为最小平均差,所以返回 3 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>nums = [0]
|
||||
<b>输出:</b>0
|
||||
<strong>解释:</strong>
|
||||
唯一的下标是 0 ,所以我们返回 0 。
|
||||
下标 0 处的平均差为:|0 / 1 - 0| = |0 - 0| = 0 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>0 <= nums[i] <= 10<sup>5</sup></code></li>
|
||||
</ul>
|
42
leetcode-cn/problem (Chinese)/移除指定数字得到的最大结果 [remove-digit-from-number-to-maximize-result].html
Normal file
42
leetcode-cn/problem (Chinese)/移除指定数字得到的最大结果 [remove-digit-from-number-to-maximize-result].html
Normal file
@ -0,0 +1,42 @@
|
||||
<p>给你一个表示某个正整数的字符串 <code>number</code> 和一个字符 <code>digit</code> 。</p>
|
||||
|
||||
<p>从 <code>number</code> 中 <strong>恰好</strong> 移除 <strong>一个</strong> 等于 <code>digit</code> 的字符后,找出并返回按 <strong>十进制</strong> 表示 <strong>最大</strong> 的结果字符串。生成的测试用例满足 <code>digit</code> 在 <code>number</code> 中出现至少一次。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>number = "123", digit = "3"
|
||||
<strong>输出:</strong>"12"
|
||||
<strong>解释:</strong>"123" 中只有一个 '3' ,在移除 '3' 之后,结果为 "12" 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>number = "1231", digit = "1"
|
||||
<strong>输出:</strong>"231"
|
||||
<strong>解释:</strong>可以移除第一个 '1' 得到 "231" 或者移除第二个 '1' 得到 "123" 。
|
||||
由于 231 > 123 ,返回 "231" 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>number = "551", digit = "5"
|
||||
<strong>输出:</strong>"51"
|
||||
<strong>解释:</strong>可以从 "551" 中移除第一个或者第二个 '5' 。
|
||||
两种方案的结果都是 "51" 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= number.length <= 100</code></li>
|
||||
<li><code>number</code> 由数字 <code>'1'</code> 到 <code>'9'</code> 组成</li>
|
||||
<li><code>digit</code> 是 <code>'1'</code> 到 <code>'9'</code> 中的一个数字</li>
|
||||
<li><code>digit</code> 在 <code>number</code> 中出现至少一次</li>
|
||||
</ul>
|
@ -0,0 +1,29 @@
|
||||
给你一个整数 <code>n</code> ,统计并返回各位数字都不同的数字 <code>x</code> 的个数,其中 <code>0 <= x < 10<sup>n</sup></code><sup> </sup>。
|
||||
<div class="original__bRMd">
|
||||
<div>
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>n = 2
|
||||
<strong>输出:</strong>91
|
||||
<strong>解释:</strong>答案应为除去 <code>11、22、33、44、55、66、77、88、99 </code>外,在 0 ≤ x < 100 范围内的所有数字。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>n = 0
|
||||
<strong>输出:</strong>1
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= n <= 8</code></li>
|
||||
</ul>
|
34
leetcode-cn/problem (Chinese)/统计是给定字符串前缀的字符串数目 [count-prefixes-of-a-given-string].html
Normal file
34
leetcode-cn/problem (Chinese)/统计是给定字符串前缀的字符串数目 [count-prefixes-of-a-given-string].html
Normal file
@ -0,0 +1,34 @@
|
||||
<p>给你一个字符串数组 <code>words</code> 和一个字符串 <code>s</code> ,其中 <code>words[i]</code> 和 <code>s</code> 只包含 <strong>小写英文字母</strong> 。</p>
|
||||
|
||||
<p>请你返回 <code>words</code> 中是字符串 <code>s</code> <strong>前缀 </strong>的 <strong>字符串数目</strong> 。</p>
|
||||
|
||||
<p>一个字符串的 <strong>前缀</strong> 是出现在字符串开头的子字符串。<strong>子字符串</strong> 是一个字符串中的连续一段字符序列。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>words = ["a","b","c","ab","bc","abc"], s = "abc"
|
||||
<b>输出:</b>3
|
||||
<strong>解释:</strong>
|
||||
words 中是 s = "abc" 前缀的字符串为:
|
||||
"a" ,"ab" 和 "abc" 。
|
||||
所以 words 中是字符串 s 前缀的字符串数目为 3 。</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><b>输入:</b>words = ["a","a"], s = "aa"
|
||||
<b>输出:</b>2
|
||||
<strong>解释:
|
||||
</strong>两个字符串都是 s 的前缀。
|
||||
注意,相同的字符串可能在 words 中出现多次,它们应该被计数多次。</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= words.length <= 1000</code></li>
|
||||
<li><code>1 <= words[i].length, s.length <= 10</code></li>
|
||||
<li><code>words[i]</code> 和 <code>s</code> <strong>只</strong> 包含小写英文字母。</li>
|
||||
</ul>
|
42
leetcode-cn/problem (Chinese)/统计网格图中没有被保卫的格子数 [count-unguarded-cells-in-the-grid].html
Normal file
42
leetcode-cn/problem (Chinese)/统计网格图中没有被保卫的格子数 [count-unguarded-cells-in-the-grid].html
Normal file
@ -0,0 +1,42 @@
|
||||
<p>给你两个整数 <code>m</code> 和 <code>n</code> 表示一个下标从<strong> 0</strong> 开始的 <code>m x n</code> 网格图。同时给你两个二维整数数组 <code>guards</code> 和 <code>walls</code> ,其中 <code>guards[i] = [row<sub>i</sub>, col<sub>i</sub>]</code> 且 <code>walls[j] = [row<sub>j</sub>, col<sub>j</sub>]</code> ,分别表示第 <code>i</code> 个警卫和第 <code>j</code> 座墙所在的位置。</p>
|
||||
|
||||
<p>一个警卫能看到 4 个坐标轴方向(即东、南、西、北)的 <strong>所有</strong> 格子,除非他们被一座墙或者另外一个警卫 <strong>挡住</strong> 了视线。如果一个格子能被 <strong>至少</strong> 一个警卫看到,那么我们说这个格子被 <strong>保卫</strong> 了。</p>
|
||||
|
||||
<p>请你返回空格子中,有多少个格子是 <strong>没被保卫</strong> 的。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/03/10/example1drawio2.png" style="width: 300px; height: 204px;"></p>
|
||||
|
||||
<pre><b>输入:</b>m = 4, n = 6, guards = [[0,0],[1,1],[2,3]], walls = [[0,1],[2,2],[1,4]]
|
||||
<b>输出:</b>7
|
||||
<strong>解释:</strong>上图中,被保卫和没有被保卫的格子分别用红色和绿色表示。
|
||||
总共有 7 个没有被保卫的格子,所以我们返回 7 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/03/10/example2drawio.png" style="width: 200px; height: 201px;"></p>
|
||||
|
||||
<pre><b>输入:</b>m = 3, n = 3, guards = [[1,1]], walls = [[0,1],[1,0],[2,1],[1,2]]
|
||||
<b>输出:</b>4
|
||||
<b>解释:</b>上图中,没有被保卫的格子用绿色表示。
|
||||
总共有 4 个没有被保卫的格子,所以我们返回 4 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= m, n <= 10<sup>5</sup></code></li>
|
||||
<li><code>2 <= m * n <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= guards.length, walls.length <= 5 * 10<sup>4</sup></code></li>
|
||||
<li><code>2 <= guards.length + walls.length <= m * n</code></li>
|
||||
<li><code>guards[i].length == walls[j].length == 2</code></li>
|
||||
<li><code>0 <= row<sub>i</sub>, row<sub>j</sub> < m</code></li>
|
||||
<li><code>0 <= col<sub>i</sub>, col<sub>j</sub> < n</code></li>
|
||||
<li><code>guards</code> 和 <code>walls</code> 中所有位置 <strong>互不相同</strong> 。</li>
|
||||
</ul>
|
@ -0,0 +1,62 @@
|
||||
<p>给你一个下标从 <strong>0</strong> 开始大小为 <code>m x n</code> 的二维整数数组 <code>grid</code> ,它表示一个网格图。每个格子为下面 3 个值之一:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>0</code> 表示草地。</li>
|
||||
<li><code>1</code> 表示着火的格子。</li>
|
||||
<li><code>2</code> 表示一座墙,你跟火都不能通过这个格子。</li>
|
||||
</ul>
|
||||
|
||||
<p>一开始你在最左上角的格子 <code>(0, 0)</code> ,你想要到达最右下角的安全屋格子 <code>(m - 1, n - 1)</code> 。每一分钟,你可以移动到 <strong>相邻</strong> 的草地格子。每次你移动 <strong>之后</strong> ,着火的格子会扩散到所有不是墙的 <strong>相邻</strong> 格子。</p>
|
||||
|
||||
<p>请你返回你在初始位置可以停留的 <strong>最多 </strong>分钟数,且停留完这段时间后你还能安全到达安全屋。如果无法实现,请你返回 <code>-1</code> 。如果不管你在初始位置停留多久,你 <strong>总是</strong> 能到达安全屋,请你返回 <code>10<sup>9</sup></code> 。</p>
|
||||
|
||||
<p>注意,如果你到达安全屋后,火马上到了安全屋,这视为你能够安全到达安全屋。</p>
|
||||
|
||||
<p>如果两个格子有共同边,那么它们为 <strong>相邻</strong> 格子。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/03/10/ex1new.jpg" style="width: 650px; height: 404px;"></p>
|
||||
|
||||
<pre><b>输入:</b>grid = [[0,2,0,0,0,0,0],[0,0,0,2,2,1,0],[0,2,0,0,1,2,0],[0,0,2,2,2,0,2],[0,0,0,0,0,0,0]]
|
||||
<b>输出:</b>3
|
||||
<b>解释:</b>上图展示了你在初始位置停留 3 分钟后的情形。
|
||||
你仍然可以安全到达安全屋。
|
||||
停留超过 3 分钟会让你无法安全到达安全屋。</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/03/10/ex2new2.jpg" style="width: 515px; height: 150px;"></p>
|
||||
|
||||
<pre><b>输入:</b>grid = [[0,0,0,0],[0,1,2,0],[0,2,0,0]]
|
||||
<b>输出:</b>-1
|
||||
<b>解释:</b>上图展示了你马上开始朝安全屋移动的情形。
|
||||
火会蔓延到你可以移动的所有格子,所以无法安全到达安全屋。
|
||||
所以返回 -1 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/03/10/ex3new.jpg" style="width: 174px; height: 150px;"></p>
|
||||
|
||||
<pre><b>输入:</b>grid = [[0,0,0],[2,2,0],[1,2,0]]
|
||||
<b>输出:</b>1000000000
|
||||
<b>解释:</b>上图展示了初始网格图。
|
||||
注意,由于火被墙围了起来,所以无论如何你都能安全到达安全屋。
|
||||
所以返回 10<sup>9</sup> 。
|
||||
</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 <= 300</code></li>
|
||||
<li><code>4 <= m * n <= 2 * 10<sup>4</sup></code></li>
|
||||
<li><code>grid[i][j]</code> 是 <code>0</code> ,<code>1</code> 或者 <code>2</code> 。</li>
|
||||
<li><code>grid[0][0] == grid[m - 1][n - 1] == 0</code></li>
|
||||
</ul>
|
44
leetcode-cn/problem (English)/含最多 K 个可整除元素的子数组(English) [k-divisible-elements-subarrays].html
Normal file
44
leetcode-cn/problem (English)/含最多 K 个可整除元素的子数组(English) [k-divisible-elements-subarrays].html
Normal file
@ -0,0 +1,44 @@
|
||||
<p>Given an integer array <code>nums</code> and two integers <code>k</code> and <code>p</code>, return <em>the number of <strong>distinct subarrays</strong> which have <strong>at most</strong></em> <code>k</code> <em>elements divisible by</em> <code>p</code>.</p>
|
||||
|
||||
<p>Two arrays <code>nums1</code> and <code>nums2</code> are said to be <strong>distinct</strong> if:</p>
|
||||
|
||||
<ul>
|
||||
<li>They are of <strong>different</strong> lengths, or</li>
|
||||
<li>There exists <strong>at least</strong> one index <code>i</code> where <code>nums1[i] != nums2[i]</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>A <strong>subarray</strong> is defined as a <strong>non-empty</strong> contiguous sequence of elements in an array.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [<u><strong>2</strong></u>,3,3,<u><strong>2</strong></u>,<u><strong>2</strong></u>], k = 2, p = 2
|
||||
<strong>Output:</strong> 11
|
||||
<strong>Explanation:</strong>
|
||||
The elements at indices 0, 3, and 4 are divisible by p = 2.
|
||||
The 11 distinct subarrays which have at most k = 2 elements divisible by 2 are:
|
||||
[2], [2,3], [2,3,3], [2,3,3,2], [3], [3,3], [3,3,2], [3,3,2,2], [3,2], [3,2,2], and [2,2].
|
||||
Note that the subarrays [2] and [3] occur more than once in nums, but they should each be counted only once.
|
||||
The subarray [2,3,3,2,2] should not be counted because it has 3 elements that are divisible by 2.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,2,3,4], k = 4, p = 1
|
||||
<strong>Output:</strong> 10
|
||||
<strong>Explanation:</strong>
|
||||
All element of nums are divisible by p = 1.
|
||||
Also, every subarray of nums will have at most 4 elements that are divisible by 1.
|
||||
Since all subarrays are distinct, the total number of subarrays satisfying all the constraints is 10.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 200</code></li>
|
||||
<li><code>1 <= nums[i], p <= 200</code></li>
|
||||
<li><code>1 <= k <= nums.length</code></li>
|
||||
</ul>
|
@ -0,0 +1,45 @@
|
||||
<p>The <b>appeal</b> of a string is the number of <strong>distinct</strong> characters found in the string.</p>
|
||||
|
||||
<ul>
|
||||
<li>For example, the appeal of <code>"abbca"</code> is <code>3</code> because it has <code>3</code> distinct characters: <code>'a'</code>, <code>'b'</code>, and <code>'c'</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Given a string <code>s</code>, return <em>the <strong>total appeal of all of its <strong>substrings</strong>.</strong></em></p>
|
||||
|
||||
<p>A <strong>substring</strong> is a contiguous sequence of characters within a string.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "abbca"
|
||||
<strong>Output:</strong> 28
|
||||
<strong>Explanation:</strong> The following are the substrings of "abbca":
|
||||
- Substrings of length 1: "a", "b", "b", "c", "a" have an appeal of 1, 1, 1, 1, and 1 respectively. The sum is 5.
|
||||
- Substrings of length 2: "ab", "bb", "bc", "ca" have an appeal of 2, 1, 2, and 2 respectively. The sum is 7.
|
||||
- Substrings of length 3: "abb", "bbc", "bca" have an appeal of 2, 2, and 3 respectively. The sum is 7.
|
||||
- Substrings of length 4: "abbc", "bbca" have an appeal of 3 and 3 respectively. The sum is 6.
|
||||
- Substrings of length 5: "abbca" has an appeal of 3. The sum is 3.
|
||||
The total sum is 5 + 7 + 7 + 6 + 3 = 28.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "code"
|
||||
<strong>Output:</strong> 20
|
||||
<strong>Explanation:</strong> The following are the substrings of "code":
|
||||
- Substrings of length 1: "c", "o", "d", "e" have an appeal of 1, 1, 1, and 1 respectively. The sum is 4.
|
||||
- Substrings of length 2: "co", "od", "de" have an appeal of 2, 2, and 2 respectively. The sum is 6.
|
||||
- Substrings of length 3: "cod", "ode" have an appeal of 3 and 3 respectively. The sum is 6.
|
||||
- Substrings of length 4: "code" has an appeal of 4. The sum is 4.
|
||||
The total sum is 4 + 6 + 6 + 4 = 20.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= s.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>s</code> consists of lowercase English letters.</li>
|
||||
</ul>
|
28
leetcode-cn/problem (English)/必须拿起的最小连续卡牌数(English) [minimum-consecutive-cards-to-pick-up].html
Normal file
28
leetcode-cn/problem (English)/必须拿起的最小连续卡牌数(English) [minimum-consecutive-cards-to-pick-up].html
Normal file
@ -0,0 +1,28 @@
|
||||
<p>You are given an integer array <code>cards</code> where <code>cards[i]</code> represents the <strong>value</strong> of the <code>i<sup>th</sup></code> card. A pair of cards are <strong>matching</strong> if the cards have the <strong>same</strong> value.</p>
|
||||
|
||||
<p>Return<em> the <strong>minimum</strong> number of <strong>consecutive</strong> cards you have to pick up to have a pair of <strong>matching</strong> cards among the picked cards.</em> If it is impossible to have matching cards, return <code>-1</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> cards = [3,4,2,3,4,7]
|
||||
<strong>Output:</strong> 4
|
||||
<strong>Explanation:</strong> We can pick up the cards [3,4,2,3] which contain a matching pair of cards with value 3. Note that picking up the cards [4,2,3,4] is also optimal.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> cards = [1,0,5,3]
|
||||
<strong>Output:</strong> -1
|
||||
<strong>Explanation:</strong> There is no way to pick up a set of consecutive cards that contain a pair of matching cards.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= cards.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>0 <= cards[i] <= 10<sup>6</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,47 @@
|
||||
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.</p>
|
||||
|
||||
<p>The <strong>average difference</strong> of the index <code>i</code> is the <strong>absolute</strong> <strong>difference</strong> between the average of the <strong>first</strong> <code>i + 1</code> elements of <code>nums</code> and the average of the <strong>last</strong> <code>n - i - 1</code> elements. Both averages should be <strong>rounded down</strong> to the nearest integer.</p>
|
||||
|
||||
<p>Return<em> the index with the <strong>minimum average difference</strong></em>. If there are multiple such indices, return the <strong>smallest</strong> one.</p>
|
||||
|
||||
<p><strong>Note:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>The <strong>absolute difference</strong> of two numbers is the absolute value of their difference.</li>
|
||||
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>sum</strong> of the <code>n</code> elements divided (<strong>integer division</strong>) by <code>n</code>.</li>
|
||||
<li>The average of <code>0</code> elements is considered to be <code>0</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [2,5,3,9,5,3]
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong>
|
||||
- The average difference of index 0 is: |2 / 1 - (5 + 3 + 9 + 5 + 3) / 5| = |2 / 1 - 25 / 5| = |2 - 5| = 3.
|
||||
- The average difference of index 1 is: |(2 + 5) / 2 - (3 + 9 + 5 + 3) / 4| = |7 / 2 - 20 / 4| = |3 - 5| = 2.
|
||||
- The average difference of index 2 is: |(2 + 5 + 3) / 3 - (9 + 5 + 3) / 3| = |10 / 3 - 17 / 3| = |3 - 5| = 2.
|
||||
- The average difference of index 3 is: |(2 + 5 + 3 + 9) / 4 - (5 + 3) / 2| = |19 / 4 - 8 / 2| = |4 - 4| = 0.
|
||||
- The average difference of index 4 is: |(2 + 5 + 3 + 9 + 5) / 5 - 3 / 1| = |24 / 5 - 3 / 1| = |4 - 3| = 1.
|
||||
- The average difference of index 5 is: |(2 + 5 + 3 + 9 + 5 + 3) / 6 - 0| = |27 / 6 - 0| = |4 - 0| = 4.
|
||||
The average difference of index 3 is the minimum average difference so return 3.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [0]
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong>
|
||||
The only index is 0 so return 0.
|
||||
The average difference of index 0 is: |0 / 1 - 0| = |0 - 0| = 0.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>0 <= nums[i] <= 10<sup>5</sup></code></li>
|
||||
</ul>
|
40
leetcode-cn/problem (English)/移除指定数字得到的最大结果(English) [remove-digit-from-number-to-maximize-result].html
Normal file
40
leetcode-cn/problem (English)/移除指定数字得到的最大结果(English) [remove-digit-from-number-to-maximize-result].html
Normal file
@ -0,0 +1,40 @@
|
||||
<p>You are given a string <code>number</code> representing a <strong>positive integer</strong> and a character <code>digit</code>.</p>
|
||||
|
||||
<p>Return <em>the resulting string after removing <strong>exactly one occurrence</strong> of </em><code>digit</code><em> from </em><code>number</code><em> such that the value of the resulting string in <strong>decimal</strong> form is <strong>maximized</strong></em>. The test cases are generated such that <code>digit</code> occurs at least once in <code>number</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> number = "123", digit = "3"
|
||||
<strong>Output:</strong> "12"
|
||||
<strong>Explanation:</strong> There is only one '3' in "123". After removing '3', the result is "12".
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> number = "1231", digit = "1"
|
||||
<strong>Output:</strong> "231"
|
||||
<strong>Explanation:</strong> We can remove the first '1' to get "231" or remove the second '1' to get "123".
|
||||
Since 231 > 123, we return "231".
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> number = "551", digit = "5"
|
||||
<strong>Output:</strong> "51"
|
||||
<strong>Explanation:</strong> We can remove either the first or second '5' from "551".
|
||||
Both result in the string "51".
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= number.length <= 100</code></li>
|
||||
<li><code>number</code> consists of digits from <code>'1'</code> to <code>'9'</code>.</li>
|
||||
<li><code>digit</code> is a digit from <code>'1'</code> to <code>'9'</code>.</li>
|
||||
<li><code>digit</code> occurs at least once in <code>number</code>.</li>
|
||||
</ul>
|
24
leetcode-cn/problem (English)/统计各位数字都不同的数字个数(English) [count-numbers-with-unique-digits].html
Normal file
24
leetcode-cn/problem (English)/统计各位数字都不同的数字个数(English) [count-numbers-with-unique-digits].html
Normal file
@ -0,0 +1,24 @@
|
||||
<p>Given an integer <code>n</code>, return the count of all numbers with unique digits, <code>x</code>, where <code>0 <= x < 10<sup>n</sup></code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 2
|
||||
<strong>Output:</strong> 91
|
||||
<strong>Explanation:</strong> The answer should be the total numbers in the range of 0 ≤ x < 100, excluding 11,22,33,44,55,66,77,88,99
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> n = 0
|
||||
<strong>Output:</strong> 1
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= n <= 8</code></li>
|
||||
</ul>
|
34
leetcode-cn/problem (English)/统计是给定字符串前缀的字符串数目(English) [count-prefixes-of-a-given-string].html
Normal file
34
leetcode-cn/problem (English)/统计是给定字符串前缀的字符串数目(English) [count-prefixes-of-a-given-string].html
Normal file
@ -0,0 +1,34 @@
|
||||
<p>You are given a string array <code>words</code> and a string <code>s</code>, where <code>words[i]</code> and <code>s</code> comprise only of <strong>lowercase English letters</strong>.</p>
|
||||
|
||||
<p>Return <em>the <strong>number of strings</strong> in</em> <code>words</code> <em>that are a <strong>prefix</strong> of</em> <code>s</code>.</p>
|
||||
|
||||
<p>A <strong>prefix</strong> of a string is a substring that occurs at the beginning of the string. A <b>substring</b> is a contiguous sequence of characters within a string.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> words = ["a","b","c","ab","bc","abc"], s = "abc"
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong>
|
||||
The strings in words which are a prefix of s = "abc" are:
|
||||
"a", "ab", and "abc".
|
||||
Thus the number of strings in words which are a prefix of s is 3.</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> words = ["a","a"], s = "aa"
|
||||
<strong>Output:</strong> 2
|
||||
<strong>Explanation:
|
||||
</strong>Both of the strings are a prefix of s.
|
||||
Note that the same string can occur multiple times in words, and it should be counted each time.</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= words.length <= 1000</code></li>
|
||||
<li><code>1 <= words[i].length, s.length <= 10</code></li>
|
||||
<li><code>words[i]</code> and <code>s</code> consist of lowercase English letters <strong>only</strong>.</li>
|
||||
</ul>
|
38
leetcode-cn/problem (English)/统计网格图中没有被保卫的格子数(English) [count-unguarded-cells-in-the-grid].html
Normal file
38
leetcode-cn/problem (English)/统计网格图中没有被保卫的格子数(English) [count-unguarded-cells-in-the-grid].html
Normal file
@ -0,0 +1,38 @@
|
||||
<p>You are given two integers <code>m</code> and <code>n</code> representing a <strong>0-indexed</strong> <code>m x n</code> grid. You are also given two 2D integer arrays <code>guards</code> and <code>walls</code> where <code>guards[i] = [row<sub>i</sub>, col<sub>i</sub>]</code> and <code>walls[j] = [row<sub>j</sub>, col<sub>j</sub>]</code> represent the positions of the <code>i<sup>th</sup></code> guard and <code>j<sup>th</sup></code> wall respectively.</p>
|
||||
|
||||
<p>A guard can see <b>every</b> cell in the four cardinal directions (north, east, south, or west) starting from their position unless <strong>obstructed</strong> by a wall or another guard. A cell is <strong>guarded</strong> if there is <strong>at least</strong> one guard that can see it.</p>
|
||||
|
||||
<p>Return<em> the number of unoccupied cells that are <strong>not</strong> <strong>guarded</strong>.</em></p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/10/example1drawio2.png" style="width: 300px; height: 204px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> m = 4, n = 6, guards = [[0,0],[1,1],[2,3]], walls = [[0,1],[2,2],[1,4]]
|
||||
<strong>Output:</strong> 7
|
||||
<strong>Explanation:</strong> The guarded and unguarded cells are shown in red and green respectively in the above diagram.
|
||||
There are a total of 7 unguarded cells, so we return 7.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/10/example2drawio.png" style="width: 200px; height: 201px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> m = 3, n = 3, guards = [[1,1]], walls = [[0,1],[1,0],[2,1],[1,2]]
|
||||
<strong>Output:</strong> 4
|
||||
<strong>Explanation:</strong> The unguarded cells are shown in green in the above diagram.
|
||||
There are a total of 4 unguarded cells, so we return 4.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= m, n <= 10<sup>5</sup></code></li>
|
||||
<li><code>2 <= m * n <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= guards.length, walls.length <= 5 * 10<sup>4</sup></code></li>
|
||||
<li><code>2 <= guards.length + walls.length <= m * n</code></li>
|
||||
<li><code>guards[i].length == walls[j].length == 2</code></li>
|
||||
<li><code>0 <= row<sub>i</sub>, row<sub>j</sub> < m</code></li>
|
||||
<li><code>0 <= col<sub>i</sub>, col<sub>j</sub> < n</code></li>
|
||||
<li>All the positions in <code>guards</code> and <code>walls</code> are <strong>unique</strong>.</li>
|
||||
</ul>
|
@ -0,0 +1,57 @@
|
||||
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>grid</code> of size <code>m x n</code> which represents a field. Each cell has one of three values:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>0</code> represents grass,</li>
|
||||
<li><code>1</code> represents fire,</li>
|
||||
<li><code>2</code> represents a wall that you and fire cannot pass through.</li>
|
||||
</ul>
|
||||
|
||||
<p>You are situated in the top-left cell, <code>(0, 0)</code>, and you want to travel to the safehouse at the bottom-right cell, <code>(m - 1, n - 1)</code>. Every minute, you may move to an <strong>adjacent</strong> grass cell. <strong>After</strong> your move, every fire cell will spread to all <strong>adjacent</strong> cells that are not walls.</p>
|
||||
|
||||
<p>Return <em>the <strong>maximum</strong> number of minutes that you can stay in your initial position before moving while still safely reaching the safehouse</em>. If this is impossible, return <code>-1</code>. If you can <strong>always</strong> reach the safehouse regardless of the minutes stayed, return <code>10<sup>9</sup></code>.</p>
|
||||
|
||||
<p>Note that even if the fire spreads to the safehouse immediately after you have reached it, it will be counted as safely reaching the safehouse.</p>
|
||||
|
||||
<p>A cell is <strong>adjacent</strong> to another cell if the former is directly north, east, south, or west of the latter (i.e., their sides are touching).</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/10/ex1new.jpg" style="width: 650px; height: 404px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> grid = [[0,2,0,0,0,0,0],[0,0,0,2,2,1,0],[0,2,0,0,1,2,0],[0,0,2,2,2,0,2],[0,0,0,0,0,0,0]]
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> The figure above shows the scenario where you stay in the initial position for 3 minutes.
|
||||
You will still be able to safely reach the safehouse.
|
||||
Staying for more than 3 minutes will not allow you to safely reach the safehouse.</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/10/ex2new2.jpg" style="width: 515px; height: 150px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> grid = [[0,0,0,0],[0,1,2,0],[0,2,0,0]]
|
||||
<strong>Output:</strong> -1
|
||||
<strong>Explanation:</strong> The figure above shows the scenario where you immediately move towards the safehouse.
|
||||
Fire will spread to any cell you move towards and it is impossible to safely reach the safehouse.
|
||||
Thus, -1 is returned.
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/10/ex3new.jpg" style="width: 174px; height: 150px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> grid = [[0,0,0],[2,2,0],[1,2,0]]
|
||||
<strong>Output:</strong> 1000000000
|
||||
<strong>Explanation:</strong> The figure above shows the initial grid.
|
||||
Notice that the fire is contained by walls and you will always be able to safely reach the safehouse.
|
||||
Thus, 10<sup>9</sup> is returned.
|
||||
</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 <= 300</code></li>
|
||||
<li><code>4 <= m * n <= 2 * 10<sup>4</sup></code></li>
|
||||
<li><code>grid[i][j]</code> is either <code>0</code>, <code>1</code>, or <code>2</code>.</li>
|
||||
<li><code>grid[0][0] == grid[m - 1][n - 1] == 0</code></li>
|
||||
</ul>
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,52 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2381",
|
||||
"questionFrontendId": "2252",
|
||||
"boundTopicId": null,
|
||||
"title": "Dynamic Pivoting of a Table",
|
||||
"titleSlug": "dynamic-pivoting-of-a-table",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Hard",
|
||||
"likes": 2,
|
||||
"dislikes": 2,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[{\"title\": \"Product's Price for Each Store\", \"titleSlug\": \"products-price-for-each-store\", \"difficulty\": \"Easy\", \"translatedTitle\": null}]",
|
||||
"exampleTestcases": null,
|
||||
"categoryTitle": "Database",
|
||||
"contributors": [],
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"75\", \"totalSubmission\": \"139\", \"totalAcceptedRaw\": 75, \"totalSubmissionRaw\": 139, \"acRate\": \"54.0%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\":{\"Products\":[\"product_id\",\"store\",\"price\"]},\"rows\":{\"Products\":[[1,\"Shop\",110],[1,\"LC_Store\",100],[2,\"Nozama\",200],[2,\"Souq\",190],[3,\"Shop\",1000],[3,\"Souq\",1900]]}}",
|
||||
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Products (product_id int, store varchar(7), price int)\"\n ],\n \"mssql\": [\n \"Create table Products (product_id int, store varchar(7), price int)\"\n ],\n \"oraclesql\": [\n \"Create table Products (product_id int, store varchar(7), price int)\"\n ],\n \"database\": true,\n \"manual\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Create table If Not Exists Products (product_id int, store varchar(7), price int)",
|
||||
"Truncate table Products",
|
||||
"insert into Products (product_id, store, price) values ('1', 'Shop', '110')",
|
||||
"insert into Products (product_id, store, price) values ('1', 'LC_Store', '100')",
|
||||
"insert into Products (product_id, store, price) values ('2', 'Nozama', '200')",
|
||||
"insert into Products (product_id, store, price) values ('2', 'Souq', '190')",
|
||||
"insert into Products (product_id, store, price) values ('3', 'Shop', '1000')",
|
||||
"insert into Products (product_id, store, price) values ('3', 'Souq', '1900')"
|
||||
],
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2382",
|
||||
"questionFrontendId": "2253",
|
||||
"boundTopicId": null,
|
||||
"title": "Dynamic Unpivoting of a Table",
|
||||
"titleSlug": "dynamic-unpivoting-of-a-table",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Hard",
|
||||
"likes": 2,
|
||||
"dislikes": 2,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[{\"title\": \"Rearrange Products Table\", \"titleSlug\": \"rearrange-products-table\", \"difficulty\": \"Easy\", \"translatedTitle\": null}]",
|
||||
"exampleTestcases": null,
|
||||
"categoryTitle": "Database",
|
||||
"contributors": [],
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"60\", \"totalSubmission\": \"96\", \"totalAcceptedRaw\": 60, \"totalSubmissionRaw\": 96, \"acRate\": \"62.5%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\": {\"Products\": [\"product_id\", \"LC_Store\", \"Nozama\", \"Shop\", \"Souq\"]}, \"rows\": {\"Products\": [[1, 100, null, 110, null], [2, null, 200, null, 190], [3, null, null, 1000, 1900]]}}",
|
||||
"metaData": "{\n \"mysql\": [],\n \"mssql\": [],\n \"oraclesql\": [],\n \"database\": true,\n \"manual\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Truncate table Products",
|
||||
"insert into Products (product_id, LC_Store, Nozama, Shop, Souq) values ('1', '100', 'None', '110', 'None')",
|
||||
"insert into Products (product_id, LC_Store, Nozama, Shop, Souq) values ('2', 'None', '200', 'None', '190')",
|
||||
"insert into Products (product_id, LC_Store, Nozama, Shop, Souq) values ('3', 'None', 'None', '1000', '1900')"
|
||||
],
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}
|
155
leetcode/originData/count-unguarded-cells-in-the-grid.json
Normal file
155
leetcode/originData/count-unguarded-cells-in-the-grid.json
Normal file
File diff suppressed because one or more lines are too long
157
leetcode/originData/escape-the-spreading-fire.json
Normal file
157
leetcode/originData/escape-the-spreading-fire.json
Normal file
File diff suppressed because one or more lines are too long
174
leetcode/originData/intersection-of-multiple-arrays.json
Normal file
174
leetcode/originData/intersection-of-multiple-arrays.json
Normal file
File diff suppressed because one or more lines are too long
155
leetcode/originData/k-divisible-elements-subarrays.json
Normal file
155
leetcode/originData/k-divisible-elements-subarrays.json
Normal file
File diff suppressed because one or more lines are too long
155
leetcode/originData/minimum-average-difference.json
Normal file
155
leetcode/originData/minimum-average-difference.json
Normal file
File diff suppressed because one or more lines are too long
155
leetcode/originData/minimum-consecutive-cards-to-pick-up.json
Normal file
155
leetcode/originData/minimum-consecutive-cards-to-pick-up.json
Normal file
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user