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
8a37a26300
commit
23a743b5be
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,65 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2613",
|
||||
"questionFrontendId": "2474",
|
||||
"categoryTitle": "Database",
|
||||
"boundTopicId": 1979417,
|
||||
"title": "Customers With Strictly Increasing Purchases",
|
||||
"titleSlug": "customers-with-strictly-increasing-purchases",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Hard",
|
||||
"likes": 0,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"contributors": [],
|
||||
"langToValidPlayground": null,
|
||||
"topicTags": [
|
||||
{
|
||||
"name": "Database",
|
||||
"slug": "database",
|
||||
"translatedName": "数据库",
|
||||
"__typename": "TopicTagNode"
|
||||
}
|
||||
],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"32\", \"totalSubmission\": \"49\", \"totalAcceptedRaw\": 32, \"totalSubmissionRaw\": 49, \"acRate\": \"65.3%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\": {\"Orders\": [\"order_id\", \"customer_id\", \"order_date\", \"price\"]}, \"rows\": {\"Orders\": [[1, 1, \"2019-07-01\", 1100], [2, 1, \"2019-11-01\", 1200], [3, 1, \"2020-05-26\", 3000], [4, 1, \"2021-08-31\", 3100], [5, 1, \"2022-12-07\", 4700], [6, 2, \"2015-01-01\", 700], [7, 2, \"2017-11-07\", 1000], [8, 3, \"2017-01-01\", 900], [9, 3, \"2018-11-07\", 900]]}}",
|
||||
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Orders (order_id int, customer_id int, order_date date, price int)\"\n ],\n \"mssql\": [\n \"Create table Orders (order_id int, customer_id int, order_date date, price int)\"\n ],\n \"oraclesql\": [\n \"Create table Orders (order_id int, customer_id int, order_date date, price int)\",\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 Orders (order_id int, customer_id int, order_date date, price int)",
|
||||
"Truncate table Orders",
|
||||
"insert into Orders (order_id, customer_id, order_date, price) values ('1', '1', '2019-07-01', '1100')",
|
||||
"insert into Orders (order_id, customer_id, order_date, price) values ('2', '1', '2019-11-01', '1200')",
|
||||
"insert into Orders (order_id, customer_id, order_date, price) values ('3', '1', '2020-05-26', '3000')",
|
||||
"insert into Orders (order_id, customer_id, order_date, price) values ('4', '1', '2021-08-31', '3100')",
|
||||
"insert into Orders (order_id, customer_id, order_date, price) values ('5', '1', '2022-12-07', '4700')",
|
||||
"insert into Orders (order_id, customer_id, order_date, price) values ('6', '2', '2015-01-01', '700')",
|
||||
"insert into Orders (order_id, customer_id, order_date, price) values ('7', '2', '2017-11-07', '1000')",
|
||||
"insert into Orders (order_id, customer_id, order_date, price) values ('8', '3', '2017-01-01', '900')",
|
||||
"insert into Orders (order_id, customer_id, order_date, price) values ('9', '3', '2018-11-07', '900')"
|
||||
],
|
||||
"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\": {\"Orders\": [\"order_id\", \"customer_id\", \"order_date\", \"price\"]}, \"rows\": {\"Orders\": [[1, 1, \"2019-07-01\", 1100], [2, 1, \"2019-11-01\", 1200], [3, 1, \"2020-05-26\", 3000], [4, 1, \"2021-08-31\", 3100], [5, 1, \"2022-12-07\", 4700], [6, 2, \"2015-01-01\", 700], [7, 2, \"2017-11-07\", 1000], [8, 3, \"2017-01-01\", 900], [9, 3, \"2018-11-07\", 900]]}}",
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
56
leetcode-cn/originData/[no content]form-a-chemical-bond.json
Normal file
56
leetcode-cn/originData/[no content]form-a-chemical-bond.json
Normal file
@ -0,0 +1,56 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2622",
|
||||
"questionFrontendId": "2480",
|
||||
"categoryTitle": "Database",
|
||||
"boundTopicId": 1988205,
|
||||
"title": "Form a Chemical Bond",
|
||||
"titleSlug": "form-a-chemical-bond",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Easy",
|
||||
"likes": 0,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"contributors": [],
|
||||
"langToValidPlayground": null,
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"17\", \"totalSubmission\": \"17\", \"totalAcceptedRaw\": 17, \"totalSubmissionRaw\": 17, \"acRate\": \"100.0%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\": {\"Elements\": [\"symbol\", \"type\", \"electrons\"]}, \"rows\": {\"Elements\": [[\"He\", \"Noble\", 0], [\"Na\", \"Metal\", 1], [\"Ca\", \"Metal\", 2], [\"La\", \"Metal\", 3], [\"Cl\", \"Nonmetal\", 1], [\"O\", \"Nonmetal\", 2], [\"N\", \"Nonmetal\", 3]]}}",
|
||||
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Elements (symbol varchar(2), type ENUM('Metal','Nonmetal','Noble'), electrons int)\"\n ],\n \"mssql\": [\n \"Create table Elements (symbol varchar(2), type varchar(8) not null check(type in ('Metal','Nonmetal','Noble')), electrons int)\\n\"\n ],\n \"oraclesql\": [\n \"Create table Elements (symbol varchar(2), type varchar(8) not null check(type in ('Metal','Nonmetal','Noble')), electrons int)\\n\"\n ],\n \"database\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Create table If Not Exists Elements (symbol varchar(2), type ENUM('Metal','Nonmetal','Noble'), electrons int)",
|
||||
"Truncate table Elements",
|
||||
"insert into Elements (symbol, type, electrons) values ('He', 'Noble', '0')",
|
||||
"insert into Elements (symbol, type, electrons) values ('Na', 'Metal', '1')",
|
||||
"insert into Elements (symbol, type, electrons) values ('Ca', 'Metal', '2')",
|
||||
"insert into Elements (symbol, type, electrons) values ('La', 'Metal', '3')",
|
||||
"insert into Elements (symbol, type, electrons) values ('Cl', 'Nonmetal', '1')",
|
||||
"insert into Elements (symbol, type, electrons) values ('O', 'Nonmetal', '2')",
|
||||
"insert into Elements (symbol, type, electrons) values ('N', 'Nonmetal', '3')"
|
||||
],
|
||||
"enableRunCode": true,
|
||||
"envInfo": "{\"mysql\":[\"MySQL\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"]}",
|
||||
"book": null,
|
||||
"isSubscribed": false,
|
||||
"isDailyQuestion": false,
|
||||
"dailyRecordStatus": null,
|
||||
"editorType": "CKEDITOR",
|
||||
"ugcQuestionId": null,
|
||||
"style": "LEETCODE",
|
||||
"exampleTestcases": "{\"headers\": {\"Elements\": [\"symbol\", \"type\", \"electrons\"]}, \"rows\": {\"Elements\": [[\"He\", \"Noble\", 0], [\"Na\", \"Metal\", 1], [\"Ca\", \"Metal\", 2], [\"La\", \"Metal\", 3], [\"Cl\", \"Nonmetal\", 1], [\"O\", \"Nonmetal\", 2], [\"N\", \"Nonmetal\", 3]]}}",
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
177
leetcode-cn/originData/number-of-beautiful-partitions.json
Normal file
177
leetcode-cn/originData/number-of-beautiful-partitions.json
Normal file
File diff suppressed because one or more lines are too long
177
leetcode-cn/originData/number-of-unequal-triplets-in-array.json
Normal file
177
leetcode-cn/originData/number-of-unequal-triplets-in-array.json
Normal file
File diff suppressed because one or more lines are too long
@ -0,0 +1,47 @@
|
||||
<p>给你一个 <strong>二叉搜索树</strong> 的根节点 <code>root</code> ,和一个由正整数组成、长度为 <code>n</code> 的数组 <code>queries</code> 。</p>
|
||||
|
||||
<p>请你找出一个长度为 <code>n</code> 的 <strong>二维</strong> 答案数组 <code>answer</code> ,其中 <code>answer[i] = [min<sub>i</sub>, max<sub>i</sub>]</code> :</p>
|
||||
|
||||
<ul>
|
||||
<li><code>min<sub>i</sub></code> 是树中小于等于 <code>queries[i]</code> 的 <strong>最大值</strong> 。如果不存在这样的值,则使用 <code>-1</code> 代替。</li>
|
||||
<li><code>max<sub>i</sub></code> 是树中大于等于 <code>queries[i]</code> 的 <strong>最小值</strong> 。如果不存在这样的值,则使用 <code>-1</code> 代替。</li>
|
||||
</ul>
|
||||
|
||||
<p>返回数组 <code>answer</code> 。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1 :</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/09/28/bstreeedrawioo.png" style="width: 261px; height: 281px;" /></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>root = [6,2,13,1,4,9,15,null,null,null,null,null,null,14], queries = [2,5,16]
|
||||
<strong>输出:</strong>[[2,2],[4,6],[15,-1]]
|
||||
<strong>解释:</strong>按下面的描述找出并返回查询的答案:
|
||||
- 树中小于等于 2 的最大值是 2 ,且大于等于 2 的最小值也是 2 。所以第一个查询的答案是 [2,2] 。
|
||||
- 树中小于等于 5 的最大值是 4 ,且大于等于 5 的最小值是 6 。所以第二个查询的答案是 [4,6] 。
|
||||
- 树中小于等于 16 的最大值是 15 ,且大于等于 16 的最小值不存在。所以第三个查询的答案是 [15,-1] 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2 :</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/09/28/bstttreee.png" style="width: 101px; height: 121px;" /></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>root = [4,null,9], queries = [3]
|
||||
<strong>输出:</strong>[[-1,4]]
|
||||
<strong>解释:</strong>树中不存在小于等于 3 的最大值,且大于等于 3 的最小值是 4 。所以查询的答案是 [-1,4] 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>树中节点的数目在范围 <code>[2, 10<sup>5</sup>]</code> 内</li>
|
||||
<li><code>1 <= Node.val <= 10<sup>6</sup></code></li>
|
||||
<li><code>n == queries.length</code></li>
|
||||
<li><code>1 <= n <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= queries[i] <= 10<sup>6</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,64 @@
|
||||
<p>给你一棵 <code>n</code> 个节点的树(一个无向、连通、无环图),每个节点表示一个城市,编号从 <code>0</code> 到 <code>n - 1</code> ,且恰好有 <code>n - 1</code> 条路。<code>0</code> 是首都。给你一个二维整数数组 <code>roads</code> ,其中 <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> ,表示城市 <code>a<sub>i</sub></code> 和 <code>b<sub>i</sub></code> 之间有一条 <strong>双向路</strong> 。</p>
|
||||
|
||||
<p>每个城市里有一个代表,他们都要去首都参加一个会议。</p>
|
||||
|
||||
<p>每座城市里有一辆车。给你一个整数 <code>seats</code> 表示每辆车里面座位的数目。</p>
|
||||
|
||||
<p>城市里的代表可以选择乘坐所在城市的车,或者乘坐其他城市的车。相邻城市之间一辆车的油耗是一升汽油。</p>
|
||||
|
||||
<p>请你返回到达首都最少需要多少升汽油。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/09/22/a4c380025e3ff0c379525e96a7d63a3.png" style="width: 303px; height: 332px;"></p>
|
||||
|
||||
<pre><b>输入:</b>roads = [[0,1],[0,2],[0,3]], seats = 5
|
||||
<b>输出:</b>3
|
||||
<b>解释:</b>
|
||||
- 代表 1 直接到达首都,消耗 1 升汽油。
|
||||
- 代表 2 直接到达首都,消耗 1 升汽油。
|
||||
- 代表 3 直接到达首都,消耗 1 升汽油。
|
||||
最少消耗 3 升汽油。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/11/16/2.png" style="width: 274px; height: 340px;"></p>
|
||||
|
||||
<pre><b>输入:</b>roads = [[3,1],[3,2],[1,0],[0,4],[0,5],[4,6]], seats = 2
|
||||
<b>输出:</b>7
|
||||
<b>解释:</b>
|
||||
- 代表 2 到达城市 3 ,消耗 1 升汽油。
|
||||
- 代表 2 和代表 3 一起到达城市 1 ,消耗 1 升汽油。
|
||||
- 代表 2 和代表 3 一起到达首都,消耗 1 升汽油。
|
||||
- 代表 1 直接到达首都,消耗 1 升汽油。
|
||||
- 代表 5 直接到达首都,消耗 1 升汽油。
|
||||
- 代表 6 到达城市 4 ,消耗 1 升汽油。
|
||||
- 代表 4 和代表 6 一起到达首都,消耗 1 升汽油。
|
||||
最少消耗 7 升汽油。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/09/27/efcf7f7be6830b8763639cfd01b690a.png" style="width: 108px; height: 86px;"></p>
|
||||
|
||||
<pre><b>输入:</b>roads = [], seats = 1
|
||||
<b>输出:</b>0
|
||||
<b>解释:</b>没有代表需要从别的城市到达首都。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n <= 10<sup>5</sup></code></li>
|
||||
<li><code>roads.length == n - 1</code></li>
|
||||
<li><code>roads[i].length == 2</code></li>
|
||||
<li><code>0 <= a<sub>i</sub>, b<sub>i</sub> < n</code></li>
|
||||
<li><code>a<sub>i</sub> != b<sub>i</sub></code></li>
|
||||
<li><code>roads</code> 表示一棵合法的树。</li>
|
||||
<li><code>1 <= seats <= 10<sup>5</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,51 @@
|
||||
<p>给你一个字符串 <code>s</code> ,每个字符是数字 <code>'1'</code> 到 <code>'9'</code> ,再给你两个整数 <code>k</code> 和 <code>minLength</code> 。</p>
|
||||
|
||||
<p>如果对 <code>s</code> 的分割满足以下条件,那么我们认为它是一个 <strong>完美</strong> 分割:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>s</code> 被分成 <code>k</code> 段互不相交的子字符串。</li>
|
||||
<li>每个子字符串长度都 <strong>至少</strong> 为 <code>minLength</code> 。</li>
|
||||
<li>每个子字符串的第一个字符都是一个 <b>质数</b> 数字,最后一个字符都是一个 <strong>非质数</strong> 数字。质数数字为 <code>'2'</code> ,<code>'3'</code> ,<code>'5'</code> 和 <code>'7'</code> ,剩下的都是非质数数字。</li>
|
||||
</ul>
|
||||
|
||||
<p>请你返回 <code>s</code> 的 <strong>完美</strong> 分割数目。由于答案可能很大,请返回答案对 <code>10<sup>9</sup> + 7</code> <strong>取余</strong> 后的结果。</p>
|
||||
|
||||
<p>一个 <strong>子字符串</strong> 是字符串中一段连续字符串序列。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>s = "23542185131", k = 3, minLength = 2
|
||||
<b>输出:</b>3
|
||||
<b>解释:</b>存在 3 种完美分割方案:
|
||||
"2354 | 218 | 5131"
|
||||
"2354 | 21851 | 31"
|
||||
"2354218 | 51 | 31"
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>s = "23542185131", k = 3, minLength = 3
|
||||
<b>输出:</b>1
|
||||
<b>解释:</b>存在一种完美分割方案:"2354 | 218 | 5131" 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<b>输入:</b>s = "3312958", k = 3, minLength = 1
|
||||
<b>输出:</b>1
|
||||
<b>解释:</b>存在一种完美分割方案:"331 | 29 | 58" 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= k, minLength <= s.length <= 1000</code></li>
|
||||
<li><code>s</code> 每个字符都为数字 <code>'1'</code> 到 <code>'9'</code> 之一。</li>
|
||||
</ul>
|
@ -0,0 +1,44 @@
|
||||
<p>给你一个下标从 <strong>0</strong> 开始的正整数数组 <code>nums</code> 。请你找出并统计满足下述条件的三元组 <code>(i, j, k)</code> 的数目:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= i < j < k < nums.length</code></li>
|
||||
<li><code>nums[i]</code>、<code>nums[j]</code> 和 <code>nums[k]</code> <strong>两两不同</strong> 。
|
||||
<ul>
|
||||
<li>换句话说:<code>nums[i] != nums[j]</code>、<code>nums[i] != nums[k]</code> 且 <code>nums[j] != nums[k]</code> 。</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<p>返回满足上述条件三元组的数目<em>。</em></p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>nums = [4,4,2,4,3]
|
||||
<strong>输出:</strong>3
|
||||
<strong>解释:</strong>下面列出的三元组均满足题目条件:
|
||||
- (0, 2, 4) 因为 4 != 2 != 3
|
||||
- (1, 2, 4) 因为 4 != 2 != 3
|
||||
- (2, 3, 4) 因为 2 != 4 != 3
|
||||
共计 3 个三元组,返回 3 。
|
||||
注意 (2, 0, 4) 不是有效的三元组,因为 2 > 0 。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>nums = [1,1,1,1,1]
|
||||
<strong>输出:</strong>0
|
||||
<strong>解释:</strong>不存在满足条件的三元组,所以返回 0 。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>3 <= nums.length <= 100</code></li>
|
||||
<li><code>1 <= nums[i] <= 1000</code></li>
|
||||
</ul>
|
@ -0,0 +1,41 @@
|
||||
<p>You are given the <code>root</code> of a <strong>binary search tree </strong>and an array <code>queries</code> of size <code>n</code> consisting of positive integers.</p>
|
||||
|
||||
<p>Find a <strong>2D</strong> array <code>answer</code> of size <code>n</code> where <code>answer[i] = [min<sub>i</sub>, max<sub>i</sub>]</code>:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>min<sub>i</sub></code> is the <strong>largest</strong> value in the tree that is smaller than or equal to <code>queries[i]</code>. If a such value does not exist, add <code>-1</code> instead.</li>
|
||||
<li><code>max<sub>i</sub></code> is the <strong>smallest</strong> value in the tree that is greater than or equal to <code>queries[i]</code>. If a such value does not exist, add <code>-1</code> instead.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the array</em> <code>answer</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/09/28/bstreeedrawioo.png" style="width: 261px; height: 281px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> root = [6,2,13,1,4,9,15,null,null,null,null,null,null,14], queries = [2,5,16]
|
||||
<strong>Output:</strong> [[2,2],[4,6],[15,-1]]
|
||||
<strong>Explanation:</strong> We answer the queries in the following way:
|
||||
- The largest number that is smaller or equal than 2 in the tree is 2, and the smallest number that is greater or equal than 2 is still 2. So the answer for the first query is [2,2].
|
||||
- The largest number that is smaller or equal than 5 in the tree is 4, and the smallest number that is greater or equal than 5 is 6. So the answer for the second query is [4,6].
|
||||
- The largest number that is smaller or equal than 16 in the tree is 15, and the smallest number that is greater or equal than 16 does not exist. So the answer for the third query is [15,-1].
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/09/28/bstttreee.png" style="width: 101px; height: 121px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> root = [4,null,9], queries = [3]
|
||||
<strong>Output:</strong> [[-1,4]]
|
||||
<strong>Explanation:</strong> The largest number that is smaller or equal to 3 in the tree does not exist, and the smallest number that is greater or equal to 3 is 4. So the answer for the query is [-1,4].
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>The number of nodes in the tree is in the range <code>[2, 10<sup>5</sup>]</code>.</li>
|
||||
<li><code>1 <= Node.val <= 10<sup>6</sup></code></li>
|
||||
<li><code>n == queries.length</code></li>
|
||||
<li><code>1 <= n <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= queries[i] <= 10<sup>6</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,61 @@
|
||||
<p>There is a tree (i.e., a connected, undirected graph with no cycles) structure country network consisting of <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> roads. The capital city is city <code>0</code>. You are given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidirectional road</strong> connecting cities <code>a<sub>i</sub></code> and <code>b<sub>i</sub></code>.</p>
|
||||
|
||||
<p>There is a meeting for the representatives of each city. The meeting is in the capital city.</p>
|
||||
|
||||
<p>There is a car in each city. You are given an integer <code>seats</code> that indicates the number of seats in each car.</p>
|
||||
|
||||
<p>A representative can use the car in their city to travel or change the car and ride with another representative. The cost of traveling between two cities is one liter of fuel.</p>
|
||||
|
||||
<p>Return <em>the minimum number of liters of fuel to reach the capital city</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/09/22/a4c380025e3ff0c379525e96a7d63a3.png" style="width: 303px; height: 332px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> roads = [[0,1],[0,2],[0,3]], seats = 5
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong>
|
||||
- Representative<sub>1</sub> goes directly to the capital with 1 liter of fuel.
|
||||
- Representative<sub>2</sub> goes directly to the capital with 1 liter of fuel.
|
||||
- Representative<sub>3</sub> goes directly to the capital with 1 liter of fuel.
|
||||
It costs 3 liters of fuel at minimum.
|
||||
It can be proven that 3 is the minimum number of liters of fuel needed.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/11/16/2.png" style="width: 274px; height: 340px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> roads = [[3,1],[3,2],[1,0],[0,4],[0,5],[4,6]], seats = 2
|
||||
<strong>Output:</strong> 7
|
||||
<strong>Explanation:</strong>
|
||||
- Representative<sub>2</sub> goes directly to city 3 with 1 liter of fuel.
|
||||
- Representative<sub>2</sub> and representative<sub>3</sub> go together to city 1 with 1 liter of fuel.
|
||||
- Representative<sub>2</sub> and representative<sub>3</sub> go together to the capital with 1 liter of fuel.
|
||||
- Representative<sub>1</sub> goes directly to the capital with 1 liter of fuel.
|
||||
- Representative<sub>5</sub> goes directly to the capital with 1 liter of fuel.
|
||||
- Representative<sub>6</sub> goes directly to city 4 with 1 liter of fuel.
|
||||
- Representative<sub>4</sub> and representative<sub>6</sub> go together to the capital with 1 liter of fuel.
|
||||
It costs 7 liters of fuel at minimum.
|
||||
It can be proven that 7 is the minimum number of liters of fuel needed.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/09/27/efcf7f7be6830b8763639cfd01b690a.png" style="width: 108px; height: 86px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> roads = [], seats = 1
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong> No representatives need to travel to the capital city.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n <= 10<sup>5</sup></code></li>
|
||||
<li><code>roads.length == n - 1</code></li>
|
||||
<li><code>roads[i].length == 2</code></li>
|
||||
<li><code>0 <= a<sub>i</sub>, b<sub>i</sub> < n</code></li>
|
||||
<li><code>a<sub>i</sub> != b<sub>i</sub></code></li>
|
||||
<li><code>roads</code> represents a valid tree.</li>
|
||||
<li><code>1 <= seats <= 10<sup>5</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,49 @@
|
||||
<p>You are given a string <code>s</code> that consists of the digits <code>'1'</code> to <code>'9'</code> and two integers <code>k</code> and <code>minLength</code>.</p>
|
||||
|
||||
<p>A partition of <code>s</code> is called <strong>beautiful</strong> if:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>s</code> is partitioned into <code>k</code> non-intersecting substrings.</li>
|
||||
<li>Each substring has a length of <strong>at least</strong> <code>minLength</code>.</li>
|
||||
<li>Each substring starts with a <strong>prime</strong> digit and ends with a <strong>non-prime</strong> digit. Prime digits are <code>'2'</code>, <code>'3'</code>, <code>'5'</code>, and <code>'7'</code>, and the rest of the digits are non-prime.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return<em> the number of <strong>beautiful</strong> partitions of </em><code>s</code>. Since the answer may be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
|
||||
|
||||
<p>A <strong>substring</strong> is a contiguous sequence of characters within a string.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "23542185131", k = 3, minLength = 2
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> There exists three ways to create a beautiful partition:
|
||||
"2354 | 218 | 5131"
|
||||
"2354 | 21851 | 31"
|
||||
"2354218 | 51 | 31"
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "23542185131", k = 3, minLength = 3
|
||||
<strong>Output:</strong> 1
|
||||
<strong>Explanation:</strong> There exists one way to create a beautiful partition: "2354 | 218 | 5131".
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "3312958", k = 3, minLength = 1
|
||||
<strong>Output:</strong> 1
|
||||
<strong>Explanation:</strong> There exists one way to create a beautiful partition: "331 | 29 | 58".
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= k, minLength <= s.length <= 1000</code></li>
|
||||
<li><code>s</code> consists of the digits <code>'1'</code> to <code>'9'</code>.</li>
|
||||
</ul>
|
@ -0,0 +1,42 @@
|
||||
<p>You are given a <strong>0-indexed</strong> array of positive integers <code>nums</code>. Find the number of triplets <code>(i, j, k)</code> that meet the following conditions:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= i < j < k < nums.length</code></li>
|
||||
<li><code>nums[i]</code>, <code>nums[j]</code>, and <code>nums[k]</code> are <strong>pairwise distinct</strong>.
|
||||
<ul>
|
||||
<li>In other words, <code>nums[i] != nums[j]</code>, <code>nums[i] != nums[k]</code>, and <code>nums[j] != nums[k]</code>.</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the number of triplets that meet the conditions.</em></p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [4,4,2,4,3]
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> The following triplets meet the conditions:
|
||||
- (0, 2, 4) because 4 != 2 != 3
|
||||
- (1, 2, 4) because 4 != 2 != 3
|
||||
- (2, 3, 4) because 2 != 4 != 3
|
||||
Since there are 3 triplets, we return 3.
|
||||
Note that (2, 0, 4) is not a valid triplet because 2 > 0.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,1,1,1,1]
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong> No triplets meet the conditions so we return 0.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>3 <= nums.length <= 100</code></li>
|
||||
<li><code>1 <= nums[i] <= 1000</code></li>
|
||||
</ul>
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,62 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2613",
|
||||
"questionFrontendId": "2474",
|
||||
"boundTopicId": null,
|
||||
"title": "Customers With Strictly Increasing Purchases",
|
||||
"titleSlug": "customers-with-strictly-increasing-purchases",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Hard",
|
||||
"likes": 5,
|
||||
"dislikes": 2,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[{\"title\": \"Report Contiguous Dates\", \"titleSlug\": \"report-contiguous-dates\", \"difficulty\": \"Hard\", \"translatedTitle\": null}, {\"title\": \"Find the Start and End Number of Continuous Ranges\", \"titleSlug\": \"find-the-start-and-end-number-of-continuous-ranges\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
|
||||
"exampleTestcases": "{\"headers\": {\"Orders\": [\"order_id\", \"customer_id\", \"order_date\", \"price\"]}, \"rows\": {\"Orders\": [[1, 1, \"2019-07-01\", 1100], [2, 1, \"2019-11-01\", 1200], [3, 1, \"2020-05-26\", 3000], [4, 1, \"2021-08-31\", 3100], [5, 1, \"2022-12-07\", 4700], [6, 2, \"2015-01-01\", 700], [7, 2, \"2017-11-07\", 1000], [8, 3, \"2017-01-01\", 900], [9, 3, \"2018-11-07\", 900]]}}",
|
||||
"categoryTitle": "Database",
|
||||
"contributors": [],
|
||||
"topicTags": [
|
||||
{
|
||||
"name": "Database",
|
||||
"slug": "database",
|
||||
"translatedName": null,
|
||||
"__typename": "TopicTagNode"
|
||||
}
|
||||
],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"137\", \"totalSubmission\": \"192\", \"totalAcceptedRaw\": 137, \"totalSubmissionRaw\": 192, \"acRate\": \"71.4%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\": {\"Orders\": [\"order_id\", \"customer_id\", \"order_date\", \"price\"]}, \"rows\": {\"Orders\": [[1, 1, \"2019-07-01\", 1100], [2, 1, \"2019-11-01\", 1200], [3, 1, \"2020-05-26\", 3000], [4, 1, \"2021-08-31\", 3100], [5, 1, \"2022-12-07\", 4700], [6, 2, \"2015-01-01\", 700], [7, 2, \"2017-11-07\", 1000], [8, 3, \"2017-01-01\", 900], [9, 3, \"2018-11-07\", 900]]}}",
|
||||
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Orders (order_id int, customer_id int, order_date date, price int)\"\n ],\n \"mssql\": [\n \"Create table Orders (order_id int, customer_id int, order_date date, price int)\"\n ],\n \"oraclesql\": [\n \"Create table Orders (order_id int, customer_id int, order_date date, price int)\",\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 Orders (order_id int, customer_id int, order_date date, price int)",
|
||||
"Truncate table Orders",
|
||||
"insert into Orders (order_id, customer_id, order_date, price) values ('1', '1', '2019-07-01', '1100')",
|
||||
"insert into Orders (order_id, customer_id, order_date, price) values ('2', '1', '2019-11-01', '1200')",
|
||||
"insert into Orders (order_id, customer_id, order_date, price) values ('3', '1', '2020-05-26', '3000')",
|
||||
"insert into Orders (order_id, customer_id, order_date, price) values ('4', '1', '2021-08-31', '3100')",
|
||||
"insert into Orders (order_id, customer_id, order_date, price) values ('5', '1', '2022-12-07', '4700')",
|
||||
"insert into Orders (order_id, customer_id, order_date, price) values ('6', '2', '2015-01-01', '700')",
|
||||
"insert into Orders (order_id, customer_id, order_date, price) values ('7', '2', '2017-11-07', '1000')",
|
||||
"insert into Orders (order_id, customer_id, order_date, price) values ('8', '3', '2017-01-01', '900')",
|
||||
"insert into Orders (order_id, customer_id, order_date, price) values ('9', '3', '2018-11-07', '900')"
|
||||
],
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}
|
53
leetcode/originData/[no content]form-a-chemical-bond.json
Normal file
53
leetcode/originData/[no content]form-a-chemical-bond.json
Normal file
@ -0,0 +1,53 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "2622",
|
||||
"questionFrontendId": "2480",
|
||||
"boundTopicId": null,
|
||||
"title": "Form a Chemical Bond",
|
||||
"titleSlug": "form-a-chemical-bond",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Easy",
|
||||
"likes": 0,
|
||||
"dislikes": 2,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"exampleTestcases": null,
|
||||
"categoryTitle": "Database",
|
||||
"contributors": [],
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"45\", \"totalSubmission\": \"63\", \"totalAcceptedRaw\": 45, \"totalSubmissionRaw\": 63, \"acRate\": \"71.4%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\": {\"Elements\": [\"symbol\", \"type\", \"electrons\"]}, \"rows\": {\"Elements\": [[\"He\", \"Noble\", 0], [\"Na\", \"Metal\", 1], [\"Ca\", \"Metal\", 2], [\"La\", \"Metal\", 3], [\"Cl\", \"Nonmetal\", 1], [\"O\", \"Nonmetal\", 2], [\"N\", \"Nonmetal\", 3]]}}",
|
||||
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Elements (symbol varchar(2), type ENUM('Metal','Nonmetal','Noble'), electrons int)\"\n ],\n \"mssql\": [\n \"Create table Elements (symbol varchar(2), type varchar(8) not null check(type in ('Metal','Nonmetal','Noble')), electrons int)\\n\"\n ],\n \"oraclesql\": [\n \"Create table Elements (symbol varchar(2), type varchar(8) not null check(type in ('Metal','Nonmetal','Noble')), electrons int)\\n\"\n ],\n \"database\": true\n}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Create table If Not Exists Elements (symbol varchar(2), type ENUM('Metal','Nonmetal','Noble'), electrons int)",
|
||||
"Truncate table Elements",
|
||||
"insert into Elements (symbol, type, electrons) values ('He', 'Noble', '0')",
|
||||
"insert into Elements (symbol, type, electrons) values ('Na', 'Metal', '1')",
|
||||
"insert into Elements (symbol, type, electrons) values ('Ca', 'Metal', '2')",
|
||||
"insert into Elements (symbol, type, electrons) values ('La', 'Metal', '3')",
|
||||
"insert into Elements (symbol, type, electrons) values ('Cl', 'Nonmetal', '1')",
|
||||
"insert into Elements (symbol, type, electrons) values ('O', 'Nonmetal', '2')",
|
||||
"insert into Elements (symbol, type, electrons) values ('N', 'Nonmetal', '3')"
|
||||
],
|
||||
"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
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
174
leetcode/originData/number-of-beautiful-partitions.json
Normal file
174
leetcode/originData/number-of-beautiful-partitions.json
Normal file
File diff suppressed because one or more lines are too long
174
leetcode/originData/number-of-unequal-triplets-in-array.json
Normal file
174
leetcode/originData/number-of-unequal-triplets-in-array.json
Normal file
File diff suppressed because one or more lines are too long
@ -0,0 +1,41 @@
|
||||
<p>You are given the <code>root</code> of a <strong>binary search tree </strong>and an array <code>queries</code> of size <code>n</code> consisting of positive integers.</p>
|
||||
|
||||
<p>Find a <strong>2D</strong> array <code>answer</code> of size <code>n</code> where <code>answer[i] = [min<sub>i</sub>, max<sub>i</sub>]</code>:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>min<sub>i</sub></code> is the <strong>largest</strong> value in the tree that is smaller than or equal to <code>queries[i]</code>. If a such value does not exist, add <code>-1</code> instead.</li>
|
||||
<li><code>max<sub>i</sub></code> is the <strong>smallest</strong> value in the tree that is greater than or equal to <code>queries[i]</code>. If a such value does not exist, add <code>-1</code> instead.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the array</em> <code>answer</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/09/28/bstreeedrawioo.png" style="width: 261px; height: 281px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> root = [6,2,13,1,4,9,15,null,null,null,null,null,null,14], queries = [2,5,16]
|
||||
<strong>Output:</strong> [[2,2],[4,6],[15,-1]]
|
||||
<strong>Explanation:</strong> We answer the queries in the following way:
|
||||
- The largest number that is smaller or equal than 2 in the tree is 2, and the smallest number that is greater or equal than 2 is still 2. So the answer for the first query is [2,2].
|
||||
- The largest number that is smaller or equal than 5 in the tree is 4, and the smallest number that is greater or equal than 5 is 6. So the answer for the second query is [4,6].
|
||||
- The largest number that is smaller or equal than 16 in the tree is 15, and the smallest number that is greater or equal than 16 does not exist. So the answer for the third query is [15,-1].
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/09/28/bstttreee.png" style="width: 101px; height: 121px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> root = [4,null,9], queries = [3]
|
||||
<strong>Output:</strong> [[-1,4]]
|
||||
<strong>Explanation:</strong> The largest number that is smaller or equal to 3 in the tree does not exist, and the smallest number that is greater or equal to 3 is 4. So the answer for the query is [-1,4].
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>The number of nodes in the tree is in the range <code>[2, 10<sup>5</sup>]</code>.</li>
|
||||
<li><code>1 <= Node.val <= 10<sup>6</sup></code></li>
|
||||
<li><code>n == queries.length</code></li>
|
||||
<li><code>1 <= n <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= queries[i] <= 10<sup>6</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,61 @@
|
||||
<p>There is a tree (i.e., a connected, undirected graph with no cycles) structure country network consisting of <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> roads. The capital city is city <code>0</code>. You are given a 2D integer array <code>roads</code> where <code>roads[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists a <strong>bidirectional road</strong> connecting cities <code>a<sub>i</sub></code> and <code>b<sub>i</sub></code>.</p>
|
||||
|
||||
<p>There is a meeting for the representatives of each city. The meeting is in the capital city.</p>
|
||||
|
||||
<p>There is a car in each city. You are given an integer <code>seats</code> that indicates the number of seats in each car.</p>
|
||||
|
||||
<p>A representative can use the car in their city to travel or change the car and ride with another representative. The cost of traveling between two cities is one liter of fuel.</p>
|
||||
|
||||
<p>Return <em>the minimum number of liters of fuel to reach the capital city</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/09/22/a4c380025e3ff0c379525e96a7d63a3.png" style="width: 303px; height: 332px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> roads = [[0,1],[0,2],[0,3]], seats = 5
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong>
|
||||
- Representative<sub>1</sub> goes directly to the capital with 1 liter of fuel.
|
||||
- Representative<sub>2</sub> goes directly to the capital with 1 liter of fuel.
|
||||
- Representative<sub>3</sub> goes directly to the capital with 1 liter of fuel.
|
||||
It costs 3 liters of fuel at minimum.
|
||||
It can be proven that 3 is the minimum number of liters of fuel needed.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/11/16/2.png" style="width: 274px; height: 340px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> roads = [[3,1],[3,2],[1,0],[0,4],[0,5],[4,6]], seats = 2
|
||||
<strong>Output:</strong> 7
|
||||
<strong>Explanation:</strong>
|
||||
- Representative<sub>2</sub> goes directly to city 3 with 1 liter of fuel.
|
||||
- Representative<sub>2</sub> and representative<sub>3</sub> go together to city 1 with 1 liter of fuel.
|
||||
- Representative<sub>2</sub> and representative<sub>3</sub> go together to the capital with 1 liter of fuel.
|
||||
- Representative<sub>1</sub> goes directly to the capital with 1 liter of fuel.
|
||||
- Representative<sub>5</sub> goes directly to the capital with 1 liter of fuel.
|
||||
- Representative<sub>6</sub> goes directly to city 4 with 1 liter of fuel.
|
||||
- Representative<sub>4</sub> and representative<sub>6</sub> go together to the capital with 1 liter of fuel.
|
||||
It costs 7 liters of fuel at minimum.
|
||||
It can be proven that 7 is the minimum number of liters of fuel needed.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2022/09/27/efcf7f7be6830b8763639cfd01b690a.png" style="width: 108px; height: 86px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> roads = [], seats = 1
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong> No representatives need to travel to the capital city.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n <= 10<sup>5</sup></code></li>
|
||||
<li><code>roads.length == n - 1</code></li>
|
||||
<li><code>roads[i].length == 2</code></li>
|
||||
<li><code>0 <= a<sub>i</sub>, b<sub>i</sub> < n</code></li>
|
||||
<li><code>a<sub>i</sub> != b<sub>i</sub></code></li>
|
||||
<li><code>roads</code> represents a valid tree.</li>
|
||||
<li><code>1 <= seats <= 10<sup>5</sup></code></li>
|
||||
</ul>
|
49
leetcode/problem/number-of-beautiful-partitions.html
Normal file
49
leetcode/problem/number-of-beautiful-partitions.html
Normal file
@ -0,0 +1,49 @@
|
||||
<p>You are given a string <code>s</code> that consists of the digits <code>'1'</code> to <code>'9'</code> and two integers <code>k</code> and <code>minLength</code>.</p>
|
||||
|
||||
<p>A partition of <code>s</code> is called <strong>beautiful</strong> if:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>s</code> is partitioned into <code>k</code> non-intersecting substrings.</li>
|
||||
<li>Each substring has a length of <strong>at least</strong> <code>minLength</code>.</li>
|
||||
<li>Each substring starts with a <strong>prime</strong> digit and ends with a <strong>non-prime</strong> digit. Prime digits are <code>'2'</code>, <code>'3'</code>, <code>'5'</code>, and <code>'7'</code>, and the rest of the digits are non-prime.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return<em> the number of <strong>beautiful</strong> partitions of </em><code>s</code>. Since the answer may be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
|
||||
|
||||
<p>A <strong>substring</strong> is a contiguous sequence of characters within a string.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "23542185131", k = 3, minLength = 2
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> There exists three ways to create a beautiful partition:
|
||||
"2354 | 218 | 5131"
|
||||
"2354 | 21851 | 31"
|
||||
"2354218 | 51 | 31"
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "23542185131", k = 3, minLength = 3
|
||||
<strong>Output:</strong> 1
|
||||
<strong>Explanation:</strong> There exists one way to create a beautiful partition: "2354 | 218 | 5131".
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> s = "3312958", k = 3, minLength = 1
|
||||
<strong>Output:</strong> 1
|
||||
<strong>Explanation:</strong> There exists one way to create a beautiful partition: "331 | 29 | 58".
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= k, minLength <= s.length <= 1000</code></li>
|
||||
<li><code>s</code> consists of the digits <code>'1'</code> to <code>'9'</code>.</li>
|
||||
</ul>
|
42
leetcode/problem/number-of-unequal-triplets-in-array.html
Normal file
42
leetcode/problem/number-of-unequal-triplets-in-array.html
Normal file
@ -0,0 +1,42 @@
|
||||
<p>You are given a <strong>0-indexed</strong> array of positive integers <code>nums</code>. Find the number of triplets <code>(i, j, k)</code> that meet the following conditions:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= i < j < k < nums.length</code></li>
|
||||
<li><code>nums[i]</code>, <code>nums[j]</code>, and <code>nums[k]</code> are <strong>pairwise distinct</strong>.
|
||||
<ul>
|
||||
<li>In other words, <code>nums[i] != nums[j]</code>, <code>nums[i] != nums[k]</code>, and <code>nums[j] != nums[k]</code>.</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the number of triplets that meet the conditions.</em></p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [4,4,2,4,3]
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> The following triplets meet the conditions:
|
||||
- (0, 2, 4) because 4 != 2 != 3
|
||||
- (1, 2, 4) because 4 != 2 != 3
|
||||
- (2, 3, 4) because 2 != 4 != 3
|
||||
Since there are 3 triplets, we return 3.
|
||||
Note that (2, 0, 4) is not a valid triplet because 2 > 0.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,1,1,1,1]
|
||||
<strong>Output:</strong> 0
|
||||
<strong>Explanation:</strong> No triplets meet the conditions so we return 0.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>3 <= nums.length <= 100</code></li>
|
||||
<li><code>1 <= nums[i] <= 1000</code></li>
|
||||
</ul>
|
Loading…
Reference in New Issue
Block a user