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
321b55e52f
commit
85985929d8
@ -1,6 +1,6 @@
|
|||||||
# 力扣题库(完整版)
|
# 力扣题库(完整版)
|
||||||
|
|
||||||
> 最后更新日期: **2022.07.29**
|
> 最后更新日期: **2022.08.26**
|
||||||
>
|
>
|
||||||
> 使用脚本前请务必仔细完整阅读本 `README.md` 文件
|
> 使用脚本前请务必仔细完整阅读本 `README.md` 文件
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,70 @@
|
|||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"question": {
|
||||||
|
"questionId": "2515",
|
||||||
|
"questionFrontendId": "2372",
|
||||||
|
"categoryTitle": "Database",
|
||||||
|
"boundTopicId": 1746115,
|
||||||
|
"title": "Calculate the Influence of Each Salesperson",
|
||||||
|
"titleSlug": "calculate-the-influence-of-each-salesperson",
|
||||||
|
"content": null,
|
||||||
|
"translatedTitle": " Calculate the Influence of Each Salesperson",
|
||||||
|
"translatedContent": null,
|
||||||
|
"isPaidOnly": true,
|
||||||
|
"difficulty": "Medium",
|
||||||
|
"likes": 0,
|
||||||
|
"dislikes": 0,
|
||||||
|
"isLiked": null,
|
||||||
|
"similarQuestions": "[]",
|
||||||
|
"contributors": [],
|
||||||
|
"langToValidPlayground": null,
|
||||||
|
"topicTags": [
|
||||||
|
{
|
||||||
|
"name": "Database",
|
||||||
|
"slug": "database",
|
||||||
|
"translatedName": "数据库",
|
||||||
|
"__typename": "TopicTagNode"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"companyTagStats": null,
|
||||||
|
"codeSnippets": null,
|
||||||
|
"stats": "{\"totalAccepted\": \"63\", \"totalSubmission\": \"72\", \"totalAcceptedRaw\": 63, \"totalSubmissionRaw\": 72, \"acRate\": \"87.5%\"}",
|
||||||
|
"hints": [],
|
||||||
|
"solution": null,
|
||||||
|
"status": null,
|
||||||
|
"sampleTestCase": "{\"headers\":{\"Salesperson\":[\"salesperson_id\",\"name\"],\"Customer\":[\"customer_id\",\"salesperson_id\"],\"Sales\":[\"sale_id\",\"customer_id\",\"price\"]},\"rows\":{\"Salesperson\":[[1,\"Alice\"],[2,\"Bob\"],[3,\"Jerry\"]],\"Customer\":[[1,1],[2,1],[3,2]],\"Sales\":[[1,2,892],[2,1,354],[3,3,988],[4,3,856]]}}",
|
||||||
|
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Salesperson (salesperson_id int, name varchar(30))\",\n \"Create table If Not Exists Customer (customer_id int, salesperson_id int)\",\n \"Create table If Not Exists Sales (sale_id int, customer_id int, price int)\"\n ],\n \"mssql\": [\n \"Create table Salesperson (salesperson_id int, name varchar(30))\",\n \"Create table Customer (customer_id int, salesperson_id int)\",\n \"Create table Sales (sale_id int, customer_id int, price int)\"\n ],\n \"oraclesql\": [\n \"Create table Salesperson (salesperson_id int, name varchar(30))\",\n \"Create table Customer (customer_id int, salesperson_id int)\",\n \"Create table Sales (sale_id int, customer_id int, price int)\"\n ],\n \"database\": true\n}",
|
||||||
|
"judgerAvailable": true,
|
||||||
|
"judgeType": "large",
|
||||||
|
"mysqlSchemas": [
|
||||||
|
"Create table If Not Exists Salesperson (salesperson_id int, name varchar(30))",
|
||||||
|
"Create table If Not Exists Customer (customer_id int, salesperson_id int)",
|
||||||
|
"Create table If Not Exists Sales (sale_id int, customer_id int, price int)",
|
||||||
|
"Truncate table Salesperson",
|
||||||
|
"insert into Salesperson (salesperson_id, name) values ('1', 'Alice')",
|
||||||
|
"insert into Salesperson (salesperson_id, name) values ('2', 'Bob')",
|
||||||
|
"insert into Salesperson (salesperson_id, name) values ('3', 'Jerry')",
|
||||||
|
"Truncate table Customer",
|
||||||
|
"insert into Customer (customer_id, salesperson_id) values ('1', '1')",
|
||||||
|
"insert into Customer (customer_id, salesperson_id) values ('2', '1')",
|
||||||
|
"insert into Customer (customer_id, salesperson_id) values ('3', '2')",
|
||||||
|
"Truncate table Sales",
|
||||||
|
"insert into Sales (sale_id, customer_id, price) values ('1', '2', '892')",
|
||||||
|
"insert into Sales (sale_id, customer_id, price) values ('2', '1', '354')",
|
||||||
|
"insert into Sales (sale_id, customer_id, price) values ('3', '3', '988')",
|
||||||
|
"insert into Sales (sale_id, customer_id, price) values ('4', '3', '856')"
|
||||||
|
],
|
||||||
|
"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\":{\"Salesperson\":[\"salesperson_id\",\"name\"],\"Customer\":[\"customer_id\",\"salesperson_id\"],\"Sales\":[\"sale_id\",\"customer_id\",\"price\"]},\"rows\":{\"Salesperson\":[[1,\"Alice\"],[2,\"Bob\"],[3,\"Jerry\"]],\"Customer\":[[1,1],[2,1],[3,2]],\"Sales\":[[1,2,892],[2,1,354],[3,3,988],[4,3,856]]}}",
|
||||||
|
"__typename": "QuestionNode"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
65
leetcode-cn/originData/[no content]generate-the-invoice.json
Normal file
65
leetcode-cn/originData/[no content]generate-the-invoice.json
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"question": {
|
||||||
|
"questionId": "2501",
|
||||||
|
"questionFrontendId": "2362",
|
||||||
|
"categoryTitle": "Database",
|
||||||
|
"boundTopicId": 1723074,
|
||||||
|
"title": "Generate the Invoice",
|
||||||
|
"titleSlug": "generate-the-invoice",
|
||||||
|
"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\": \"70\", \"totalSubmission\": \"84\", \"totalAcceptedRaw\": 70, \"totalSubmissionRaw\": 84, \"acRate\": \"83.3%\"}",
|
||||||
|
"hints": [],
|
||||||
|
"solution": null,
|
||||||
|
"status": null,
|
||||||
|
"sampleTestCase": "{\"headers\":{\"Products\":[\"product_id\",\"price\"],\"Purchases\":[\"invoice_id\",\"product_id\",\"quantity\"]},\"rows\":{\"Products\":[[1,100],[2,200]],\"Purchases\":[[1,1,2],[3,2,1],[2,2,3],[2,1,4],[4,1,10]]}}",
|
||||||
|
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Products (product_id int, price int)\",\n \"Create table If Not Exists Purchases (invoice_id int, product_id int, quantity int)\"\n ],\n \"mssql\": [\n \"Create table Products (product_id int, price int)\",\n \"Create table Purchases (invoice_id int, product_id int, quantity int)\"\n ],\n \"oraclesql\": [\n \"Create table Products (product_id int, price int)\",\n \"Create table Purchases (invoice_id int, product_id int, quantity int)\"\n ],\n \"database\": true\n}",
|
||||||
|
"judgerAvailable": true,
|
||||||
|
"judgeType": "large",
|
||||||
|
"mysqlSchemas": [
|
||||||
|
"Create table If Not Exists Products (product_id int, price int)",
|
||||||
|
"Create table If Not Exists Purchases (invoice_id int, product_id int, quantity int)",
|
||||||
|
"Truncate table Products",
|
||||||
|
"insert into Products (product_id, price) values ('1', '100')",
|
||||||
|
"insert into Products (product_id, price) values ('2', '200')",
|
||||||
|
"Truncate table Purchases",
|
||||||
|
"insert into Purchases (invoice_id, product_id, quantity) values ('1', '1', '2')",
|
||||||
|
"insert into Purchases (invoice_id, product_id, quantity) values ('3', '2', '1')",
|
||||||
|
"insert into Purchases (invoice_id, product_id, quantity) values ('2', '2', '3')",
|
||||||
|
"insert into Purchases (invoice_id, product_id, quantity) values ('2', '1', '4')",
|
||||||
|
"insert into Purchases (invoice_id, product_id, quantity) values ('4', '1', '10')"
|
||||||
|
],
|
||||||
|
"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\",\"price\"],\"Purchases\":[\"invoice_id\",\"product_id\",\"quantity\"]},\"rows\":{\"Products\":[[1,100],[2,200]],\"Purchases\":[[1,1,2],[3,2,1],[2,2,3],[2,1,4],[4,1,10]]}}",
|
||||||
|
"__typename": "QuestionNode"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,76 @@
|
|||||||
|
{
|
||||||
|
"errors": [
|
||||||
|
{
|
||||||
|
"message": "发生未知错误,请联系管理员。",
|
||||||
|
"locations": [
|
||||||
|
{
|
||||||
|
"line": 46,
|
||||||
|
"column": 5
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"question",
|
||||||
|
"sampleTestCase"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"data": {
|
||||||
|
"question": {
|
||||||
|
"questionId": "2516",
|
||||||
|
"questionFrontendId": "2377",
|
||||||
|
"categoryTitle": "Database",
|
||||||
|
"boundTopicId": 1751271,
|
||||||
|
"title": "Sort the Olympic Table",
|
||||||
|
"titleSlug": "sort-the-olympic-table",
|
||||||
|
"content": null,
|
||||||
|
"translatedTitle": null,
|
||||||
|
"translatedContent": null,
|
||||||
|
"isPaidOnly": true,
|
||||||
|
"difficulty": "Easy",
|
||||||
|
"likes": 0,
|
||||||
|
"dislikes": 0,
|
||||||
|
"isLiked": null,
|
||||||
|
"similarQuestions": "[]",
|
||||||
|
"contributors": [],
|
||||||
|
"langToValidPlayground": null,
|
||||||
|
"topicTags": [
|
||||||
|
{
|
||||||
|
"name": "Database",
|
||||||
|
"slug": "database",
|
||||||
|
"translatedName": "数据库",
|
||||||
|
"__typename": "TopicTagNode"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"companyTagStats": null,
|
||||||
|
"codeSnippets": null,
|
||||||
|
"stats": "{\"totalAccepted\": \"14\", \"totalSubmission\": \"25\", \"totalAcceptedRaw\": 14, \"totalSubmissionRaw\": 25, \"acRate\": \"56.0%\"}",
|
||||||
|
"hints": [],
|
||||||
|
"solution": null,
|
||||||
|
"status": null,
|
||||||
|
"sampleTestCase": null,
|
||||||
|
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Olympic (country varchar(50), gold_medals int, silver_medals int, bronze_medals int)\"\n ],\n \"mssql\": [\n \"Create table Olympic (country varchar(50), gold_medals int, silver_medals int, bronze_medals int)\"\n ],\n \"oraclesql\": [\n \"Create table Olympic (country varchar(50), gold_medals int, silver_medals int, bronze_medals int)\"\n ],\n \"database\": true\n}",
|
||||||
|
"judgerAvailable": true,
|
||||||
|
"judgeType": "large",
|
||||||
|
"mysqlSchemas": [
|
||||||
|
"Create table If Not Exists Olympic (country varchar(50), gold_medals int, silver_medals int, bronze_medals int)",
|
||||||
|
"Truncate table Olympic",
|
||||||
|
"insert into Olympic (country, gold_medals, silver_medals, bronze_medals) values ('China', '10', '10', '20')",
|
||||||
|
"insert into Olympic (country, gold_medals, silver_medals, bronze_medals) values ('South Sudan', '0', '0', '1')",
|
||||||
|
"insert into Olympic (country, gold_medals, silver_medals, bronze_medals) values ('USA', '10', '10', '20')",
|
||||||
|
"insert into Olympic (country, gold_medals, silver_medals, bronze_medals) values ('Israel', '2', '2', '3')",
|
||||||
|
"insert into Olympic (country, gold_medals, silver_medals, bronze_medals) values ('Egypt', '2', '2', '2')"
|
||||||
|
],
|
||||||
|
"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": "",
|
||||||
|
"__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
178
leetcode-cn/originData/count-number-of-bad-pairs.json
Normal file
178
leetcode-cn/originData/count-number-of-bad-pairs.json
Normal file
File diff suppressed because one or more lines are too long
177
leetcode-cn/originData/count-special-integers.json
Normal file
177
leetcode-cn/originData/count-special-integers.json
Normal file
File diff suppressed because one or more lines are too long
177
leetcode-cn/originData/find-closest-node-to-given-two-nodes.json
Normal file
177
leetcode-cn/originData/find-closest-node-to-given-two-nodes.json
Normal file
File diff suppressed because one or more lines are too long
183
leetcode-cn/originData/find-the-k-sum-of-an-array.json
Normal file
183
leetcode-cn/originData/find-the-k-sum-of-an-array.json
Normal file
File diff suppressed because one or more lines are too long
177
leetcode-cn/originData/largest-local-values-in-a-matrix.json
Normal file
177
leetcode-cn/originData/largest-local-values-in-a-matrix.json
Normal file
File diff suppressed because one or more lines are too long
185
leetcode-cn/originData/largest-palindromic-number.json
Normal file
185
leetcode-cn/originData/largest-palindromic-number.json
Normal file
File diff suppressed because one or more lines are too long
183
leetcode-cn/originData/longest-cycle-in-a-graph.json
Normal file
183
leetcode-cn/originData/longest-cycle-in-a-graph.json
Normal file
File diff suppressed because one or more lines are too long
183
leetcode-cn/originData/longest-ideal-subsequence.json
Normal file
183
leetcode-cn/originData/longest-ideal-subsequence.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
190
leetcode-cn/originData/maximum-segment-sum-after-removals.json
Normal file
190
leetcode-cn/originData/maximum-segment-sum-after-removals.json
Normal file
File diff suppressed because one or more lines are too long
189
leetcode-cn/originData/merge-similar-items.json
Normal file
189
leetcode-cn/originData/merge-similar-items.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
178
leetcode-cn/originData/node-with-highest-edge-score.json
Normal file
178
leetcode-cn/originData/node-with-highest-edge-score.json
Normal file
File diff suppressed because one or more lines are too long
189
leetcode-cn/originData/number-of-arithmetic-triplets.json
Normal file
189
leetcode-cn/originData/number-of-arithmetic-triplets.json
Normal file
File diff suppressed because one or more lines are too long
202
leetcode-cn/originData/reachable-nodes-with-restrictions.json
Normal file
202
leetcode-cn/originData/reachable-nodes-with-restrictions.json
Normal file
File diff suppressed because one or more lines are too long
183
leetcode-cn/originData/shifting-letters-ii.json
Normal file
183
leetcode-cn/originData/shifting-letters-ii.json
Normal file
File diff suppressed because one or more lines are too long
183
leetcode-cn/originData/task-scheduler-ii.json
Normal file
183
leetcode-cn/originData/task-scheduler-ii.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,44 @@
|
|||||||
|
<p>给你一个二进制字符串 <code>s</code> 。在一秒之中,<strong>所有</strong> 子字符串 <code>"01"</code> <strong>同时</strong> 被替换成 <code>"10"</code> 。这个过程持续进行到没有 <code>"01"</code> 存在。</p>
|
||||||
|
|
||||||
|
<p>请你返回完成这个过程所需要的秒数。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<b>输入:</b>s = "0110101"
|
||||||
|
<b>输出:</b>4
|
||||||
|
<b>解释:</b>
|
||||||
|
一秒后,s 变成 "1011010" 。
|
||||||
|
再过 1 秒后,s 变成 "1101100" 。
|
||||||
|
第三秒过后,s 变成 "1110100" 。
|
||||||
|
第四秒后,s 变成 "1111000" 。
|
||||||
|
此时没有 "01" 存在,整个过程花费 4 秒。
|
||||||
|
所以我们返回 4 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<b>输入:</b>s = "11100"
|
||||||
|
<b>输出:</b>0
|
||||||
|
<strong>解释:</strong>
|
||||||
|
s 中没有 "01" 存在,整个过程花费 0 秒。
|
||||||
|
所以我们返回 0 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= s.length <= 1000</code></li>
|
||||||
|
<li><code>s[i]</code> 要么是 <code>'0'</code> ,要么是 <code>'1'</code> 。</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>进阶:</strong></p>
|
||||||
|
|
||||||
|
<p>你能以 O(n) 的时间复杂度解决这个问题吗?</p>
|
@ -0,0 +1,57 @@
|
|||||||
|
<p>给你一个下标从 <strong>0</strong> 开始的正整数数组 <code>tasks</code> ,表示需要 <strong>按顺序</strong> 完成的任务,其中 <code>tasks[i]</code> 表示第 <code>i</code> 件任务的 <strong>类型</strong> 。</p>
|
||||||
|
|
||||||
|
<p>同时给你一个正整数 <code>space</code> ,表示一个任务完成 <strong>后</strong> ,另一个 <strong>相同</strong> 类型任务完成前需要间隔的 <strong>最少</strong> 天数。</p>
|
||||||
|
|
||||||
|
<p>在所有任务完成前的每一天,你都必须进行以下两种操作中的一种:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>完成 <code>tasks</code> 中的下一个任务</li>
|
||||||
|
<li>休息一天</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>请你返回完成所有任务所需的 <strong>最少</strong> 天数。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre><b>输入:</b>tasks = [1,2,1,2,3,1], space = 3
|
||||||
|
<b>输出:</b>9
|
||||||
|
<strong>解释:</strong>
|
||||||
|
9 天完成所有任务的一种方法是:
|
||||||
|
第 1 天:完成任务 0 。
|
||||||
|
第 2 天:完成任务 1 。
|
||||||
|
第 3 天:休息。
|
||||||
|
第 4 天:休息。
|
||||||
|
第 5 天:完成任务 2 。
|
||||||
|
第 6 天:完成任务 3 。
|
||||||
|
第 7 天:休息。
|
||||||
|
第 8 天:完成任务 4 。
|
||||||
|
第 9 天:完成任务 5 。
|
||||||
|
可以证明无法少于 9 天完成所有任务。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre><b>输入:</b>tasks = [5,8,8,5], space = 2
|
||||||
|
<b>输出:</b>6
|
||||||
|
<strong>解释:</strong>
|
||||||
|
6 天完成所有任务的一种方法是:
|
||||||
|
第 1 天:完成任务 0 。
|
||||||
|
第 2 天:完成任务 1 。
|
||||||
|
第 3 天:休息。
|
||||||
|
第 4 天:休息。
|
||||||
|
第 5 天:完成任务 2 。
|
||||||
|
第 6 天:完成任务 3 。
|
||||||
|
可以证明无法少于 6 天完成所有任务。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= tasks.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>1 <= tasks[i] <= 10<sup>9</sup></code></li>
|
||||||
|
<li><code>1 <= space <= tasks.length</code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,37 @@
|
|||||||
|
<p>给你一个非负整数数组 <code>nums</code> 。在一步操作中,你必须:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>选出一个正整数 <code>x</code> ,<code>x</code> 需要小于或等于 <code>nums</code> 中 <strong>最小</strong> 的 <strong>非零</strong> 元素。</li>
|
||||||
|
<li><code>nums</code> 中的每个正整数都减去 <code>x</code>。</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>返回使 <code>nums</code> 中所有元素都等于<em> </em><code>0</code> 需要的 <strong>最少</strong> 操作数。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>输入:</strong>nums = [1,5,0,3,5]
|
||||||
|
<strong>输出:</strong>3
|
||||||
|
<strong>解释:</strong>
|
||||||
|
第一步操作:选出 x = 1 ,之后 nums = [0,4,0,2,4] 。
|
||||||
|
第二步操作:选出 x = 2 ,之后 nums = [0,2,0,0,2] 。
|
||||||
|
第三步操作:选出 x = 2 ,之后 nums = [0,0,0,0,0] 。</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>输入:</strong>nums = [0]
|
||||||
|
<strong>输出:</strong>0
|
||||||
|
<strong>解释:</strong>nums 中的每个元素都已经是 0 ,所以不需要执行任何操作。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= nums.length <= 100</code></li>
|
||||||
|
<li><code>0 <= nums[i] <= 100</code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,37 @@
|
|||||||
|
<p>给你一个正整数数组 <code>grades</code> ,表示大学中一些学生的成绩。你打算将 <strong>所有</strong> 学生分为一些 <strong>有序</strong> 的非空分组,其中分组间的顺序满足以下全部条件:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>第 <code>i</code> 个分组中的学生总成绩 <strong>小于</strong> 第 <code>(i + 1)</code> 个分组中的学生总成绩,对所有组均成立(除了最后一组)。</li>
|
||||||
|
<li>第 <code>i</code> 个分组中的学生总数 <strong>小于</strong> 第 <code>(i + 1)</code> 个分组中的学生总数,对所有组均成立(除了最后一组)。</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>返回可以形成的 <strong>最大</strong> 组数。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre><strong>输入:</strong>grades = [10,6,12,7,3,5]
|
||||||
|
<strong>输出:</strong>3
|
||||||
|
<strong>解释:</strong>下面是形成 3 个分组的一种可行方法:
|
||||||
|
- 第 1 个分组的学生成绩为 grades = [12] ,总成绩:12 ,学生数:1
|
||||||
|
- 第 2 个分组的学生成绩为 grades = [6,7] ,总成绩:6 + 7 = 13 ,学生数:2
|
||||||
|
- 第 3 个分组的学生成绩为 grades = [10,3,5] ,总成绩:10 + 3 + 5 = 18 ,学生数:3
|
||||||
|
可以证明无法形成超过 3 个分组。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre><strong>输入:</strong>grades = [8,8]
|
||||||
|
<strong>输出:</strong>1
|
||||||
|
<strong>解释:</strong>只能形成 1 个分组,因为如果要形成 2 个分组的话,会导致每个分组中的学生数目相等。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= grades.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>1 <= grades[i] <= 10<sup>5</sup></code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,45 @@
|
|||||||
|
<p>给你两个下标从 <strong>0</strong> 开始的整数数组 <code>nums</code> 和 <code>removeQueries</code> ,两者长度都为 <code>n</code> 。对于第 <code>i</code> 个查询,<code>nums</code> 中位于下标 <code>removeQueries[i]</code> 处的元素被删除,将 <code>nums</code> 分割成更小的子段。</p>
|
||||||
|
|
||||||
|
<p>一个 <strong>子段</strong> 是 <code>nums</code> 中连续 <strong>正</strong> 整数形成的序列。<strong>子段和</strong> 是子段中所有元素的和。</p>
|
||||||
|
|
||||||
|
<p>请你返回一个长度为 <code>n</code> 的整数数组<em> </em><code>answer</code> ,其中<em> </em><code>answer[i]</code>是第 <code>i</code> 次删除操作以后的 <strong>最大</strong> 子段和。</p>
|
||||||
|
|
||||||
|
<p><strong>注意:</strong>一个下标至多只会被删除一次。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre><b>输入:</b>nums = [1,2,5,6,1], removeQueries = [0,3,2,4,1]
|
||||||
|
<b>输出:</b>[14,7,2,2,0]
|
||||||
|
<b>解释:</b>用 0 表示被删除的元素,答案如下所示:
|
||||||
|
查询 1 :删除第 0 个元素,nums 变成 [0,2,5,6,1] ,最大子段和为子段 [2,5,6,1] 的和 14 。
|
||||||
|
查询 2 :删除第 3 个元素,nums 变成 [0,2,5,0,1] ,最大子段和为子段 [2,5] 的和 7 。
|
||||||
|
查询 3 :删除第 2 个元素,nums 变成 [0,2,0,0,1] ,最大子段和为子段 [2] 的和 2 。
|
||||||
|
查询 4 :删除第 4 个元素,nums 变成 [0,2,0,0,0] ,最大子段和为子段 [2] 的和 2 。
|
||||||
|
查询 5 :删除第 1 个元素,nums 变成 [0,0,0,0,0] ,最大子段和为 0 ,因为没有任何子段存在。
|
||||||
|
所以,我们返回 [14,7,2,2,0] 。</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre><b>输入:</b>nums = [3,2,11,1], removeQueries = [3,2,1,0]
|
||||||
|
<b>输出:</b>[16,5,3,0]
|
||||||
|
<b>解释:</b>用 0 表示被删除的元素,答案如下所示:
|
||||||
|
查询 1 :删除第 3 个元素,nums 变成 [3,2,11,0] ,最大子段和为子段 [3,2,11] 的和 16 。
|
||||||
|
查询 2 :删除第 2 个元素,nums 变成 [3,2,0,0] ,最大子段和为子段 [3,2] 的和 5 。
|
||||||
|
查询 3 :删除第 1 个元素,nums 变成 [3,0,0,0] ,最大子段和为子段 [3] 的和 3 。
|
||||||
|
查询 5 :删除第 0 个元素,nums 变成 [0,0,0,0] ,最大子段和为 0 ,因为没有任何子段存在。
|
||||||
|
所以,我们返回 [16,5,3,0] 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>n == nums.length == removeQueries.length</code></li>
|
||||||
|
<li><code>1 <= n <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>
|
||||||
|
<li><code>0 <= removeQueries[i] < n</code></li>
|
||||||
|
<li><code>removeQueries</code> 中所有数字 <strong>互不相同</strong> 。</li>
|
||||||
|
</ul>
|
@ -0,0 +1,40 @@
|
|||||||
|
<p>现有一棵由 <code>n</code> 个节点组成的无向树,节点编号从 <code>0</code> 到 <code>n - 1</code> ,共有 <code>n - 1</code> 条边。</p>
|
||||||
|
|
||||||
|
<p>给你一个二维整数数组 <code>edges</code> ,长度为 <code>n - 1</code> ,其中 <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> 表示树中节点 <code>a<sub>i</sub></code> 和 <code>b<sub>i</sub></code> 之间存在一条边。另给你一个整数数组 <code>restricted</code> 表示 <strong>受限</strong> 节点。</p>
|
||||||
|
|
||||||
|
<p>在不访问受限节点的前提下,返回你可以从节点<em> </em><code>0</code><em> </em>到达的 <strong>最多</strong> 节点数目<em>。</em></p>
|
||||||
|
|
||||||
|
<p>注意,节点 <code>0</code> <strong>不</strong> 会标记为受限节点。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
<img alt="" src="https://assets.leetcode.com/uploads/2022/06/15/ex1drawio.png" style="width: 402px; height: 322px;">
|
||||||
|
<pre><strong>输入:</strong>n = 7, edges = [[0,1],[1,2],[3,1],[4,0],[0,5],[5,6]], restricted = [4,5]
|
||||||
|
<strong>输出:</strong>4
|
||||||
|
<strong>解释:</strong>上图所示正是这棵树。
|
||||||
|
在不访问受限节点的前提下,只有节点 [0,1,2,3] 可以从节点 0 到达。</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
<img alt="" src="https://assets.leetcode.com/uploads/2022/06/15/ex2drawio.png" style="width: 412px; height: 312px;">
|
||||||
|
<pre><strong>输入:</strong>n = 7, edges = [[0,1],[0,2],[0,5],[0,4],[3,2],[6,5]], restricted = [4,2,1]
|
||||||
|
<strong>输出:</strong>3
|
||||||
|
<strong>解释:</strong>上图所示正是这棵树。
|
||||||
|
在不访问受限节点的前提下,只有节点 [0,5,6] 可以从节点 0 到达。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>2 <= n <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>edges.length == n - 1</code></li>
|
||||||
|
<li><code>edges[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>edges</code> 表示一棵有效的树</li>
|
||||||
|
<li><code>1 <= restricted.length < n</code></li>
|
||||||
|
<li><code>1 <= restricted[i] < n</code></li>
|
||||||
|
<li><code>restricted</code> 中的所有值 <strong>互不相同</strong></li>
|
||||||
|
</ul>
|
@ -0,0 +1,59 @@
|
|||||||
|
<p>给你两个二维整数数组 <code>items1</code> 和 <code>items2</code> ,表示两个物品集合。每个数组 <code>items</code> 有以下特质:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>items[i] = [value<sub>i</sub>, weight<sub>i</sub>]</code> 其中 <code>value<sub>i</sub></code> 表示第 <code>i</code> 件物品的 <strong>价值</strong> ,<code>weight<sub>i</sub></code> 表示第 <code>i</code> 件物品的 <strong>重量</strong> 。</li>
|
||||||
|
<li><code>items</code> 中每件物品的价值都是 <strong>唯一的</strong> 。</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>请你返回一个二维数组 <code>ret</code>,其中 <code>ret[i] = [value<sub>i</sub>, weight<sub>i</sub>]</code>, <code>weight<sub>i</sub></code> 是所有价值为 <code>value<sub>i</sub></code><sub> </sub>物品的 <strong>重量之和</strong> 。</p>
|
||||||
|
|
||||||
|
<p><strong>注意:</strong><code>ret</code> 应该按价值 <strong>升序</strong> 排序后返回。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<b>输入:</b>items1 = [[1,1],[4,5],[3,8]], items2 = [[3,1],[1,5]]
|
||||||
|
<b>输出:</b>[[1,6],[3,9],[4,5]]
|
||||||
|
<b>解释:</b>
|
||||||
|
value = 1 的物品在 items1 中 weight = 1 ,在 items2 中 weight = 5 ,总重量为 1 + 5 = 6 。
|
||||||
|
value = 3 的物品再 items1 中 weight = 8 ,在 items2 中 weight = 1 ,总重量为 8 + 1 = 9 。
|
||||||
|
value = 4 的物品在 items1 中 weight = 5 ,总重量为 5 。
|
||||||
|
所以,我们返回 [[1,6],[3,9],[4,5]] 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<b>输入:</b>items1 = [[1,1],[3,2],[2,3]], items2 = [[2,1],[3,2],[1,3]]
|
||||||
|
<b>输出:</b>[[1,4],[2,4],[3,4]]
|
||||||
|
<b>解释:</b>
|
||||||
|
value = 1 的物品在 items1 中 weight = 1 ,在 items2 中 weight = 3 ,总重量为 1 + 3 = 4 。
|
||||||
|
value = 2 的物品在 items1 中 weight = 3 ,在 items2 中 weight = 1 ,总重量为 3 + 1 = 4 。
|
||||||
|
value = 3 的物品在 items1 中 weight = 2 ,在 items2 中 weight = 2 ,总重量为 2 + 2 = 4 。
|
||||||
|
所以,我们返回 [[1,4],[2,4],[3,4]] 。</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 3:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<b>输入:</b>items1 = [[1,3],[2,2]], items2 = [[7,1],[2,2],[1,4]]
|
||||||
|
<b>输出:</b>[[1,7],[2,4],[7,1]]
|
||||||
|
<strong>解释:
|
||||||
|
</strong>value = 1 的物品在 items1 中 weight = 3 ,在 items2 中 weight = 4 ,总重量为 3 + 4 = 7 。
|
||||||
|
value = 2 的物品在 items1 中 weight = 2 ,在 items2 中 weight = 2 ,总重量为 2 + 2 = 4 。
|
||||||
|
value = 7 的物品在 items2 中 weight = 1 ,总重量为 1 。
|
||||||
|
所以,我们返回 [[1,7],[2,4],[7,1]] 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= items1.length, items2.length <= 1000</code></li>
|
||||||
|
<li><code>items1[i].length == items2[i].length == 2</code></li>
|
||||||
|
<li><code>1 <= value<sub>i</sub>, weight<sub>i</sub> <= 1000</code></li>
|
||||||
|
<li><code>items1</code> 中每个 <code>value<sub>i</sub></code> 都是 <b>唯一的</b> 。</li>
|
||||||
|
<li><code>items2</code> 中每个 <code>value<sub>i</sub></code> 都是 <b>唯一的</b> 。</li>
|
||||||
|
</ul>
|
@ -0,0 +1,41 @@
|
|||||||
|
<p>给你一个 <code>n</code> 个节点的 <b>有向图</b> ,节点编号为 <code>0</code> 到 <code>n - 1</code> ,其中每个节点 <strong>至多</strong> 有一条出边。</p>
|
||||||
|
|
||||||
|
<p>图用一个大小为 <code>n</code> 下标从<strong> 0</strong> 开始的数组 <code>edges</code> 表示,节点 <code>i</code> 到节点 <code>edges[i]</code> 之间有一条有向边。如果节点 <code>i</code> 没有出边,那么 <code>edges[i] == -1</code> 。</p>
|
||||||
|
|
||||||
|
<p>请你返回图中的 <strong>最长</strong> 环,如果没有任何环,请返回 <code>-1</code> 。</p>
|
||||||
|
|
||||||
|
<p>一个环指的是起点和终点是 <strong>同一个</strong> 节点的路径。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/06/08/graph4drawio-5.png" style="width: 335px; height: 191px;" /></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<b>输入:</b>edges = [3,3,4,2,3]
|
||||||
|
<b>输出去:</b>3
|
||||||
|
<b>解释:</b>图中的最长环是:2 -> 4 -> 3 -> 2 。
|
||||||
|
这个环的长度为 3 ,所以返回 3 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/06/07/graph4drawio-1.png" style="width: 171px; height: 161px;" /></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<b>输入:</b>edges = [2,-1,3,1]
|
||||||
|
<b>输出:</b>-1
|
||||||
|
<b>解释:</b>图中没有任何环。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>n == edges.length</code></li>
|
||||||
|
<li><code>2 <= n <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>-1 <= edges[i] < n</code></li>
|
||||||
|
<li><code>edges[i] != i</code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,35 @@
|
|||||||
|
<p>给你一个小写英文字母组成的字符串 <code>s</code> 和一个二维整数数组 <code>shifts</code> ,其中 <code>shifts[i] = [start<sub>i</sub>, end<sub>i</sub>, direction<sub>i</sub>]</code> 。对于每个 <code>i</code> ,将 <code>s</code> 中从下标 <code>start<sub>i</sub></code> 到下标 <code>end<sub>i</sub></code> (两者都包含)所有字符都进行移位运算,如果 <code>direction<sub>i</sub> = 1</code> 将字符向后移位,如果 <code>direction<sub>i</sub> = 0</code> 将字符向前移位。</p>
|
||||||
|
|
||||||
|
<p>将一个字符 <strong>向后</strong> 移位的意思是将这个字符用字母表中 <strong>下一个</strong> 字母替换(字母表视为环绕的,所以 <code>'z'</code> 变成 <code>'a'</code>)。类似的,将一个字符 <strong>向前</strong> 移位的意思是将这个字符用字母表中 <strong>前一个</strong> 字母替换(字母表是环绕的,所以 <code>'a'</code> 变成 <code>'z'</code> )。</p>
|
||||||
|
|
||||||
|
<p>请你返回对 <code>s</code> 进行所有移位操作以后得到的最终字符串。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre><b>输入:</b>s = "abc", shifts = [[0,1,0],[1,2,1],[0,2,1]]
|
||||||
|
<b>输出:</b>"ace"
|
||||||
|
<b>解释:</b>首先,将下标从 0 到 1 的字母向前移位,得到 s = "zac" 。
|
||||||
|
然后,将下标从 1 到 2 的字母向后移位,得到 s = "zbd" 。
|
||||||
|
最后,将下标从 0 到 2 的字符向后移位,得到 s = "ace" 。</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre><b>输入:</b>s = "dztz", shifts = [[0,0,0],[1,1,1]]
|
||||||
|
<b>输出:</b>"catz"
|
||||||
|
<b>解释:</b>首先,将下标从 0 到 0 的字母向前移位,得到 s = "cztz" 。
|
||||||
|
最后,将下标从 1 到 1 的字符向后移位,得到 s = "catz" 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= s.length, shifts.length <= 5 * 10<sup>4</sup></code></li>
|
||||||
|
<li><code>shifts[i].length == 3</code></li>
|
||||||
|
<li><code>0 <= start<sub>i</sub> <= end<sub>i</sub> < s.length</code></li>
|
||||||
|
<li><code>0 <= direction<sub>i</sub> <= 1</code></li>
|
||||||
|
<li><code>s</code> 只包含小写英文字母。</li>
|
||||||
|
</ul>
|
@ -0,0 +1,37 @@
|
|||||||
|
<p>给你一个下表从 <strong>0</strong> 开始的整数数组 <code>nums</code> 。每次操作中,你可以将数组中任何一个元素替换为 <strong>任意两个</strong> 和为该元素的数字。</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>比方说,<code>nums = [5,6,7]</code> 。一次操作中,我们可以将 <code>nums[1]</code> 替换成 <code>2</code> 和 <code>4</code> ,将 <code>nums</code> 转变成 <code>[5,2,4,7]</code> 。</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>请你执行上述操作,将数组变成元素按 <strong>非递减</strong> 顺序排列的数组,并返回所需的最少操作次数。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<b>输入:</b>nums = [3,9,3]
|
||||||
|
<b>输出:</b>2
|
||||||
|
<b>解释:</b>以下是将数组变成非递减顺序的步骤:
|
||||||
|
- [3,9,3] ,将9 变成 3 和 6 ,得到数组 [3,3,6,3]
|
||||||
|
- [3,3,6,3] ,将 6 变成 3 和 3 ,得到数组 [3,3,3,3,3]
|
||||||
|
总共需要 2 步将数组变成非递减有序,所以我们返回 2 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<b>输入:</b>nums = [1,2,3,4,5]
|
||||||
|
<b>输出:</b>0
|
||||||
|
<b>解释:</b>数组已经是非递减顺序,所以我们返回 0 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,42 @@
|
|||||||
|
<p>给你一个长度为 <code>n</code> 下标从 <strong>0</strong> 开始的字符串 <code>blocks</code> ,<code>blocks[i]</code> 要么是 <code>'W'</code> 要么是 <code>'B'</code> ,表示第 <code>i</code> 块的颜色。字符 <code>'W'</code> 和 <code>'B'</code> 分别表示白色和黑色。</p>
|
||||||
|
|
||||||
|
<p>给你一个整数 <code>k</code> ,表示想要 <strong>连续</strong> 黑色块的数目。</p>
|
||||||
|
|
||||||
|
<p>每一次操作中,你可以选择一个白色块将它 <strong>涂成</strong> 黑色块。</p>
|
||||||
|
|
||||||
|
<p>请你返回至少出现 <strong>一次</strong> 连续 <code>k</code> 个黑色块的 <strong>最少</strong> 操作次数。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<b>输入:</b>blocks = "WBBWWBBWBW", k = 7
|
||||||
|
<b>输出:</b>3
|
||||||
|
<strong>解释:</strong>
|
||||||
|
一种得到 7 个连续黑色块的方法是把第 0 ,3 和 4 个块涂成黑色。
|
||||||
|
得到 blocks = "BBBBBBBWBW" 。
|
||||||
|
可以证明无法用少于 3 次操作得到 7 个连续的黑块。
|
||||||
|
所以我们返回 3 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<b>输入:</b>blocks = "WBWBBBW", k = 2
|
||||||
|
<b>输出:</b>0
|
||||||
|
<strong>解释:</strong>
|
||||||
|
不需要任何操作,因为已经有 2 个连续的黑块。
|
||||||
|
所以我们返回 0 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><b>提示:</b></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>n == blocks.length</code></li>
|
||||||
|
<li><code>1 <= n <= 100</code></li>
|
||||||
|
<li><code>blocks[i]</code> 要么是 <code>'W'</code> ,要么是 <code>'B'</code> 。</li>
|
||||||
|
<li><code>1 <= k <= n</code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,43 @@
|
|||||||
|
<p>给你一棵二叉树的根节点 <code>root</code> ,二叉树中节点的值 <strong>互不相同</strong> 。另给你一个整数 <code>start</code> 。在第 <code>0</code> 分钟,<strong>感染</strong> 将会从值为 <code>start</code> 的节点开始爆发。</p>
|
||||||
|
|
||||||
|
<p>每分钟,如果节点满足以下全部条件,就会被感染:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>节点此前还没有感染。</li>
|
||||||
|
<li>节点与一个已感染节点相邻。</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>返回感染整棵树需要的分钟数<em>。</em></p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
<img alt="" src="https://assets.leetcode.com/uploads/2022/06/25/image-20220625231744-1.png" style="width: 400px; height: 306px;">
|
||||||
|
<pre><strong>输入:</strong>root = [1,5,3,null,4,10,6,9,2], start = 3
|
||||||
|
<strong>输出:</strong>4
|
||||||
|
<strong>解释:</strong>节点按以下过程被感染:
|
||||||
|
- 第 0 分钟:节点 3
|
||||||
|
- 第 1 分钟:节点 1、10、6
|
||||||
|
- 第 2 分钟:节点5
|
||||||
|
- 第 3 分钟:节点 4
|
||||||
|
- 第 4 分钟:节点 9 和 2
|
||||||
|
感染整棵树需要 4 分钟,所以返回 4 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
<img alt="" src="https://assets.leetcode.com/uploads/2022/06/25/image-20220625231812-2.png" style="width: 75px; height: 66px;">
|
||||||
|
<pre><strong>输入:</strong>root = [1], start = 1
|
||||||
|
<strong>输出:</strong>0
|
||||||
|
<strong>解释:</strong>第 0 分钟,树中唯一一个节点处于感染状态,返回 0 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>树中节点的数目在范围 <code>[1, 10<sup>5</sup>]</code> 内</li>
|
||||||
|
<li><code>1 <= Node.val <= 10<sup>5</sup></code></li>
|
||||||
|
<li>每个节点的值 <strong>互不相同</strong></li>
|
||||||
|
<li>树中必定存在值为 <code>start</code> 的节点</li>
|
||||||
|
</ul>
|
@ -0,0 +1,38 @@
|
|||||||
|
<p>给你一个整数数组 <code>nums</code> 和一个 <strong>正</strong> 整数 <code>k</code> 。你可以选择数组的任一 <strong>子序列</strong> 并且对其全部元素求和。</p>
|
||||||
|
|
||||||
|
<p>数组的 <strong>第 k 大和</strong> 定义为:可以获得的第 <code>k</code> 个 <strong>最大</strong> 子序列和(子序列和允许出现重复)</p>
|
||||||
|
|
||||||
|
<p>返回数组的 <strong>第 k 大和</strong> 。</p>
|
||||||
|
|
||||||
|
<p>子序列是一个可以由其他数组删除某些或不删除元素排生而来的数组,且派生过程不改变剩余元素的顺序。</p>
|
||||||
|
|
||||||
|
<p><strong>注意:</strong>空子序列的和视作 <code>0</code> 。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre><strong>输入:</strong>nums = [2,4,-2], k = 5
|
||||||
|
<strong>输出:</strong>2
|
||||||
|
<strong>解释:</strong>所有可能获得的子序列和列出如下,按递减顺序排列:
|
||||||
|
- 6、4、4、2、<strong><em>2</em></strong>、0、0、-2
|
||||||
|
数组的第 5 大和是 2 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre><strong>输入:</strong>nums = [1,-2,3,4,-10,12], k = 16
|
||||||
|
<strong>输出:</strong>10
|
||||||
|
<strong>解释:</strong>数组的第 16 大和是 10 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>n == nums.length</code></li>
|
||||||
|
<li><code>1 <= n <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li>
|
||||||
|
<li><code>1 <= k <= min(2000, 2<sup>n</sup>)</code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,43 @@
|
|||||||
|
<p>给你一个 <code>n</code> 个节点的 <strong>有向图</strong> ,节点编号为 <code>0</code> 到 <code>n - 1</code> ,每个节点 <strong>至多</strong> 有一条出边。</p>
|
||||||
|
|
||||||
|
<p>有向图用大小为 <code>n</code> 下标从 <strong>0</strong> 开始的数组 <code>edges</code> 表示,表示节点 <code>i</code> 有一条有向边指向 <code>edges[i]</code> 。如果节点 <code>i</code> 没有出边,那么 <code>edges[i] == -1</code> 。</p>
|
||||||
|
|
||||||
|
<p>同时给你两个节点 <code>node1</code> 和 <code>node2</code> 。</p>
|
||||||
|
|
||||||
|
<p>请你返回一个从 <code>node1</code> 和 <code>node2</code> 都能到达节点的编号,使节点 <code>node1</code> 和节点 <code>node2</code> 到这个节点的距离 <b>较大值最小化</b>。如果有多个答案,请返回 <strong>最小</strong> 的节点编号。如果答案不存在,返回 <code>-1</code> 。</p>
|
||||||
|
|
||||||
|
<p>注意 <code>edges</code> 可能包含环。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/06/07/graph4drawio-2.png" style="width: 321px; height: 161px;"></p>
|
||||||
|
|
||||||
|
<pre><b>输入:</b>edges = [2,2,3,-1], node1 = 0, node2 = 1
|
||||||
|
<b>输出:</b>2
|
||||||
|
<b>解释:</b>从节点 0 到节点 2 的距离为 1 ,从节点 1 到节点 2 的距离为 1 。
|
||||||
|
两个距离的较大值为 1 。我们无法得到一个比 1 更小的较大值,所以我们返回节点 2 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/06/07/graph4drawio-4.png" style="width: 195px; height: 161px;"></p>
|
||||||
|
|
||||||
|
<pre><b>输入:</b>edges = [1,2,-1], node1 = 0, node2 = 2
|
||||||
|
<b>输出:</b>2
|
||||||
|
<b>解释:</b>节点 0 到节点 2 的距离为 2 ,节点 2 到它自己的距离为 0 。
|
||||||
|
两个距离的较大值为 2 。我们无法得到一个比 2 更小的较大值,所以我们返回节点 2 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>n == edges.length</code></li>
|
||||||
|
<li><code>2 <= n <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>-1 <= edges[i] < n</code></li>
|
||||||
|
<li><code>edges[i] != i</code></li>
|
||||||
|
<li><code>0 <= node1, node2 < n</code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,41 @@
|
|||||||
|
<p>给你一个仅由数字(<code>0 - 9</code>)组成的字符串 <code>num</code> 。</p>
|
||||||
|
|
||||||
|
<p>请你找出能够使用 <code>num</code> 中数字形成的 <strong>最大回文</strong> 整数,并以字符串形式返回。该整数不含 <strong>前导零</strong> 。</p>
|
||||||
|
|
||||||
|
<p><strong>注意:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>你 <strong>无需</strong> 使用 <code>num</code> 中的所有数字,但你必须使用 <strong>至少</strong> 一个数字。</li>
|
||||||
|
<li>数字可以重新排序。</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>输入:</strong>num = "444947137"
|
||||||
|
<strong>输出:</strong>"7449447"
|
||||||
|
<strong>解释:</strong>
|
||||||
|
从 "<em><strong>44494</strong></em><em><strong>7</strong></em>13<em><strong>7</strong></em>" 中选用数字 "4449477",可以形成回文整数 "7449447" 。
|
||||||
|
可以证明 "7449447" 是能够形成的最大回文整数。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>输入:</strong>num = "00009"
|
||||||
|
<strong>输出:</strong>"9"
|
||||||
|
<strong>解释:</strong>
|
||||||
|
可以证明 "9" 能够形成的最大回文整数。
|
||||||
|
注意返回的整数不应含前导零。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= num.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>num</code> 由数字(<code>0 - 9</code>)组成</li>
|
||||||
|
</ul>
|
@ -0,0 +1,40 @@
|
|||||||
|
<p>给你一个由小写字母组成的字符串 <code>s</code> ,和一个整数 <code>k</code> 。如果满足下述条件,则可以将字符串 <code>t</code> 视作是 <strong>理想字符串</strong> :</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>t</code> 是字符串 <code>s</code> 的一个子序列。</li>
|
||||||
|
<li><code>t</code> 中每两个 <strong>相邻</strong> 字母在字母表中位次的绝对差值小于或等于 <code>k</code> 。</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>返回 <strong>最长</strong> 理想字符串的长度。</p>
|
||||||
|
|
||||||
|
<p>字符串的子序列同样是一个字符串,并且子序列还满足:可以经由其他字符串删除某些字符(也可以不删除)但不改变剩余字符的顺序得到。</p>
|
||||||
|
|
||||||
|
<p><strong>注意:</strong>字母表顺序不会循环。例如,<code>'a'</code> 和 <code>'z'</code> 在字母表中位次的绝对差值是 <code>25</code> ,而不是 <code>1</code> 。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>输入:</strong>s = "acfgbd", k = 2
|
||||||
|
<strong>输出:</strong>4
|
||||||
|
<strong>解释:</strong>最长理想字符串是 "acbd" 。该字符串长度为 4 ,所以返回 4 。
|
||||||
|
注意 "acfgbd" 不是理想字符串,因为 'c' 和 'f' 的字母表位次差值为 3 。</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>输入:</strong>s = "abcd", k = 3
|
||||||
|
<strong>输出:</strong>4
|
||||||
|
<strong>解释:</strong>最长理想字符串是 "abcd" ,该字符串长度为 4 ,所以返回 4 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= s.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>0 <= k <= 25</code></li>
|
||||||
|
<li><code>s</code> 由小写英文字母组成</li>
|
||||||
|
</ul>
|
@ -0,0 +1,44 @@
|
|||||||
|
<p>给你下标从 <strong>0</strong> 开始、长度为 <code>n</code> 的字符串 <code>pattern</code> ,它包含两种字符,<code>'I'</code> 表示 <strong>上升</strong> ,<code>'D'</code> 表示 <strong>下降</strong> 。</p>
|
||||||
|
|
||||||
|
<p>你需要构造一个下标从 <strong>0</strong> 开始长度为 <code>n + 1</code> 的字符串,且它要满足以下条件:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>num</code> 包含数字 <code>'1'</code> 到 <code>'9'</code> ,其中每个数字 <strong>至多</strong> 使用一次。</li>
|
||||||
|
<li>如果 <code>pattern[i] == 'I'</code> ,那么 <code>num[i] < num[i + 1]</code> 。</li>
|
||||||
|
<li>如果 <code>pattern[i] == 'D'</code> ,那么 <code>num[i] > num[i + 1]</code> 。</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>请你返回满足上述条件字典序 <strong>最小</strong> 的字符串<em> </em><code>num</code>。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<b>输入:</b>pattern = "IIIDIDDD"
|
||||||
|
<b>输出:</b>"123549876"
|
||||||
|
<strong>解释:
|
||||||
|
</strong>下标 0 ,1 ,2 和 4 处,我们需要使 num[i] < num[i+1] 。
|
||||||
|
下标 3 ,5 ,6 和 7 处,我们需要使 num[i] > num[i+1] 。
|
||||||
|
一些可能的 num 的值为 "245639871" ,"135749862" 和 "123849765" 。
|
||||||
|
"123549876" 是满足条件最小的数字。
|
||||||
|
注意,"123414321" 不是可行解因为数字 '1' 使用次数超过 1 次。</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<b>输入:</b>pattern = "DDD"
|
||||||
|
<b>输出:</b>"4321"
|
||||||
|
<strong>解释:</strong>
|
||||||
|
一些可能的 num 的值为 "9876" ,"7321" 和 "8742" 。
|
||||||
|
"4321" 是满足条件最小的数字。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= pattern.length <= 8</code></li>
|
||||||
|
<li><code>pattern</code> 只包含字符 <code>'I'</code> 和 <code>'D'</code> 。</li>
|
||||||
|
</ul>
|
@ -0,0 +1,39 @@
|
|||||||
|
<p>给你一个下标从 <strong>0</strong> 开始的整数数组 <code>nums</code> ,你必须将数组划分为一个或多个 <strong>连续</strong> 子数组。</p>
|
||||||
|
|
||||||
|
<p>如果获得的这些子数组中每个都能满足下述条件<strong> 之一</strong> ,则可以称其为数组的一种 <strong>有效</strong> 划分:</p>
|
||||||
|
|
||||||
|
<ol>
|
||||||
|
<li>子数组 <strong>恰</strong> 由 <code>2</code> 个相等元素组成,例如,子数组 <code>[2,2]</code> 。</li>
|
||||||
|
<li>子数组 <strong>恰</strong> 由 <code>3</code> 个相等元素组成,例如,子数组 <code>[4,4,4]</code> 。</li>
|
||||||
|
<li>子数组 <strong>恰</strong> 由 <code>3</code> 个连续递增元素组成,并且相邻元素之间的差值为 <code>1</code> 。例如,子数组 <code>[3,4,5]</code> ,但是子数组 <code>[1,3,5]</code> 不符合要求。</li>
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
<p>如果数组 <strong>至少</strong> 存在一种有效划分,返回 <code>true</code><em> </em>,否则,返回 <code>false</code> 。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>输入:</strong>nums = [4,4,4,5,6]
|
||||||
|
<strong>输出:</strong>true
|
||||||
|
<strong>解释:</strong>数组可以划分成子数组 [4,4] 和 [4,5,6] 。
|
||||||
|
这是一种有效划分,所以返回 true 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>输入:</strong>nums = [1,1,1,2]
|
||||||
|
<strong>输出:</strong>false
|
||||||
|
<strong>解释:</strong>该数组不存在有效划分。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>2 <= nums.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>1 <= nums[i] <= 10<sup>6</sup></code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,43 @@
|
|||||||
|
<p>给你一个大小为 <code>n x n</code> 的整数矩阵 <code>grid</code> 。</p>
|
||||||
|
|
||||||
|
<p>生成一个大小为 <code>(n - 2) x (n - 2)</code> 的整数矩阵 <code>maxLocal</code> ,并满足:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>maxLocal[i][j]</code> 等于 <code>grid</code> 中以 <code>i + 1</code> 行和 <code>j + 1</code> 列为中心的 <code>3 x 3</code> 矩阵中的 <strong>最大值</strong> 。</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>换句话说,我们希望找出 <code>grid</code> 中每个 <code>3 x 3</code> 矩阵中的最大值。</p>
|
||||||
|
|
||||||
|
<p>返回生成的矩阵。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/06/21/ex1.png" style="width: 371px; height: 210px;" /></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>输入:</strong>grid = [[9,9,8,1],[5,6,2,6],[8,2,6,4],[6,2,2,2]]
|
||||||
|
<strong>输出:</strong>[[9,9],[8,6]]
|
||||||
|
<strong>解释:</strong>原矩阵和生成的矩阵如上图所示。
|
||||||
|
注意,生成的矩阵中,每个值都对应 grid 中一个相接的 3 x 3 矩阵的最大值。</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/07/02/ex2new2.png" style="width: 436px; height: 240px;" /></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>输入:</strong>grid = [[1,1,1,1,1],[1,1,1,1,1],[1,1,2,1,1],[1,1,1,1,1],[1,1,1,1,1]]
|
||||||
|
<strong>输出:</strong>[[2,2,2],[2,2,2],[2,2,2]]
|
||||||
|
<strong>解释:</strong>注意,2 包含在 grid 中每个 3 x 3 的矩阵中。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>n == grid.length == grid[i].length</code></li>
|
||||||
|
<li><code>3 <= n <= 100</code></li>
|
||||||
|
<li><code>1 <= grid[i][j] <= 100</code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,40 @@
|
|||||||
|
<p>给你一个下标从 <strong>0</strong> 开始、<strong>严格递增</strong> 的整数数组 <code>nums</code> 和一个正整数 <code>diff</code> 。如果满足下述全部条件,则三元组 <code>(i, j, k)</code> 就是一个 <strong>算术三元组</strong> :</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>i < j < k</code> ,</li>
|
||||||
|
<li><code>nums[j] - nums[i] == diff</code> 且</li>
|
||||||
|
<li><code>nums[k] - nums[j] == diff</code></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>返回不同 <strong>算术三元组</strong> 的数目<em>。</em></p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre><strong>输入:</strong>nums = [0,1,4,6,7,10], diff = 3
|
||||||
|
<strong>输出:</strong>2
|
||||||
|
<strong>解释:</strong>
|
||||||
|
(1, 2, 4) 是算术三元组:7 - 4 == 3 且 4 - 1 == 3 。
|
||||||
|
(2, 4, 5) 是算术三元组:10 - 7 == 3 且 7 - 4 == 3 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre><strong>输入:</strong>nums = [4,5,6,7,8,9], diff = 2
|
||||||
|
<strong>输出:</strong>2
|
||||||
|
<strong>解释:</strong>
|
||||||
|
(0, 2, 4) 是算术三元组:8 - 6 == 2 且 6 - 4 == 2 。
|
||||||
|
(1, 3, 5) 是算术三元组:9 - 7 == 2 且 7 - 5 == 2 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>3 <= nums.length <= 200</code></li>
|
||||||
|
<li><code>0 <= nums[i] <= 200</code></li>
|
||||||
|
<li><code>1 <= diff <= 50</code></li>
|
||||||
|
<li><code>nums</code> <strong>严格</strong> 递增</li>
|
||||||
|
</ul>
|
@ -0,0 +1,33 @@
|
|||||||
|
<p>给你一个下标从<strong> 0</strong> 开始的整数数组 <code>nums</code> 。如果 <code>i < j</code> 且 <code>j - i != nums[j] - nums[i]</code> ,那么我们称 <code>(i, j)</code> 是一个 <strong>坏</strong><strong>数对</strong> 。</p>
|
||||||
|
|
||||||
|
<p>请你返回 <code>nums</code> 中 <strong>坏数对</strong> 的总数目。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre><b>输入:</b>nums = [4,1,3,3]
|
||||||
|
<b>输出:</b>5
|
||||||
|
<b>解释:</b>数对 (0, 1) 是坏数对,因为 1 - 0 != 1 - 4 。
|
||||||
|
数对 (0, 2) 是坏数对,因为 2 - 0 != 3 - 4, 2 != -1 。
|
||||||
|
数对 (0, 3) 是坏数对,因为 3 - 0 != 3 - 4, 3 != -1 。
|
||||||
|
数对 (1, 2) 是坏数对,因为 2 - 1 != 3 - 1, 1 != 2 。
|
||||||
|
数对 (2, 3) 是坏数对,因为 3 - 2 != 3 - 3, 1 != 0 。
|
||||||
|
总共有 5 个坏数对,所以我们返回 5 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre><b>输入:</b>nums = [1,2,3,4,5]
|
||||||
|
<b>输出:</b>0
|
||||||
|
<strong>解释:</strong>没有坏数对。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,37 @@
|
|||||||
|
<p>如果一个正整数每一个数位都是 <strong>互不相同</strong> 的,我们称它是 <strong>特殊整数</strong> 。</p>
|
||||||
|
|
||||||
|
<p>给你一个 <strong>正</strong> 整数 <code>n</code> ,请你返回区间<em> </em><code>[1, n]</code> 之间特殊整数的数目。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<b>输入:</b>n = 20
|
||||||
|
<b>输出:</b>19
|
||||||
|
<b>解释:</b>1 到 20 之间所有整数除了 11 以外都是特殊整数。所以总共有 19 个特殊整数。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<b>输入:</b>n = 5
|
||||||
|
<b>输出:</b>5
|
||||||
|
<b>解释:</b>1 到 5 所有整数都是特殊整数。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 3:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<b>输入:</b>n = 135
|
||||||
|
<b>输出:</b>110
|
||||||
|
<b>解释:</b>从 1 到 135 总共有 110 个整数是特殊整数。
|
||||||
|
不特殊的部分数字为:22 ,114 和 131 。</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= n <= 2 * 10<sup>9</sup></code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,48 @@
|
|||||||
|
<p>你正在参加一场比赛,给你两个 <strong>正</strong> 整数 <code>initialEnergy</code> 和 <code>initialExperience</code> 分别表示你的初始精力和初始经验。</p>
|
||||||
|
|
||||||
|
<p>另给你两个下标从 <strong>0</strong> 开始的整数数组 <code>energy</code> 和 <code>experience</code>,长度均为 <code>n</code> 。</p>
|
||||||
|
|
||||||
|
<p>你将会 <strong>依次</strong> 对上 <code>n</code> 个对手。第 <code>i</code> 个对手的精力和经验分别用 <code>energy[i]</code> 和 <code>experience[i]</code> 表示。当你对上对手时,需要在经验和精力上都 <strong>严格</strong> 超过对手才能击败他们,然后在可能的情况下继续对上下一个对手。</p>
|
||||||
|
|
||||||
|
<p>击败第 <code>i</code> 个对手会使你的经验 <strong>增加</strong> <code>experience[i]</code>,但会将你的精力 <strong>减少</strong> <code>energy[i]</code> 。</p>
|
||||||
|
|
||||||
|
<p>在开始比赛前,你可以训练几个小时。每训练一个小时,你可以选择将增加经验增加 1 <strong>或者</strong> 将精力增加 1 。</p>
|
||||||
|
|
||||||
|
<p>返回击败全部 <code>n</code> 个对手需要训练的 <strong>最少</strong> 小时数目。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
|
||||||
|
<pre><strong>输入:</strong>initialEnergy = 5, initialExperience = 3, energy = [1,4,3,2], experience = [2,6,3,1]
|
||||||
|
<strong>输出:</strong>8
|
||||||
|
<strong>解释:</strong>在 6 小时训练后,你可以将精力提高到 11 ,并且再训练 2 个小时将经验提高到 5 。
|
||||||
|
按以下顺序与对手比赛:
|
||||||
|
- 你的精力与经验都超过第 0 个对手,所以获胜。
|
||||||
|
精力变为:11 - 1 = 10 ,经验变为:5 + 2 = 7 。
|
||||||
|
- 你的精力与经验都超过第 1 个对手,所以获胜。
|
||||||
|
精力变为:10 - 4 = 6 ,经验变为:7 + 6 = 13 。
|
||||||
|
- 你的精力与经验都超过第 2 个对手,所以获胜。
|
||||||
|
精力变为:6 - 3 = 3 ,经验变为:13 + 3 = 16 。
|
||||||
|
- 你的精力与经验都超过第 3 个对手,所以获胜。
|
||||||
|
精力变为:3 - 2 = 1 ,经验变为:16 + 1 = 17 。
|
||||||
|
在比赛前进行了 8 小时训练,所以返回 8 。
|
||||||
|
可以证明不存在更小的答案。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
|
||||||
|
<pre><strong>输入:</strong>initialEnergy = 2, initialExperience = 4, energy = [1], experience = [3]
|
||||||
|
<strong>输出:</strong>0
|
||||||
|
<strong>解释:</strong>你不需要额外的精力和经验就可以赢得比赛,所以返回 0 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>n == energy.length == experience.length</code></li>
|
||||||
|
<li><code>1 <= n <= 100</code></li>
|
||||||
|
<li><code>1 <= initialEnergy, initialExperience, energy[i], experience[i] <= 100</code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,42 @@
|
|||||||
|
<p>给你一个有向图,图中有 <code>n</code> 个节点,节点编号从 <code>0</code> 到 <code>n - 1</code> ,其中每个节点都 <strong>恰有一条</strong> 出边。</p>
|
||||||
|
|
||||||
|
<p>图由一个下标从 <strong>0</strong> 开始、长度为 <code>n</code> 的整数数组 <code>edges</code> 表示,其中 <code>edges[i]</code> 表示存在一条从节点 <code>i</code> 到节点 <code>edges[i]</code> 的 <strong>有向</strong> 边。</p>
|
||||||
|
|
||||||
|
<p>节点 <code>i</code> 的 <strong>边积分</strong> 定义为:所有存在一条指向节点 <code>i</code> 的边的节点的 <strong>编号</strong> 总和。</p>
|
||||||
|
|
||||||
|
<p>返回 <strong>边积分</strong> 最高的节点。如果多个节点的 <strong>边积分</strong> 相同,返回编号 <strong>最小</strong> 的那个。</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>示例 1:</strong></p>
|
||||||
|
<img src="https://assets.leetcode.com/uploads/2022/06/20/image-20220620195403-1.png" style="width: 450px; height: 260px;">
|
||||||
|
<pre><strong>输入:</strong>edges = [1,0,0,0,0,7,7,5]
|
||||||
|
<strong>输出:</strong>7
|
||||||
|
<strong>解释:</strong>
|
||||||
|
- 节点 1、2、3 和 4 都有指向节点 0 的边,节点 0 的边积分等于 1 + 2 + 3 + 4 = 10 。
|
||||||
|
- 节点 0 有一条指向节点 1 的边,节点 1 的边积分等于 0 。
|
||||||
|
- 节点 7 有一条指向节点 5 的边,节点 5 的边积分等于 7 。
|
||||||
|
- 节点 5 和 6 都有指向节点 7 的边,节点 7 的边积分等于 5 + 6 = 11 。
|
||||||
|
节点 7 的边积分最高,所以返回 7 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>示例 2:</strong></p>
|
||||||
|
<img src="https://assets.leetcode.com/uploads/2022/06/20/image-20220620200212-3.png" style="width: 150px; height: 155px;">
|
||||||
|
<pre><strong>输入:</strong>edges = [2,0,0,2]
|
||||||
|
<strong>输出:</strong>0
|
||||||
|
<strong>解释:
|
||||||
|
</strong>- 节点 1 和 2 都有指向节点 0 的边,节点 0 的边积分等于 1 + 2 = 3 。
|
||||||
|
- 节点 0 和 3 都有指向节点 2 的边,节点 2 的边积分等于 0 + 3 = 3 。
|
||||||
|
节点 0 和 2 的边积分都是 3 。由于节点 0 的编号更小,返回 0 。
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<p><strong>提示:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>n == edges.length</code></li>
|
||||||
|
<li><code>2 <= n <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>0 <= edges[i] < n</code></li>
|
||||||
|
<li><code>edges[i] != i</code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,41 @@
|
|||||||
|
<p>You are given a binary string <code>s</code>. In one second, <strong>all</strong> occurrences of <code>"01"</code> are <strong>simultaneously</strong> replaced with <code>"10"</code>. This process <strong>repeats</strong> until no occurrences of <code>"01"</code> exist.</p>
|
||||||
|
|
||||||
|
<p>Return<em> the number of seconds needed to complete this process.</em></p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> s = "0110101"
|
||||||
|
<strong>Output:</strong> 4
|
||||||
|
<strong>Explanation:</strong>
|
||||||
|
After one second, s becomes "1011010".
|
||||||
|
After another second, s becomes "1101100".
|
||||||
|
After the third second, s becomes "1110100".
|
||||||
|
After the fourth second, s becomes "1111000".
|
||||||
|
No occurrence of "01" exists any longer, and the process needed 4 seconds to complete,
|
||||||
|
so we return 4.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> s = "11100"
|
||||||
|
<strong>Output:</strong> 0
|
||||||
|
<strong>Explanation:</strong>
|
||||||
|
No occurrence of "01" exists in s, and the processes needed 0 seconds to complete,
|
||||||
|
so we return 0.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= s.length <= 1000</code></li>
|
||||||
|
<li><code>s[i]</code> is either <code>'0'</code> or <code>'1'</code>.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Follow up:</strong></p>
|
||||||
|
|
||||||
|
<p>Can you solve this problem in O(n) time complexity?</p>
|
@ -0,0 +1,57 @@
|
|||||||
|
<p>You are given a <strong>0-indexed</strong> array of positive integers <code>tasks</code>, representing tasks that need to be completed <strong>in order</strong>, where <code>tasks[i]</code> represents the <strong>type</strong> of the <code>i<sup>th</sup></code> task.</p>
|
||||||
|
|
||||||
|
<p>You are also given a positive integer <code>space</code>, which represents the <strong>minimum</strong> number of days that must pass <strong>after</strong> the completion of a task before another task of the <strong>same</strong> type can be performed.</p>
|
||||||
|
|
||||||
|
<p>Each day, until all tasks have been completed, you must either:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>Complete the next task from <code>tasks</code>, or</li>
|
||||||
|
<li>Take a break.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Return<em> the <strong>minimum</strong> number of days needed to complete all tasks</em>.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> tasks = [1,2,1,2,3,1], space = 3
|
||||||
|
<strong>Output:</strong> 9
|
||||||
|
<strong>Explanation:</strong>
|
||||||
|
One way to complete all tasks in 9 days is as follows:
|
||||||
|
Day 1: Complete the 0th task.
|
||||||
|
Day 2: Complete the 1st task.
|
||||||
|
Day 3: Take a break.
|
||||||
|
Day 4: Take a break.
|
||||||
|
Day 5: Complete the 2nd task.
|
||||||
|
Day 6: Complete the 3rd task.
|
||||||
|
Day 7: Take a break.
|
||||||
|
Day 8: Complete the 4th task.
|
||||||
|
Day 9: Complete the 5th task.
|
||||||
|
It can be shown that the tasks cannot be completed in less than 9 days.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> tasks = [5,8,8,5], space = 2
|
||||||
|
<strong>Output:</strong> 6
|
||||||
|
<strong>Explanation:</strong>
|
||||||
|
One way to complete all tasks in 6 days is as follows:
|
||||||
|
Day 1: Complete the 0th task.
|
||||||
|
Day 2: Complete the 1st task.
|
||||||
|
Day 3: Take a break.
|
||||||
|
Day 4: Take a break.
|
||||||
|
Day 5: Complete the 2nd task.
|
||||||
|
Day 6: Complete the 3rd task.
|
||||||
|
It can be shown that the tasks cannot be completed in less than 6 days.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= tasks.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>1 <= tasks[i] <= 10<sup>9</sup></code></li>
|
||||||
|
<li><code>1 <= space <= tasks.length</code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,36 @@
|
|||||||
|
<p>You are given a non-negative integer array <code>nums</code>. In one operation, you must:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>Choose a positive integer <code>x</code> such that <code>x</code> is less than or equal to the <strong>smallest non-zero</strong> element in <code>nums</code>.</li>
|
||||||
|
<li>Subtract <code>x</code> from every <strong>positive</strong> element in <code>nums</code>.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Return <em>the <strong>minimum</strong> number of operations to make every element in </em><code>nums</code><em> equal to </em><code>0</code>.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [1,5,0,3,5]
|
||||||
|
<strong>Output:</strong> 3
|
||||||
|
<strong>Explanation:</strong>
|
||||||
|
In the first operation, choose x = 1. Now, nums = [0,4,0,2,4].
|
||||||
|
In the second operation, choose x = 2. Now, nums = [0,2,0,0,2].
|
||||||
|
In the third operation, choose x = 2. Now, nums = [0,0,0,0,0].
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [0]
|
||||||
|
<strong>Output:</strong> 0
|
||||||
|
<strong>Explanation:</strong> Each element in nums is already 0 so no operations are needed.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= nums.length <= 100</code></li>
|
||||||
|
<li><code>0 <= nums[i] <= 100</code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,37 @@
|
|||||||
|
<p>You are given a positive integer array <code>grades</code> which represents the grades of students in a university. You would like to enter <strong>all</strong> these students into a competition in <strong>ordered</strong> non-empty groups, such that the ordering meets the following conditions:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>The sum of the grades of students in the <code>i<sup>th</sup></code> group is <strong>less than</strong> the sum of the grades of students in the <code>(i + 1)<sup>th</sup></code> group, for all groups (except the last).</li>
|
||||||
|
<li>The total number of students in the <code>i<sup>th</sup></code> group is <strong>less than</strong> the total number of students in the <code>(i + 1)<sup>th</sup></code> group, for all groups (except the last).</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Return <em>the <strong>maximum</strong> number of groups that can be formed</em>.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> grades = [10,6,12,7,3,5]
|
||||||
|
<strong>Output:</strong> 3
|
||||||
|
<strong>Explanation:</strong> The following is a possible way to form 3 groups of students:
|
||||||
|
- 1<sup>st</sup> group has the students with grades = [12]. Sum of grades: 12. Student count: 1
|
||||||
|
- 2<sup>nd</sup> group has the students with grades = [6,7]. Sum of grades: 6 + 7 = 13. Student count: 2
|
||||||
|
- 3<sup>rd</sup> group has the students with grades = [10,3,5]. Sum of grades: 10 + 3 + 5 = 18. Student count: 3
|
||||||
|
It can be shown that it is not possible to form more than 3 groups.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> grades = [8,8]
|
||||||
|
<strong>Output:</strong> 1
|
||||||
|
<strong>Explanation:</strong> We can only form 1 group, since forming 2 groups would lead to an equal number of students in both groups.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= grades.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>1 <= grades[i] <= 10<sup>5</sup></code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,45 @@
|
|||||||
|
<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums</code> and <code>removeQueries</code>, both of length <code>n</code>. For the <code>i<sup>th</sup></code> query, the element in <code>nums</code> at the index <code>removeQueries[i]</code> is removed, splitting <code>nums</code> into different segments.</p>
|
||||||
|
|
||||||
|
<p>A <strong>segment</strong> is a contiguous sequence of <strong>positive</strong> integers in <code>nums</code>. A <strong>segment sum</strong> is the sum of every element in a segment.</p>
|
||||||
|
|
||||||
|
<p>Return<em> an integer array </em><code>answer</code><em>, of length </em><code>n</code><em>, where </em><code>answer[i]</code><em> is the <strong>maximum</strong> segment sum after applying the </em><code>i<sup>th</sup></code> <em>removal.</em></p>
|
||||||
|
|
||||||
|
<p><strong>Note:</strong> The same index will <strong>not</strong> be removed more than once.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [1,2,5,6,1], removeQueries = [0,3,2,4,1]
|
||||||
|
<strong>Output:</strong> [14,7,2,2,0]
|
||||||
|
<strong>Explanation:</strong> Using 0 to indicate a removed element, the answer is as follows:
|
||||||
|
Query 1: Remove the 0th element, nums becomes [0,2,5,6,1] and the maximum segment sum is 14 for segment [2,5,6,1].
|
||||||
|
Query 2: Remove the 3rd element, nums becomes [0,2,5,0,1] and the maximum segment sum is 7 for segment [2,5].
|
||||||
|
Query 3: Remove the 2nd element, nums becomes [0,2,0,0,1] and the maximum segment sum is 2 for segment [2].
|
||||||
|
Query 4: Remove the 4th element, nums becomes [0,2,0,0,0] and the maximum segment sum is 2 for segment [2].
|
||||||
|
Query 5: Remove the 1st element, nums becomes [0,0,0,0,0] and the maximum segment sum is 0, since there are no segments.
|
||||||
|
Finally, we return [14,7,2,2,0].</pre>
|
||||||
|
|
||||||
|
<p><strong>Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [3,2,11,1], removeQueries = [3,2,1,0]
|
||||||
|
<strong>Output:</strong> [16,5,3,0]
|
||||||
|
<strong>Explanation:</strong> Using 0 to indicate a removed element, the answer is as follows:
|
||||||
|
Query 1: Remove the 3rd element, nums becomes [3,2,11,0] and the maximum segment sum is 16 for segment [3,2,11].
|
||||||
|
Query 2: Remove the 2nd element, nums becomes [3,2,0,0] and the maximum segment sum is 5 for segment [3,2].
|
||||||
|
Query 3: Remove the 1st element, nums becomes [3,0,0,0] and the maximum segment sum is 3 for segment [3].
|
||||||
|
Query 4: Remove the 0th element, nums becomes [0,0,0,0] and the maximum segment sum is 0, since there are no segments.
|
||||||
|
Finally, we return [16,5,3,0].
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>n == nums.length == removeQueries.length</code></li>
|
||||||
|
<li><code>1 <= n <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>
|
||||||
|
<li><code>0 <= removeQueries[i] < n</code></li>
|
||||||
|
<li>All the values of <code>removeQueries</code> are <strong>unique</strong>.</li>
|
||||||
|
</ul>
|
@ -0,0 +1,41 @@
|
|||||||
|
<p>There is an undirected tree with <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code> and <code>n - 1</code> edges.</p>
|
||||||
|
|
||||||
|
<p>You are given a 2D integer array <code>edges</code> of length <code>n - 1</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that there is an edge between nodes <code>a<sub>i</sub></code> and <code>b<sub>i</sub></code> in the tree. You are also given an integer array <code>restricted</code> which represents <strong>restricted</strong> nodes.</p>
|
||||||
|
|
||||||
|
<p>Return <em>the <strong>maximum</strong> number of nodes you can reach from node </em><code>0</code><em> without visiting a restricted node.</em></p>
|
||||||
|
|
||||||
|
<p>Note that node <code>0</code> will <strong>not</strong> be a restricted node.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Example 1:</strong></p>
|
||||||
|
<img alt="" src="https://assets.leetcode.com/uploads/2022/06/15/ex1drawio.png" style="width: 402px; height: 322px;" />
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> n = 7, edges = [[0,1],[1,2],[3,1],[4,0],[0,5],[5,6]], restricted = [4,5]
|
||||||
|
<strong>Output:</strong> 4
|
||||||
|
<strong>Explanation:</strong> The diagram above shows the tree.
|
||||||
|
We have that [0,1,2,3] are the only nodes that can be reached from node 0 without visiting a restricted node.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>Example 2:</strong></p>
|
||||||
|
<img alt="" src="https://assets.leetcode.com/uploads/2022/06/15/ex2drawio.png" style="width: 412px; height: 312px;" />
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> n = 7, edges = [[0,1],[0,2],[0,5],[0,4],[3,2],[6,5]], restricted = [4,2,1]
|
||||||
|
<strong>Output:</strong> 3
|
||||||
|
<strong>Explanation:</strong> The diagram above shows the tree.
|
||||||
|
We have that [0,5,6] are the only nodes that can be reached from node 0 without visiting a restricted node.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>2 <= n <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>edges.length == n - 1</code></li>
|
||||||
|
<li><code>edges[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>edges</code> represents a valid tree.</li>
|
||||||
|
<li><code>1 <= restricted.length < n</code></li>
|
||||||
|
<li><code>1 <= restricted[i] < n</code></li>
|
||||||
|
<li>All the values of <code>restricted</code> are <strong>unique</strong>.</li>
|
||||||
|
</ul>
|
@ -0,0 +1,57 @@
|
|||||||
|
<p>You are given two 2D integer arrays, <code>items1</code> and <code>items2</code>, representing two sets of items. Each array <code>items</code> has the following properties:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>items[i] = [value<sub>i</sub>, weight<sub>i</sub>]</code> where <code>value<sub>i</sub></code> represents the <strong>value</strong> and <code>weight<sub>i</sub></code> represents the <strong>weight </strong>of the <code>i<sup>th</sup></code> item.</li>
|
||||||
|
<li>The value of each item in <code>items</code> is <strong>unique</strong>.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Return <em>a 2D integer array</em> <code>ret</code> <em>where</em> <code>ret[i] = [value<sub>i</sub>, weight<sub>i</sub>]</code><em>,</em> <em>with</em> <code>weight<sub>i</sub></code> <em>being the <strong>sum of weights</strong> of all items with value</em> <code>value<sub>i</sub></code>.</p>
|
||||||
|
|
||||||
|
<p><strong>Note:</strong> <code>ret</code> should be returned in <strong>ascending</strong> order by value.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> items1 = [[1,1],[4,5],[3,8]], items2 = [[3,1],[1,5]]
|
||||||
|
<strong>Output:</strong> [[1,6],[3,9],[4,5]]
|
||||||
|
<strong>Explanation:</strong>
|
||||||
|
The item with value = 1 occurs in items1 with weight = 1 and in items2 with weight = 5, total weight = 1 + 5 = 6.
|
||||||
|
The item with value = 3 occurs in items1 with weight = 8 and in items2 with weight = 1, total weight = 8 + 1 = 9.
|
||||||
|
The item with value = 4 occurs in items1 with weight = 5, total weight = 5.
|
||||||
|
Therefore, we return [[1,6],[3,9],[4,5]].
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> items1 = [[1,1],[3,2],[2,3]], items2 = [[2,1],[3,2],[1,3]]
|
||||||
|
<strong>Output:</strong> [[1,4],[2,4],[3,4]]
|
||||||
|
<strong>Explanation:</strong>
|
||||||
|
The item with value = 1 occurs in items1 with weight = 1 and in items2 with weight = 3, total weight = 1 + 3 = 4.
|
||||||
|
The item with value = 2 occurs in items1 with weight = 3 and in items2 with weight = 1, total weight = 3 + 1 = 4.
|
||||||
|
The item with value = 3 occurs in items1 with weight = 2 and in items2 with weight = 2, total weight = 2 + 2 = 4.
|
||||||
|
Therefore, we return [[1,4],[2,4],[3,4]].</pre>
|
||||||
|
|
||||||
|
<p><strong>Example 3:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> items1 = [[1,3],[2,2]], items2 = [[7,1],[2,2],[1,4]]
|
||||||
|
<strong>Output:</strong> [[1,7],[2,4],[7,1]]
|
||||||
|
<strong>Explanation:
|
||||||
|
</strong>The item with value = 1 occurs in items1 with weight = 3 and in items2 with weight = 4, total weight = 3 + 4 = 7.
|
||||||
|
The item with value = 2 occurs in items1 with weight = 2 and in items2 with weight = 2, total weight = 2 + 2 = 4.
|
||||||
|
The item with value = 7 occurs in items2 with weight = 1, total weight = 1.
|
||||||
|
Therefore, we return [[1,7],[2,4],[7,1]].
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= items1.length, items2.length <= 1000</code></li>
|
||||||
|
<li><code>items1[i].length == items2[i].length == 2</code></li>
|
||||||
|
<li><code>1 <= value<sub>i</sub>, weight<sub>i</sub> <= 1000</code></li>
|
||||||
|
<li>Each <code>value<sub>i</sub></code> in <code>items1</code> is <strong>unique</strong>.</li>
|
||||||
|
<li>Each <code>value<sub>i</sub></code> in <code>items2</code> is <strong>unique</strong>.</li>
|
||||||
|
</ul>
|
@ -0,0 +1,35 @@
|
|||||||
|
<p>You are given a <strong>directed</strong> graph of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>, where each node has <strong>at most one</strong> outgoing edge.</p>
|
||||||
|
|
||||||
|
<p>The graph is represented with a given <strong>0-indexed</strong> array <code>edges</code> of size <code>n</code>, indicating that there is a directed edge from node <code>i</code> to node <code>edges[i]</code>. If there is no outgoing edge from node <code>i</code>, then <code>edges[i] == -1</code>.</p>
|
||||||
|
|
||||||
|
<p>Return <em>the length of the <strong>longest</strong> cycle in the graph</em>. If no cycle exists, return <code>-1</code>.</p>
|
||||||
|
|
||||||
|
<p>A cycle is a path that starts and ends at the <strong>same</strong> node.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Example 1:</strong></p>
|
||||||
|
<img alt="" src="https://assets.leetcode.com/uploads/2022/06/08/graph4drawio-5.png" style="width: 335px; height: 191px;" />
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> edges = [3,3,4,2,3]
|
||||||
|
<strong>Output:</strong> 3
|
||||||
|
<strong>Explanation:</strong> The longest cycle in the graph is the cycle: 2 -> 4 -> 3 -> 2.
|
||||||
|
The length of this cycle is 3, so 3 is returned.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>Example 2:</strong></p>
|
||||||
|
<img alt="" src="https://assets.leetcode.com/uploads/2022/06/07/graph4drawio-1.png" style="width: 171px; height: 161px;" />
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> edges = [2,-1,3,1]
|
||||||
|
<strong>Output:</strong> -1
|
||||||
|
<strong>Explanation:</strong> There are no cycles in this graph.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>n == edges.length</code></li>
|
||||||
|
<li><code>2 <= n <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>-1 <= edges[i] < n</code></li>
|
||||||
|
<li><code>edges[i] != i</code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,35 @@
|
|||||||
|
<p>You are given a string <code>s</code> of lowercase English letters and a 2D integer array <code>shifts</code> where <code>shifts[i] = [start<sub>i</sub>, end<sub>i</sub>, direction<sub>i</sub>]</code>. For every <code>i</code>, <strong>shift</strong> the characters in <code>s</code> from the index <code>start<sub>i</sub></code> to the index <code>end<sub>i</sub></code> (<strong>inclusive</strong>) forward if <code>direction<sub>i</sub> = 1</code>, or shift the characters backward if <code>direction<sub>i</sub> = 0</code>.</p>
|
||||||
|
|
||||||
|
<p>Shifting a character <strong>forward</strong> means replacing it with the <strong>next</strong> letter in the alphabet (wrapping around so that <code>'z'</code> becomes <code>'a'</code>). Similarly, shifting a character <strong>backward</strong> means replacing it with the <strong>previous</strong> letter in the alphabet (wrapping around so that <code>'a'</code> becomes <code>'z'</code>).</p>
|
||||||
|
|
||||||
|
<p>Return <em>the final string after all such shifts to </em><code>s</code><em> are applied</em>.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> s = "abc", shifts = [[0,1,0],[1,2,1],[0,2,1]]
|
||||||
|
<strong>Output:</strong> "ace"
|
||||||
|
<strong>Explanation:</strong> Firstly, shift the characters from index 0 to index 1 backward. Now s = "zac".
|
||||||
|
Secondly, shift the characters from index 1 to index 2 forward. Now s = "zbd".
|
||||||
|
Finally, shift the characters from index 0 to index 2 forward. Now s = "ace".</pre>
|
||||||
|
|
||||||
|
<p><strong>Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> s = "dztz", shifts = [[0,0,0],[1,1,1]]
|
||||||
|
<strong>Output:</strong> "catz"
|
||||||
|
<strong>Explanation:</strong> Firstly, shift the characters from index 0 to index 0 backward. Now s = "cztz".
|
||||||
|
Finally, shift the characters from index 1 to index 1 forward. Now s = "catz".
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= s.length, shifts.length <= 5 * 10<sup>4</sup></code></li>
|
||||||
|
<li><code>shifts[i].length == 3</code></li>
|
||||||
|
<li><code>0 <= start<sub>i</sub> <= end<sub>i</sub> < s.length</code></li>
|
||||||
|
<li><code>0 <= direction<sub>i</sub> <= 1</code></li>
|
||||||
|
<li><code>s</code> consists of lowercase English letters.</li>
|
||||||
|
</ul>
|
@ -0,0 +1,36 @@
|
|||||||
|
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. In one operation you can replace any element of the array with <strong>any two</strong> elements that <strong>sum</strong> to it.</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>For example, consider <code>nums = [5,6,7]</code>. In one operation, we can replace <code>nums[1]</code> with <code>2</code> and <code>4</code> and convert <code>nums</code> to <code>[5,2,4,7]</code>.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Return <em>the minimum number of operations to make an array that is sorted in <strong>non-decreasing</strong> order</em>.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [3,9,3]
|
||||||
|
<strong>Output:</strong> 2
|
||||||
|
<strong>Explanation:</strong> Here are the steps to sort the array in non-decreasing order:
|
||||||
|
- From [3,9,3], replace the 9 with 3 and 6 so the array becomes [3,3,6,3]
|
||||||
|
- From [3,3,6,3], replace the 6 with 3 and 3 so the array becomes [3,3,3,3,3]
|
||||||
|
There are 2 steps to sort the array in non-decreasing order. Therefore, we return 2.
|
||||||
|
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [1,2,3,4,5]
|
||||||
|
<strong>Output:</strong> 0
|
||||||
|
<strong>Explanation:</strong> The array is already in non-decreasing order. Therefore, we return 0.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,40 @@
|
|||||||
|
<p>You are given a <strong>0-indexed</strong> string <code>blocks</code> of length <code>n</code>, where <code>blocks[i]</code> is either <code>'W'</code> or <code>'B'</code>, representing the color of the <code>i<sup>th</sup></code> block. The characters <code>'W'</code> and <code>'B'</code> denote the colors white and black, respectively.</p>
|
||||||
|
|
||||||
|
<p>You are also given an integer <code>k</code>, which is the desired number of <strong>consecutive</strong> black blocks.</p>
|
||||||
|
|
||||||
|
<p>In one operation, you can <strong>recolor</strong> a white block such that it becomes a black block.</p>
|
||||||
|
|
||||||
|
<p>Return<em> the <strong>minimum</strong> number of operations needed such that there is at least <strong>one</strong> occurrence of </em><code>k</code><em> consecutive black blocks.</em></p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> blocks = "WBBWWBBWBW", k = 7
|
||||||
|
<strong>Output:</strong> 3
|
||||||
|
<strong>Explanation:</strong>
|
||||||
|
One way to achieve 7 consecutive black blocks is to recolor the 0th, 3rd, and 4th blocks
|
||||||
|
so that blocks = "BBBBBBBWBW".
|
||||||
|
It can be shown that there is no way to achieve 7 consecutive black blocks in less than 3 operations.
|
||||||
|
Therefore, we return 3.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> blocks = "WBWBBBW", k = 2
|
||||||
|
<strong>Output:</strong> 0
|
||||||
|
<strong>Explanation:</strong>
|
||||||
|
No changes need to be made, since 2 consecutive black blocks already exist.
|
||||||
|
Therefore, we return 0.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>n == blocks.length</code></li>
|
||||||
|
<li><code>1 <= n <= 100</code></li>
|
||||||
|
<li><code>blocks[i]</code> is either <code>'W'</code> or <code>'B'</code>.</li>
|
||||||
|
<li><code>1 <= k <= n</code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,43 @@
|
|||||||
|
<p>You are given the <code>root</code> of a binary tree with <strong>unique</strong> values, and an integer <code>start</code>. At minute <code>0</code>, an <strong>infection</strong> starts from the node with value <code>start</code>.</p>
|
||||||
|
|
||||||
|
<p>Each minute, a node becomes infected if:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>The node is currently uninfected.</li>
|
||||||
|
<li>The node is adjacent to an infected node.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Return <em>the number of minutes needed for the entire tree to be infected.</em></p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Example 1:</strong></p>
|
||||||
|
<img alt="" src="https://assets.leetcode.com/uploads/2022/06/25/image-20220625231744-1.png" style="width: 400px; height: 306px;" />
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> root = [1,5,3,null,4,10,6,9,2], start = 3
|
||||||
|
<strong>Output:</strong> 4
|
||||||
|
<strong>Explanation:</strong> The following nodes are infected during:
|
||||||
|
- Minute 0: Node 3
|
||||||
|
- Minute 1: Nodes 1, 10 and 6
|
||||||
|
- Minute 2: Node 5
|
||||||
|
- Minute 3: Node 4
|
||||||
|
- Minute 4: Nodes 9 and 2
|
||||||
|
It takes 4 minutes for the whole tree to be infected so we return 4.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>Example 2:</strong></p>
|
||||||
|
<img alt="" src="https://assets.leetcode.com/uploads/2022/06/25/image-20220625231812-2.png" style="width: 75px; height: 66px;" />
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> root = [1], start = 1
|
||||||
|
<strong>Output:</strong> 0
|
||||||
|
<strong>Explanation:</strong> At minute 0, the only node in the tree is infected so we return 0.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>The number of nodes in the tree is in the range <code>[1, 10<sup>5</sup>]</code>.</li>
|
||||||
|
<li><code>1 <= Node.val <= 10<sup>5</sup></code></li>
|
||||||
|
<li>Each node has a <strong>unique</strong> value.</li>
|
||||||
|
<li>A node with a value of <code>start</code> exists in the tree.</li>
|
||||||
|
</ul>
|
@ -0,0 +1,38 @@
|
|||||||
|
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>. You can choose any <strong>subsequence</strong> of the array and sum all of its elements together.</p>
|
||||||
|
|
||||||
|
<p>We define the <strong>K-Sum</strong> of the array as the <code>k<sup>th</sup></code> <strong>largest</strong> subsequence sum that can be obtained (<strong>not</strong> necessarily distinct).</p>
|
||||||
|
|
||||||
|
<p>Return <em>the K-Sum of the array</em>.</p>
|
||||||
|
|
||||||
|
<p>A <strong>subsequence</strong> is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.</p>
|
||||||
|
|
||||||
|
<p><strong>Note</strong> that the empty subsequence is considered to have a sum of <code>0</code>.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [2,4,-2], k = 5
|
||||||
|
<strong>Output:</strong> 2
|
||||||
|
<strong>Explanation:</strong> All the possible subsequence sums that we can obtain are the following sorted in decreasing order:
|
||||||
|
- 6, 4, 4, 2, <u>2</u>, 0, 0, -2.
|
||||||
|
The 5-Sum of the array is 2.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [1,-2,3,4,-10,12], k = 16
|
||||||
|
<strong>Output:</strong> 10
|
||||||
|
<strong>Explanation:</strong> The 16-Sum of the array is 10.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>n == nums.length</code></li>
|
||||||
|
<li><code>1 <= n <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li>
|
||||||
|
<li><code>1 <= k <= min(2000, 2<sup>n</sup>)</code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,39 @@
|
|||||||
|
<p>You are given a <strong>directed</strong> graph of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>, where each node has <strong>at most one</strong> outgoing edge.</p>
|
||||||
|
|
||||||
|
<p>The graph is represented with a given <strong>0-indexed</strong> array <code>edges</code> of size <code>n</code>, indicating that there is a directed edge from node <code>i</code> to node <code>edges[i]</code>. If there is no outgoing edge from <code>i</code>, then <code>edges[i] == -1</code>.</p>
|
||||||
|
|
||||||
|
<p>You are also given two integers <code>node1</code> and <code>node2</code>.</p>
|
||||||
|
|
||||||
|
<p>Return <em>the <strong>index</strong> of the node that can be reached from both </em><code>node1</code><em> and </em><code>node2</code><em>, such that the <strong>maximum</strong> between the distance from </em><code>node1</code><em> to that node, and from </em><code>node2</code><em> to that node is <strong>minimized</strong></em>. If there are multiple answers, return the node with the <strong>smallest</strong> index, and if no possible answer exists, return <code>-1</code>.</p>
|
||||||
|
|
||||||
|
<p>Note that <code>edges</code> may contain cycles.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Example 1:</strong></p>
|
||||||
|
<img alt="" src="https://assets.leetcode.com/uploads/2022/06/07/graph4drawio-2.png" style="width: 321px; height: 161px;" />
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> edges = [2,2,3,-1], node1 = 0, node2 = 1
|
||||||
|
<strong>Output:</strong> 2
|
||||||
|
<strong>Explanation:</strong> The distance from node 0 to node 2 is 1, and the distance from node 1 to node 2 is 1.
|
||||||
|
The maximum of those two distances is 1. It can be proven that we cannot get a node with a smaller maximum distance than 1, so we return node 2.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>Example 2:</strong></p>
|
||||||
|
<img alt="" src="https://assets.leetcode.com/uploads/2022/06/07/graph4drawio-4.png" style="width: 195px; height: 161px;" />
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> edges = [1,2,-1], node1 = 0, node2 = 2
|
||||||
|
<strong>Output:</strong> 2
|
||||||
|
<strong>Explanation:</strong> The distance from node 0 to node 2 is 2, and the distance from node 2 to itself is 0.
|
||||||
|
The maximum of those two distances is 2. It can be proven that we cannot get a node with a smaller maximum distance than 2, so we return node 2.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>n == edges.length</code></li>
|
||||||
|
<li><code>2 <= n <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>-1 <= edges[i] < n</code></li>
|
||||||
|
<li><code>edges[i] != i</code></li>
|
||||||
|
<li><code>0 <= node1, node2 < n</code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,39 @@
|
|||||||
|
<p>You are given a string <code>num</code> consisting of digits only.</p>
|
||||||
|
|
||||||
|
<p>Return <em>the <strong>largest palindromic</strong> integer (in the form of a string) that can be formed using digits taken from </em><code>num</code>. It should not contain <strong>leading zeroes</strong>.</p>
|
||||||
|
|
||||||
|
<p><strong>Notes:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>You do <strong>not</strong> need to use all the digits of <code>num</code>, but you must use <strong>at least</strong> one digit.</li>
|
||||||
|
<li>The digits can be reordered.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> num = "444947137"
|
||||||
|
<strong>Output:</strong> "7449447"
|
||||||
|
<strong>Explanation:</strong>
|
||||||
|
Use the digits "4449477" from "<u><strong>44494</strong></u><u><strong>7</strong></u>13<u><strong>7</strong></u>" to form the palindromic integer "7449447".
|
||||||
|
It can be shown that "7449447" is the largest palindromic integer that can be formed.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> num = "00009"
|
||||||
|
<strong>Output:</strong> "9"
|
||||||
|
<strong>Explanation:</strong>
|
||||||
|
It can be shown that "9" is the largest palindromic integer that can be formed.
|
||||||
|
Note that the integer returned should not contain leading zeroes.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= num.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>num</code> consists of digits.</li>
|
||||||
|
</ul>
|
@ -0,0 +1,38 @@
|
|||||||
|
<p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>t</code> is a <strong>subsequence</strong> of the string <code>s</code>.</li>
|
||||||
|
<li>The absolute difference in the alphabet order of every two <strong>adjacent</strong> letters in <code>t</code> is less than or equal to <code>k</code>.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Return <em>the length of the <strong>longest</strong> ideal string</em>.</p>
|
||||||
|
|
||||||
|
<p>A <strong>subsequence</strong> is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.</p>
|
||||||
|
|
||||||
|
<p><strong>Note</strong> that the alphabet order is not cyclic. For example, the absolute difference in the alphabet order of <code>'a'</code> and <code>'z'</code> is <code>25</code>, not <code>1</code>.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> s = "acfgbd", k = 2
|
||||||
|
<strong>Output:</strong> 4
|
||||||
|
<strong>Explanation:</strong> The longest ideal string is "acbd". The length of this string is 4, so 4 is returned.
|
||||||
|
Note that "acfgbd" is not ideal because 'c' and 'f' have a difference of 3 in alphabet order.</pre>
|
||||||
|
|
||||||
|
<p><strong>Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> s = "abcd", k = 3
|
||||||
|
<strong>Output:</strong> 4
|
||||||
|
<strong>Explanation:</strong> The longest ideal string is "abcd". The length of this string is 4, so 4 is returned.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= s.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>0 <= k <= 25</code></li>
|
||||||
|
<li><code>s</code> consists of lowercase English letters.</li>
|
||||||
|
</ul>
|
@ -0,0 +1,42 @@
|
|||||||
|
<p>You are given a <strong>0-indexed</strong> string <code>pattern</code> of length <code>n</code> consisting of the characters <code>'I'</code> meaning <strong>increasing</strong> and <code>'D'</code> meaning <strong>decreasing</strong>.</p>
|
||||||
|
|
||||||
|
<p>A <strong>0-indexed</strong> string <code>num</code> of length <code>n + 1</code> is created using the following conditions:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>num</code> consists of the digits <code>'1'</code> to <code>'9'</code>, where each digit is used <strong>at most</strong> once.</li>
|
||||||
|
<li>If <code>pattern[i] == 'I'</code>, then <code>num[i] < num[i + 1]</code>.</li>
|
||||||
|
<li>If <code>pattern[i] == 'D'</code>, then <code>num[i] > num[i + 1]</code>.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Return <em>the lexicographically <strong>smallest</strong> possible string </em><code>num</code><em> that meets the conditions.</em></p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> pattern = "IIIDIDDD"
|
||||||
|
<strong>Output:</strong> "123549876"
|
||||||
|
<strong>Explanation:
|
||||||
|
</strong>At indices 0, 1, 2, and 4 we must have that num[i] < num[i+1].
|
||||||
|
At indices 3, 5, 6, and 7 we must have that num[i] > num[i+1].
|
||||||
|
Some possible values of num are "245639871", "135749862", and "123849765".
|
||||||
|
It can be proven that "123549876" is the smallest possible num that meets the conditions.
|
||||||
|
Note that "123414321" is not possible because the digit '1' is used more than once.</pre>
|
||||||
|
|
||||||
|
<p><strong>Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> pattern = "DDD"
|
||||||
|
<strong>Output:</strong> "4321"
|
||||||
|
<strong>Explanation:</strong>
|
||||||
|
Some possible values of num are "9876", "7321", and "8742".
|
||||||
|
It can be proven that "4321" is the smallest possible num that meets the conditions.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= pattern.length <= 8</code></li>
|
||||||
|
<li><code>pattern</code> consists of only the letters <code>'I'</code> and <code>'D'</code>.</li>
|
||||||
|
</ul>
|
@ -0,0 +1,37 @@
|
|||||||
|
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. You have to partition the array into one or more <strong>contiguous</strong> subarrays.</p>
|
||||||
|
|
||||||
|
<p>We call a partition of the array <strong>valid</strong> if each of the obtained subarrays satisfies <strong>one</strong> of the following conditions:</p>
|
||||||
|
|
||||||
|
<ol>
|
||||||
|
<li>The subarray consists of <strong>exactly</strong> <code>2</code> equal elements. For example, the subarray <code>[2,2]</code> is good.</li>
|
||||||
|
<li>The subarray consists of <strong>exactly</strong> <code>3</code> equal elements. For example, the subarray <code>[4,4,4]</code> is good.</li>
|
||||||
|
<li>The subarray consists of <strong>exactly</strong> <code>3</code> consecutive increasing elements, that is, the difference between adjacent elements is <code>1</code>. For example, the subarray <code>[3,4,5]</code> is good, but the subarray <code>[1,3,5]</code> is not.</li>
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
<p>Return <code>true</code><em> if the array has <strong>at least</strong> one valid partition</em>. Otherwise, return <code>false</code>.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [4,4,4,5,6]
|
||||||
|
<strong>Output:</strong> true
|
||||||
|
<strong>Explanation:</strong> The array can be partitioned into the subarrays [4,4] and [4,5,6].
|
||||||
|
This partition is valid, so we return true.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [1,1,1,2]
|
||||||
|
<strong>Output:</strong> false
|
||||||
|
<strong>Explanation:</strong> There is no valid partition for this array.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>2 <= nums.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>1 <= nums[i] <= 10<sup>6</sup></code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,37 @@
|
|||||||
|
<p>You are given an <code>n x n</code> integer matrix <code>grid</code>.</p>
|
||||||
|
|
||||||
|
<p>Generate an integer matrix <code>maxLocal</code> of size <code>(n - 2) x (n - 2)</code> such that:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>maxLocal[i][j]</code> is equal to the <strong>largest</strong> value of the <code>3 x 3</code> matrix in <code>grid</code> centered around row <code>i + 1</code> and column <code>j + 1</code>.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>In other words, we want to find the largest value in every contiguous <code>3 x 3</code> matrix in <code>grid</code>.</p>
|
||||||
|
|
||||||
|
<p>Return <em>the generated matrix</em>.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Example 1:</strong></p>
|
||||||
|
<img alt="" src="https://assets.leetcode.com/uploads/2022/06/21/ex1.png" style="width: 371px; height: 210px;" />
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> grid = [[9,9,8,1],[5,6,2,6],[8,2,6,4],[6,2,2,2]]
|
||||||
|
<strong>Output:</strong> [[9,9],[8,6]]
|
||||||
|
<strong>Explanation:</strong> The diagram above shows the original matrix and the generated matrix.
|
||||||
|
Notice that each value in the generated matrix corresponds to the largest value of a contiguous 3 x 3 matrix in grid.</pre>
|
||||||
|
|
||||||
|
<p><strong>Example 2:</strong></p>
|
||||||
|
<img alt="" src="https://assets.leetcode.com/uploads/2022/07/02/ex2new2.png" style="width: 436px; height: 240px;" />
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> grid = [[1,1,1,1,1],[1,1,1,1,1],[1,1,2,1,1],[1,1,1,1,1],[1,1,1,1,1]]
|
||||||
|
<strong>Output:</strong> [[2,2,2],[2,2,2],[2,2,2]]
|
||||||
|
<strong>Explanation:</strong> Notice that the 2 is contained within every contiguous 3 x 3 matrix in grid.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>n == grid.length == grid[i].length</code></li>
|
||||||
|
<li><code>3 <= n <= 100</code></li>
|
||||||
|
<li><code>1 <= grid[i][j] <= 100</code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,40 @@
|
|||||||
|
<p>You are given a <strong>0-indexed</strong>, <strong>strictly increasing</strong> integer array <code>nums</code> and a positive integer <code>diff</code>. A triplet <code>(i, j, k)</code> is an <strong>arithmetic triplet</strong> if the following conditions are met:</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>i < j < k</code>,</li>
|
||||||
|
<li><code>nums[j] - nums[i] == diff</code>, and</li>
|
||||||
|
<li><code>nums[k] - nums[j] == diff</code>.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Return <em>the number of unique <strong>arithmetic triplets</strong>.</em></p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [0,1,4,6,7,10], diff = 3
|
||||||
|
<strong>Output:</strong> 2
|
||||||
|
<strong>Explanation:</strong>
|
||||||
|
(1, 2, 4) is an arithmetic triplet because both 7 - 4 == 3 and 4 - 1 == 3.
|
||||||
|
(2, 4, 5) is an arithmetic triplet because both 10 - 7 == 3 and 7 - 4 == 3.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [4,5,6,7,8,9], diff = 2
|
||||||
|
<strong>Output:</strong> 2
|
||||||
|
<strong>Explanation:</strong>
|
||||||
|
(0, 2, 4) is an arithmetic triplet because both 8 - 6 == 2 and 6 - 4 == 2.
|
||||||
|
(1, 3, 5) is an arithmetic triplet because both 9 - 7 == 2 and 7 - 5 == 2.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>3 <= nums.length <= 200</code></li>
|
||||||
|
<li><code>0 <= nums[i] <= 200</code></li>
|
||||||
|
<li><code>1 <= diff <= 50</code></li>
|
||||||
|
<li><code>nums</code> is <strong>strictly</strong> increasing.</li>
|
||||||
|
</ul>
|
@ -0,0 +1,33 @@
|
|||||||
|
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of indices <code>(i, j)</code> is a <strong>bad pair</strong> if <code>i < j</code> and <code>j - i != nums[j] - nums[i]</code>.</p>
|
||||||
|
|
||||||
|
<p>Return<em> the total number of <strong>bad pairs</strong> in </em><code>nums</code>.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [4,1,3,3]
|
||||||
|
<strong>Output:</strong> 5
|
||||||
|
<strong>Explanation:</strong> The pair (0, 1) is a bad pair since 1 - 0 != 1 - 4.
|
||||||
|
The pair (0, 2) is a bad pair since 2 - 0 != 3 - 4, 2 != -1.
|
||||||
|
The pair (0, 3) is a bad pair since 3 - 0 != 3 - 4, 3 != -1.
|
||||||
|
The pair (1, 2) is a bad pair since 2 - 1 != 3 - 1, 1 != 2.
|
||||||
|
The pair (2, 3) is a bad pair since 3 - 2 != 3 - 3, 1 != 0.
|
||||||
|
There are a total of 5 bad pairs, so we return 5.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> nums = [1,2,3,4,5]
|
||||||
|
<strong>Output:</strong> 0
|
||||||
|
<strong>Explanation:</strong> There are no bad pairs.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,35 @@
|
|||||||
|
<p>We call a positive integer <strong>special</strong> if all of its digits are <strong>distinct</strong>.</p>
|
||||||
|
|
||||||
|
<p>Given a <strong>positive</strong> integer <code>n</code>, return <em>the number of special integers that belong to the interval </em><code>[1, n]</code>.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> n = 20
|
||||||
|
<strong>Output:</strong> 19
|
||||||
|
<strong>Explanation:</strong> All the integers from 1 to 20, except 11, are special. Thus, there are 19 special integers.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> n = 5
|
||||||
|
<strong>Output:</strong> 5
|
||||||
|
<strong>Explanation:</strong> All the integers from 1 to 5 are special.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>Example 3:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> n = 135
|
||||||
|
<strong>Output:</strong> 110
|
||||||
|
<strong>Explanation:</strong> There are 110 integers from 1 to 135 that are special.
|
||||||
|
Some of the integers that are not special are: 22, 114, and 131.</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>1 <= n <= 2 * 10<sup>9</sup></code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,48 @@
|
|||||||
|
<p>You are entering a competition, and are given two <strong>positive</strong> integers <code>initialEnergy</code> and <code>initialExperience</code> denoting your initial energy and initial experience respectively.</p>
|
||||||
|
|
||||||
|
<p>You are also given two <strong>0-indexed</strong> integer arrays <code>energy</code> and <code>experience</code>, both of length <code>n</code>.</p>
|
||||||
|
|
||||||
|
<p>You will face <code>n</code> opponents <strong>in order</strong>. The energy and experience of the <code>i<sup>th</sup></code> opponent is denoted by <code>energy[i]</code> and <code>experience[i]</code> respectively. When you face an opponent, you need to have both <strong>strictly</strong> greater experience and energy to defeat them and move to the next opponent if available.</p>
|
||||||
|
|
||||||
|
<p>Defeating the <code>i<sup>th</sup></code> opponent <strong>increases</strong> your experience by <code>experience[i]</code>, but <strong>decreases</strong> your energy by <code>energy[i]</code>.</p>
|
||||||
|
|
||||||
|
<p>Before starting the competition, you can train for some number of hours. After each hour of training, you can <strong>either</strong> choose to increase your initial experience by one, or increase your initial energy by one.</p>
|
||||||
|
|
||||||
|
<p>Return <em>the <strong>minimum</strong> number of training hours required to defeat all </em><code>n</code><em> opponents</em>.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Example 1:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> initialEnergy = 5, initialExperience = 3, energy = [1,4,3,2], experience = [2,6,3,1]
|
||||||
|
<strong>Output:</strong> 8
|
||||||
|
<strong>Explanation:</strong> You can increase your energy to 11 after 6 hours of training, and your experience to 5 after 2 hours of training.
|
||||||
|
You face the opponents in the following order:
|
||||||
|
- You have more energy and experience than the 0<sup>th</sup> opponent so you win.
|
||||||
|
Your energy becomes 11 - 1 = 10, and your experience becomes 5 + 2 = 7.
|
||||||
|
- You have more energy and experience than the 1<sup>st</sup> opponent so you win.
|
||||||
|
Your energy becomes 10 - 4 = 6, and your experience becomes 7 + 6 = 13.
|
||||||
|
- You have more energy and experience than the 2<sup>nd</sup> opponent so you win.
|
||||||
|
Your energy becomes 6 - 3 = 3, and your experience becomes 13 + 3 = 16.
|
||||||
|
- You have more energy and experience than the 3<sup>rd</sup> opponent so you win.
|
||||||
|
Your energy becomes 3 - 2 = 1, and your experience becomes 16 + 1 = 17.
|
||||||
|
You did a total of 6 + 2 = 8 hours of training before the competition, so we return 8.
|
||||||
|
It can be proven that no smaller answer exists.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>Example 2:</strong></p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> initialEnergy = 2, initialExperience = 4, energy = [1], experience = [3]
|
||||||
|
<strong>Output:</strong> 0
|
||||||
|
<strong>Explanation:</strong> You do not need any additional energy or experience to win the competition, so we return 0.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>n == energy.length == experience.length</code></li>
|
||||||
|
<li><code>1 <= n <= 100</code></li>
|
||||||
|
<li><code>1 <= initialEnergy, initialExperience, energy[i], experience[i] <= 100</code></li>
|
||||||
|
</ul>
|
@ -0,0 +1,42 @@
|
|||||||
|
<p>You are given a directed graph with <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>, where each node has <strong>exactly one</strong> outgoing edge.</p>
|
||||||
|
|
||||||
|
<p>The graph is represented by a given <strong>0-indexed</strong> integer array <code>edges</code> of length <code>n</code>, where <code>edges[i]</code> indicates that there is a <strong>directed</strong> edge from node <code>i</code> to node <code>edges[i]</code>.</p>
|
||||||
|
|
||||||
|
<p>The <strong>edge score</strong> of a node <code>i</code> is defined as the sum of the <strong>labels</strong> of all the nodes that have an edge pointing to <code>i</code>.</p>
|
||||||
|
|
||||||
|
<p>Return <em>the node with the highest <strong>edge score</strong></em>. If multiple nodes have the same <strong>edge score</strong>, return the node with the <strong>smallest</strong> index.</p>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Example 1:</strong></p>
|
||||||
|
<img src="https://assets.leetcode.com/uploads/2022/06/20/image-20220620195403-1.png" style="width: 450px; height: 260px;" />
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> edges = [1,0,0,0,0,7,7,5]
|
||||||
|
<strong>Output:</strong> 7
|
||||||
|
<strong>Explanation:</strong>
|
||||||
|
- The nodes 1, 2, 3 and 4 have an edge pointing to node 0. The edge score of node 0 is 1 + 2 + 3 + 4 = 10.
|
||||||
|
- The node 0 has an edge pointing to node 1. The edge score of node 1 is 0.
|
||||||
|
- The node 7 has an edge pointing to node 5. The edge score of node 5 is 7.
|
||||||
|
- The nodes 5 and 6 have an edge pointing to node 7. The edge score of node 7 is 5 + 6 = 11.
|
||||||
|
Node 7 has the highest edge score so return 7.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p><strong>Example 2:</strong></p>
|
||||||
|
<img src="https://assets.leetcode.com/uploads/2022/06/20/image-20220620200212-3.png" style="width: 150px; height: 155px;" />
|
||||||
|
<pre>
|
||||||
|
<strong>Input:</strong> edges = [2,0,0,2]
|
||||||
|
<strong>Output:</strong> 0
|
||||||
|
<strong>Explanation:</strong>
|
||||||
|
- The nodes 1 and 2 have an edge pointing to node 0. The edge score of node 0 is 1 + 2 = 3.
|
||||||
|
- The nodes 0 and 3 have an edge pointing to node 2. The edge score of node 2 is 0 + 3 = 3.
|
||||||
|
Nodes 0 and 2 both have an edge score of 3. Since node 0 has a smaller index, we return 0.
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
<p><strong>Constraints:</strong></p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>n == edges.length</code></li>
|
||||||
|
<li><code>2 <= n <= 10<sup>5</sup></code></li>
|
||||||
|
<li><code>0 <= edges[i] < n</code></li>
|
||||||
|
<li><code>edges[i] != i</code></li>
|
||||||
|
</ul>
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,67 @@
|
|||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"question": {
|
||||||
|
"questionId": "2515",
|
||||||
|
"questionFrontendId": "2372",
|
||||||
|
"boundTopicId": null,
|
||||||
|
"title": "Calculate the Influence of Each Salesperson",
|
||||||
|
"titleSlug": "calculate-the-influence-of-each-salesperson",
|
||||||
|
"content": null,
|
||||||
|
"translatedTitle": null,
|
||||||
|
"translatedContent": null,
|
||||||
|
"isPaidOnly": true,
|
||||||
|
"difficulty": "Medium",
|
||||||
|
"likes": 6,
|
||||||
|
"dislikes": 4,
|
||||||
|
"isLiked": null,
|
||||||
|
"similarQuestions": "[]",
|
||||||
|
"exampleTestcases": "{\"headers\":{\"Salesperson\":[\"salesperson_id\",\"name\"],\"Customer\":[\"customer_id\",\"salesperson_id\"],\"Sales\":[\"sale_id\",\"customer_id\",\"price\"]},\"rows\":{\"Salesperson\":[[1,\"Alice\"],[2,\"Bob\"],[3,\"Jerry\"]],\"Customer\":[[1,1],[2,1],[3,2]],\"Sales\":[[1,2,892],[2,1,354],[3,3,988],[4,3,856]]}}",
|
||||||
|
"categoryTitle": "Database",
|
||||||
|
"contributors": [],
|
||||||
|
"topicTags": [
|
||||||
|
{
|
||||||
|
"name": "Database",
|
||||||
|
"slug": "database",
|
||||||
|
"translatedName": null,
|
||||||
|
"__typename": "TopicTagNode"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"companyTagStats": null,
|
||||||
|
"codeSnippets": null,
|
||||||
|
"stats": "{\"totalAccepted\": \"407\", \"totalSubmission\": \"445\", \"totalAcceptedRaw\": 407, \"totalSubmissionRaw\": 445, \"acRate\": \"91.5%\"}",
|
||||||
|
"hints": [],
|
||||||
|
"solution": null,
|
||||||
|
"status": null,
|
||||||
|
"sampleTestCase": "{\"headers\":{\"Salesperson\":[\"salesperson_id\",\"name\"],\"Customer\":[\"customer_id\",\"salesperson_id\"],\"Sales\":[\"sale_id\",\"customer_id\",\"price\"]},\"rows\":{\"Salesperson\":[[1,\"Alice\"],[2,\"Bob\"],[3,\"Jerry\"]],\"Customer\":[[1,1],[2,1],[3,2]],\"Sales\":[[1,2,892],[2,1,354],[3,3,988],[4,3,856]]}}",
|
||||||
|
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Salesperson (salesperson_id int, name varchar(30))\",\n \"Create table If Not Exists Customer (customer_id int, salesperson_id int)\",\n \"Create table If Not Exists Sales (sale_id int, customer_id int, price int)\"\n ],\n \"mssql\": [\n \"Create table Salesperson (salesperson_id int, name varchar(30))\",\n \"Create table Customer (customer_id int, salesperson_id int)\",\n \"Create table Sales (sale_id int, customer_id int, price int)\"\n ],\n \"oraclesql\": [\n \"Create table Salesperson (salesperson_id int, name varchar(30))\",\n \"Create table Customer (customer_id int, salesperson_id int)\",\n \"Create table Sales (sale_id int, customer_id int, price int)\"\n ],\n \"database\": true\n}",
|
||||||
|
"judgerAvailable": true,
|
||||||
|
"judgeType": "large",
|
||||||
|
"mysqlSchemas": [
|
||||||
|
"Create table If Not Exists Salesperson (salesperson_id int, name varchar(30))",
|
||||||
|
"Create table If Not Exists Customer (customer_id int, salesperson_id int)",
|
||||||
|
"Create table If Not Exists Sales (sale_id int, customer_id int, price int)",
|
||||||
|
"Truncate table Salesperson",
|
||||||
|
"insert into Salesperson (salesperson_id, name) values ('1', 'Alice')",
|
||||||
|
"insert into Salesperson (salesperson_id, name) values ('2', 'Bob')",
|
||||||
|
"insert into Salesperson (salesperson_id, name) values ('3', 'Jerry')",
|
||||||
|
"Truncate table Customer",
|
||||||
|
"insert into Customer (customer_id, salesperson_id) values ('1', '1')",
|
||||||
|
"insert into Customer (customer_id, salesperson_id) values ('2', '1')",
|
||||||
|
"insert into Customer (customer_id, salesperson_id) values ('3', '2')",
|
||||||
|
"Truncate table Sales",
|
||||||
|
"insert into Sales (sale_id, customer_id, price) values ('1', '2', '892')",
|
||||||
|
"insert into Sales (sale_id, customer_id, price) values ('2', '1', '354')",
|
||||||
|
"insert into Sales (sale_id, customer_id, price) values ('3', '3', '988')",
|
||||||
|
"insert into Sales (sale_id, customer_id, price) values ('4', '3', '856')"
|
||||||
|
],
|
||||||
|
"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
62
leetcode/originData/[no content]generate-the-invoice.json
Normal file
62
leetcode/originData/[no content]generate-the-invoice.json
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"question": {
|
||||||
|
"questionId": "2501",
|
||||||
|
"questionFrontendId": "2362",
|
||||||
|
"boundTopicId": null,
|
||||||
|
"title": "Generate the Invoice",
|
||||||
|
"titleSlug": "generate-the-invoice",
|
||||||
|
"content": null,
|
||||||
|
"translatedTitle": null,
|
||||||
|
"translatedContent": null,
|
||||||
|
"isPaidOnly": true,
|
||||||
|
"difficulty": "Hard",
|
||||||
|
"likes": 11,
|
||||||
|
"dislikes": 9,
|
||||||
|
"isLiked": null,
|
||||||
|
"similarQuestions": "[]",
|
||||||
|
"exampleTestcases": "{\"headers\":{\"Products\":[\"product_id\",\"price\"],\"Purchases\":[\"invoice_id\",\"product_id\",\"quantity\"]},\"rows\":{\"Products\":[[1,100],[2,200]],\"Purchases\":[[1,1,2],[3,2,1],[2,2,3],[2,1,4],[4,1,10]]}}",
|
||||||
|
"categoryTitle": "Database",
|
||||||
|
"contributors": [],
|
||||||
|
"topicTags": [
|
||||||
|
{
|
||||||
|
"name": "Database",
|
||||||
|
"slug": "database",
|
||||||
|
"translatedName": null,
|
||||||
|
"__typename": "TopicTagNode"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"companyTagStats": null,
|
||||||
|
"codeSnippets": null,
|
||||||
|
"stats": "{\"totalAccepted\": \"397\", \"totalSubmission\": \"433\", \"totalAcceptedRaw\": 397, \"totalSubmissionRaw\": 433, \"acRate\": \"91.7%\"}",
|
||||||
|
"hints": [],
|
||||||
|
"solution": null,
|
||||||
|
"status": null,
|
||||||
|
"sampleTestCase": "{\"headers\":{\"Products\":[\"product_id\",\"price\"],\"Purchases\":[\"invoice_id\",\"product_id\",\"quantity\"]},\"rows\":{\"Products\":[[1,100],[2,200]],\"Purchases\":[[1,1,2],[3,2,1],[2,2,3],[2,1,4],[4,1,10]]}}",
|
||||||
|
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Products (product_id int, price int)\",\n \"Create table If Not Exists Purchases (invoice_id int, product_id int, quantity int)\"\n ],\n \"mssql\": [\n \"Create table Products (product_id int, price int)\",\n \"Create table Purchases (invoice_id int, product_id int, quantity int)\"\n ],\n \"oraclesql\": [\n \"Create table Products (product_id int, price int)\",\n \"Create table Purchases (invoice_id int, product_id int, quantity int)\"\n ],\n \"database\": true\n}",
|
||||||
|
"judgerAvailable": true,
|
||||||
|
"judgeType": "large",
|
||||||
|
"mysqlSchemas": [
|
||||||
|
"Create table If Not Exists Products (product_id int, price int)",
|
||||||
|
"Create table If Not Exists Purchases (invoice_id int, product_id int, quantity int)",
|
||||||
|
"Truncate table Products",
|
||||||
|
"insert into Products (product_id, price) values ('1', '100')",
|
||||||
|
"insert into Products (product_id, price) values ('2', '200')",
|
||||||
|
"Truncate table Purchases",
|
||||||
|
"insert into Purchases (invoice_id, product_id, quantity) values ('1', '1', '2')",
|
||||||
|
"insert into Purchases (invoice_id, product_id, quantity) values ('3', '2', '1')",
|
||||||
|
"insert into Purchases (invoice_id, product_id, quantity) values ('2', '2', '3')",
|
||||||
|
"insert into Purchases (invoice_id, product_id, quantity) values ('2', '1', '4')",
|
||||||
|
"insert into Purchases (invoice_id, product_id, quantity) values ('4', '1', '10')"
|
||||||
|
],
|
||||||
|
"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
58
leetcode/originData/[no content]sort-the-olympic-table.json
Normal file
58
leetcode/originData/[no content]sort-the-olympic-table.json
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"question": {
|
||||||
|
"questionId": "2516",
|
||||||
|
"questionFrontendId": "2377",
|
||||||
|
"boundTopicId": null,
|
||||||
|
"title": "Sort the Olympic Table",
|
||||||
|
"titleSlug": "sort-the-olympic-table",
|
||||||
|
"content": null,
|
||||||
|
"translatedTitle": null,
|
||||||
|
"translatedContent": null,
|
||||||
|
"isPaidOnly": true,
|
||||||
|
"difficulty": "Easy",
|
||||||
|
"likes": 9,
|
||||||
|
"dislikes": 0,
|
||||||
|
"isLiked": null,
|
||||||
|
"similarQuestions": "[]",
|
||||||
|
"exampleTestcases": null,
|
||||||
|
"categoryTitle": "Database",
|
||||||
|
"contributors": [],
|
||||||
|
"topicTags": [
|
||||||
|
{
|
||||||
|
"name": "Database",
|
||||||
|
"slug": "database",
|
||||||
|
"translatedName": null,
|
||||||
|
"__typename": "TopicTagNode"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"companyTagStats": null,
|
||||||
|
"codeSnippets": null,
|
||||||
|
"stats": "{\"totalAccepted\": \"474\", \"totalSubmission\": \"562\", \"totalAcceptedRaw\": 474, \"totalSubmissionRaw\": 562, \"acRate\": \"84.3%\"}",
|
||||||
|
"hints": [],
|
||||||
|
"solution": null,
|
||||||
|
"status": null,
|
||||||
|
"sampleTestCase": "{\"headers\":{\"Olympic\":[\"country\",\"gold_medals\",\"silver_medals\",\"bronze_medals\"]},\"rows\":{\"Olympic\":[[\"China\",10,10,20],[\"South Sudan\",0,0,1],[\"USA\",10,10,20],[\"Israel\",2,2,3],[\"Egypt\",2,2,2]]}}",
|
||||||
|
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Olympic (country varchar(50), gold_medals int, silver_medals int, bronze_medals int)\"\n ],\n \"mssql\": [\n \"Create table Olympic (country varchar(50), gold_medals int, silver_medals int, bronze_medals int)\"\n ],\n \"oraclesql\": [\n \"Create table Olympic (country varchar(50), gold_medals int, silver_medals int, bronze_medals int)\"\n ],\n \"database\": true\n}",
|
||||||
|
"judgerAvailable": true,
|
||||||
|
"judgeType": "large",
|
||||||
|
"mysqlSchemas": [
|
||||||
|
"Create table If Not Exists Olympic (country varchar(50), gold_medals int, silver_medals int, bronze_medals int)",
|
||||||
|
"Truncate table Olympic",
|
||||||
|
"insert into Olympic (country, gold_medals, silver_medals, bronze_medals) values ('China', '10', '10', '20')",
|
||||||
|
"insert into Olympic (country, gold_medals, silver_medals, bronze_medals) values ('South Sudan', '0', '0', '1')",
|
||||||
|
"insert into Olympic (country, gold_medals, silver_medals, bronze_medals) values ('USA', '10', '10', '20')",
|
||||||
|
"insert into Olympic (country, gold_medals, silver_medals, bronze_medals) values ('Israel', '2', '2', '3')",
|
||||||
|
"insert into Olympic (country, gold_medals, silver_medals, bronze_medals) values ('Egypt', '2', '2', '2')"
|
||||||
|
],
|
||||||
|
"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
175
leetcode/originData/count-number-of-bad-pairs.json
Normal file
175
leetcode/originData/count-number-of-bad-pairs.json
Normal file
File diff suppressed because one or more lines are too long
174
leetcode/originData/count-special-integers.json
Normal file
174
leetcode/originData/count-special-integers.json
Normal file
File diff suppressed because one or more lines are too long
174
leetcode/originData/find-closest-node-to-given-two-nodes.json
Normal file
174
leetcode/originData/find-closest-node-to-given-two-nodes.json
Normal file
File diff suppressed because one or more lines are too long
180
leetcode/originData/find-the-k-sum-of-an-array.json
Normal file
180
leetcode/originData/find-the-k-sum-of-an-array.json
Normal file
File diff suppressed because one or more lines are too long
174
leetcode/originData/largest-local-values-in-a-matrix.json
Normal file
174
leetcode/originData/largest-local-values-in-a-matrix.json
Normal file
File diff suppressed because one or more lines are too long
182
leetcode/originData/largest-palindromic-number.json
Normal file
182
leetcode/originData/largest-palindromic-number.json
Normal file
File diff suppressed because one or more lines are too long
180
leetcode/originData/longest-cycle-in-a-graph.json
Normal file
180
leetcode/originData/longest-cycle-in-a-graph.json
Normal file
File diff suppressed because one or more lines are too long
180
leetcode/originData/longest-ideal-subsequence.json
Normal file
180
leetcode/originData/longest-ideal-subsequence.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
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user