1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
程序员小墨 2022-04-24 17:05:32 +08:00
parent 55953eb844
commit f3e61dc093
118 changed files with 23543 additions and 11861 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,62 @@
{
"data": {
"question": {
"questionId": "2376",
"questionFrontendId": "2238",
"categoryTitle": "Database",
"boundTopicId": 1422071,
"title": "Number of Times a Driver Was a Passenger",
"titleSlug": "number-of-times-a-driver-was-a-passenger",
"content": null,
"translatedTitle": null,
"translatedContent": null,
"isPaidOnly": true,
"difficulty": "Medium",
"likes": 0,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
"contributors": [],
"langToValidPlayground": null,
"topicTags": [
{
"name": "Database",
"slug": "database",
"translatedName": "数据库",
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": null,
"stats": "{\"totalAccepted\": \"72\", \"totalSubmission\": \"93\", \"totalAcceptedRaw\": 72, \"totalSubmissionRaw\": 93, \"acRate\": \"77.4%\"}",
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "{\"headers\":{\"Rides\":[\"ride_id\",\"driver_id\",\"passenger_id\"]},\"rows\":{\"Rides\":[[1,7,1],[2,7,2],[3,11,1],[4,11,7],[5,11,7],[6,11,3]]}}",
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Rides (ride_id int, driver_id int, passenger_id int)\"\n ],\n \"mssql\": [\n \"Create table Rides (ride_id int, driver_id int, passenger_id int)\"\n ],\n \"oraclesql\": [\n \"Create table Rides (ride_id int, driver_id int, passenger_id int)\"\n ],\n \"database\": true\n}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [
"Create table If Not Exists Rides (ride_id int, driver_id int, passenger_id int)",
"Truncate table Rides",
"insert into Rides (ride_id, driver_id, passenger_id) values ('1', '7', '1')",
"insert into Rides (ride_id, driver_id, passenger_id) values ('2', '7', '2')",
"insert into Rides (ride_id, driver_id, passenger_id) values ('3', '11', '1')",
"insert into Rides (ride_id, driver_id, passenger_id) values ('4', '11', '7')",
"insert into Rides (ride_id, driver_id, passenger_id) values ('5', '11', '7')",
"insert into Rides (ride_id, driver_id, passenger_id) values ('6', '11', '3')"
],
"enableRunCode": true,
"envInfo": "{\"mysql\":[\"MySQL\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"]}",
"book": null,
"isSubscribed": false,
"isDailyQuestion": false,
"dailyRecordStatus": null,
"editorType": "CKEDITOR",
"ugcQuestionId": null,
"style": "LEETCODE",
"exampleTestcases": "{\"headers\":{\"Rides\":[\"ride_id\",\"driver_id\",\"passenger_id\"]},\"rows\":{\"Rides\":[[1,7,1],[2,7,2],[3,11,1],[4,11,7],[5,11,7],[6,11,3]]}}",
"__typename": "QuestionNode"
}
}
}

View File

@ -0,0 +1,60 @@
{
"data": {
"question": {
"questionId": "2371",
"questionFrontendId": "2230",
"categoryTitle": "Database",
"boundTopicId": 1406223,
"title": "The Users That Are Eligible for Discount",
"titleSlug": "the-users-that-are-eligible-for-discount",
"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\": \"107\", \"totalSubmission\": \"205\", \"totalAcceptedRaw\": 107, \"totalSubmissionRaw\": 205, \"acRate\": \"52.2%\"}",
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "{\"headers\": {\"Purchases\": [\"user_id\", \"time_stamp\", \"amount\"]}, \"startDate\": \"2022-03-08\", \"endDate\": \"2022-03-20\", \"minAmount\": 1000, \"rows\": {\"Purchases\": [[1, \"2022-04-20 09:03:00\", 4416], [2, \"2022-03-19 19:24:02\", 678], [3, \"2022-03-18 12:03:09\", 4523], [3, \"2022-03-30 09:43:42\", 626]]}}",
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Purchases (user_id int, time_stamp datetime, amount int)\"\n ],\n \"mssql\": [\n \"Create table Purchases (user_id int, time_stamp datetime, amount int)\"\n ],\n \"oraclesql\": [\n \"Create table Purchases (user_id int, time_stamp date, amount int)\",\n \"ALTER SESSION SET nls_date_format='YYYY-MM-DD HH24:MI:SS'\"\n ],\n \"database\": true,\n \"manual\": true\n}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [
"Create table If Not Exists Purchases (user_id int, time_stamp datetime, amount int)",
"Truncate table Purchases",
"insert into Purchases (user_id, time_stamp, amount) values ('1', '2022-04-20 09:03:00', '4416')",
"insert into Purchases (user_id, time_stamp, amount) values ('2', '2022-03-19 19:24:02', '678')",
"insert into Purchases (user_id, time_stamp, amount) values ('3', '2022-03-18 12:03:09', '4523')",
"insert into Purchases (user_id, time_stamp, amount) values ('3', '2022-03-30 09:43:42', '626')"
],
"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\": {\"Purchases\": [\"user_id\", \"time_stamp\", \"amount\"]}, \"startDate\": \"2022-03-08\", \"endDate\": \"2022-03-20\", \"minAmount\": 1000, \"rows\": {\"Purchases\": [[1, \"2022-04-20 09:03:00\", 4416], [2, \"2022-03-19 19:24:02\", 678], [3, \"2022-03-18 12:03:09\", 4523], [3, \"2022-03-30 09:43:42\", 626]]}}",
"__typename": "QuestionNode"
}
}
}

View File

@ -0,0 +1,62 @@
{
"data": {
"question": {
"questionId": "2370",
"questionFrontendId": "2228",
"categoryTitle": "Database",
"boundTopicId": 1395841,
"title": "Users With Two Purchases Within Seven Days",
"titleSlug": "users-with-two-purchases-within-seven-days",
"content": null,
"translatedTitle": null,
"translatedContent": null,
"isPaidOnly": true,
"difficulty": "Medium",
"likes": 0,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
"contributors": [],
"langToValidPlayground": null,
"topicTags": [
{
"name": "Database",
"slug": "database",
"translatedName": "数据库",
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": null,
"stats": "{\"totalAccepted\": \"134\", \"totalSubmission\": \"248\", \"totalAcceptedRaw\": 134, \"totalSubmissionRaw\": 248, \"acRate\": \"54.0%\"}",
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "{\"headers\":{\"Purchases\":[\"purchase_id\",\"user_id\",\"purchase_date\"]},\"rows\":{\"Purchases\":[[4,2,\"2022-03-13\"],[1,5,\"2022-02-11\"],[3,7,\"2022-06-19\"],[6,2,\"2022-03-20\"],[5,7,\"2022-06-19\"],[2,2,\"2022-06-08\"]]}}",
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Purchases (purchase_id int, user_id int, purchase_date date)\"\n ],\n \"mssql\": [\n \"Create table Purchases (purchase_id int, user_id int, purchase_date date)\"\n ],\n \"oraclesql\": [\n \"Create table Purchases (purchase_id int, user_id int, purchase_date date)\",\n \"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"\n ],\n \"database\": true\n}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [
"Create table If Not Exists Purchases (purchase_id int, user_id int, purchase_date date)",
"Truncate table Purchases",
"insert into Purchases (purchase_id, user_id, purchase_date) values ('4', '2', '2022-03-13')",
"insert into Purchases (purchase_id, user_id, purchase_date) values ('1', '5', '2022-02-11')",
"insert into Purchases (purchase_id, user_id, purchase_date) values ('3', '7', '2022-06-19')",
"insert into Purchases (purchase_id, user_id, purchase_date) values ('6', '2', '2022-03-20')",
"insert into Purchases (purchase_id, user_id, purchase_date) values ('5', '7', '2022-06-19')",
"insert into Purchases (purchase_id, user_id, purchase_date) values ('2', '2', '2022-06-08')"
],
"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\":{\"Purchases\":[\"purchase_id\",\"user_id\",\"purchase_date\"]},\"rows\":{\"Purchases\":[[4,2,\"2022-03-13\"],[1,5,\"2022-02-11\"],[3,7,\"2022-06-19\"],[6,2,\"2022-03-20\"],[5,7,\"2022-06-19\"],[2,2,\"2022-06-08\"]]}}",
"__typename": "QuestionNode"
}
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

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

View File

@ -0,0 +1,34 @@
<p>给你一个非负整数数组&nbsp;<code>nums</code>&nbsp;和一个整数&nbsp;<code>k</code>&nbsp;。每次操作,你可以选择&nbsp;<code>nums</code>&nbsp;<strong>任一</strong>&nbsp;元素并将它 <strong>增加</strong>&nbsp;<code>1</code>&nbsp;</p>
<p>请你返回 <strong>至多</strong>&nbsp;<code>k</code>&nbsp;次操作后,能得到的<em>&nbsp;</em><code>nums</code>&nbsp;<strong>最大乘积</strong>&nbsp;。由于答案可能很大,请你将答案对&nbsp;<code>10<sup>9</sup> + 7</code>&nbsp;取余后返回。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><b>输入:</b>nums = [0,4], k = 5
<b>输出:</b>20
<b>解释:</b>将第一个数增加 5 次。
得到 nums = [5, 4] ,乘积为 5 * 4 = 20 。
可以证明 20 是能得到的最大乘积,所以我们返回 20 。
存在其他增加 nums 的方法,也能得到最大乘积。
</pre>
<p><strong>示例 2</strong></p>
<pre><b>输入:</b>nums = [6,3,3,2], k = 2
<b>输出:</b>216
<b>解释:</b>将第二个数增加 1 次,将第四个数增加 1 次。
得到 nums = [6, 4, 3, 3] ,乘积为 6 * 4 * 3 * 3 = 216 。
可以证明 216 是能得到的最大乘积,所以我们返回 216 。
存在其他增加 nums 的方法,也能得到最大乘积。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length, k &lt;= 10<sup>5</sup></code></li>
<li><code>0 &lt;= nums[i] &lt;= 10<sup>6</sup></code></li>
</ul>

View File

@ -0,0 +1,26 @@
给你两个整数&nbsp;<code>num1</code><code>num2</code>,返回这两个整数的和。
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>num1 = 12, num2 = 5
<strong>输出:</strong>17
<strong>解释:</strong>num1 是 12num2 是 5 ,它们的和是 12 + 5 = 17 ,因此返回 17 。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>num1 = -10, num2 = 4
<strong>输出:</strong>-6
<strong>解释:</strong>num1 + num2 = -6 ,因此返回 -6 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>-100 &lt;= num1, num2 &lt;= 100</code></li>
</ul>

View File

@ -0,0 +1,31 @@
<p>给你一个整数&nbsp;<code>total</code>&nbsp;,表示你拥有的总钱数。同时给你两个整数&nbsp;<code>cost1</code>&nbsp;<code>cost2</code>&nbsp;,分别表示一支钢笔和一支铅笔的价格。你可以花费你部分或者全部的钱,去买任意数目的两种笔。</p>
<p>请你返回购买钢笔和铅笔的&nbsp;<strong>不同方案数目</strong>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><b>输入:</b>total = 20, cost1 = 10, cost2 = 5
<b>输出:</b>9
<b>解释:</b>一支钢笔的价格为 10 ,一支铅笔的价格为 5 。
- 如果你买 0 支钢笔,那么你可以买 0 1 2 3 或者 4 支铅笔。
- 如果你买 1 支钢笔,那么你可以买 0 1 或者 2 支铅笔。
- 如果你买 2 支钢笔,那么你没法买任何铅笔。
所以买钢笔和铅笔的总方案数为 5 + 3 + 1 = 9 种。
</pre>
<p><strong>示例 2</strong></p>
<pre><b>输入:</b>total = 5, cost1 = 10, cost2 = 10
<b>输出:</b>1
<b>解释:</b>钢笔和铅笔的价格都为 10 ,都比拥有的钱数多,所以你没法购买任何文具。所以只有 1 种方案:买 0 支钢笔和 0 支铅笔。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= total, cost1, cost2 &lt;= 10<sup>6</sup></code></li>
</ul>

View File

@ -0,0 +1,46 @@
欢迎各位勇者来到力扣城,本次试炼主题为「二叉搜索树染色」。
每位勇士面前设有一个**二叉搜索树**的模型,模型的根节点为 `root`,树上的各个节点值均不重复。初始时,所有节点均为蓝色。现在按顺序对这棵二叉树进行若干次操作, `ops[i] = [type, x, y]` 表示第 `i` 次操作为:
+ `type` 等于 0 时,将节点值范围在 `[x, y]` 的节点均染蓝
+ `type` 等于 1 时,将节点值范围在 `[x, y]` 的节点均染红
请返回完成所有染色后,该二叉树中红色节点的数量。
**注意:**
+ 题目保证对于每个操作的 `x`、`y` 值定出现在二叉搜索树节点中
**示例 1**
>输入:`root = [1,null,2,null,3,null,4,null,5], ops = [[1,2,4],[1,1,3],[0,3,5]]`
>
>输出:`2`
>
>解释:
>第 0 次操作,将值为 2、3、4 的节点染红;
>第 1 次操作,将值为 1、2、3 的节点染红;
>第 2 次操作,将值为 3、4、5 的节点染蓝;
>因此,最终值为 1、2 的节点为红色节点,返回数量 2
![image.png](https://pic.leetcode-cn.com/1649833948-arSlXd-image.png){:width=230px}
**示例 2**
>输入:`root = [4,2,7,1,null,5,null,null,null,null,6]`
>`ops = [[0,2,2],[1,1,5],[0,4,5],[1,5,7]]`
>
>输出:`5`
>
>解释:
>第 0 次操作,将值为 2 的节点染蓝;
>第 1 次操作,将值为 1、2、4、5 的节点染红;
>第 2 次操作,将值为 4、5 的节点染蓝;
>第 3 次操作,将值为 5、6、7 的节点染红;
>因此,最终值为 1、2、5、6、7 的节点为红色节点,返回数量 5
![image.png](https://pic.leetcode-cn.com/1649833763-BljEbP-image.png){:width=230px}
**提示:**
+ `1 <= 二叉树节点数量 <= 10^5`
+ `1 <= ops.length <= 10^5`
+ `ops[i].length == 3`
+ `ops[i][0]` 仅为 `0` or `1`
+ `0 <= ops[i][1] <= ops[i][2] <= 10^9`
+ `0 <= 节点值 <= 10^9`

View File

@ -0,0 +1,42 @@
欢迎各位勇者来到力扣城,本次试炼主题为「信物传送」。
本次试炼场地设有若干传送带,`matrix[i][j]` 表示第 `i``j` 列的传送带运作方向,`"^","v","<",">"` 这四种符号分别表示 **上、下、左、右** 四个方向。信物会随传送带的方向移动。勇者**每一次**施法操作,可**临时**变更一处传送带的方向,在物品经过后传送带恢复原方向。
![lcp (2).gif](https://pic.leetcode-cn.com/1649835246-vfupSL-lcp%20\(2\).gif){:width=300px}
通关信物初始位于坐标 `start`处,勇者需要将其移动到坐标 `end` 处,请返回勇者施法操作的最少次数。
**注意:**
- `start``end` 的格式均为 `[i,j]`
**示例 1:**
> 输入:`matrix = [">>v","v^<","<><"], start = [0,1], end = [2,0]`
>
> 输出:`1`
>
> 解释:
> 如上图所示
> 当信物移动到 `[1,1]` 时,勇者施法一次将 `[1,1]` 的传送方向 `^` 从变更为 `<`
> 从而信物移动到 `[1,0]`,后续到达 `end` 位置
> 因此勇者最少需要施法操作 1 次
**示例 2:**
> 输入:`matrix = [">>v",">>v","^<<"], start = [0,0], end = [1,1]`
>
> 输出:`0`
>
> 解释:勇者无需施法,信物将自动传送至 `end` 位置
**示例 3:**
> 输入:`matrix = [">^^>","<^v>","^v^<"], start = [0,0], end = [1,3]`
>
> 输出:`3`
**提示:**
- `matrix` 中仅包含 `'^'、'v'、'<'、'>'`
- `0 < matrix.length <= 100`
- `0 < matrix[i].length <= 100`
- `0 <= start[0],end[0] < matrix.length`
- `0 <= start[1],end[1] < matrix[i].length`

View File

@ -0,0 +1,32 @@
<p>给你一个 <strong>二叉树 </strong>的根结点&nbsp;<code>root</code>,该二叉树由恰好&nbsp;<code>3</code>&nbsp;个结点组成:根结点、左子结点和右子结点。</p>
<p>如果根结点值等于两个子结点值之和,返回&nbsp;<code>true</code>&nbsp;,否则返回<em>&nbsp;</em><code>false</code></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2022/04/08/graph3drawio.png" style="width: 281px; height: 199px;" />
<pre>
<strong>输入:</strong>root = [10,4,6]
<strong>输出:</strong>true
<strong>解释:</strong>根结点、左子结点和右子结点的值分别是 10 、4 和 6 。
由于 10 等于 4 + 6 ,因此返回 true 。
</pre>
<p><strong>示例 2</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2022/04/08/graph3drawio-1.png" style="width: 281px; height: 199px;" />
<pre>
<strong>输入:</strong>root = [5,3,1]
<strong>输出:</strong>false
<strong>解释:</strong>根结点、左子结点和右子结点的值分别是 5 、3 和 1 。
由于 5 不等于 3 + 1 ,因此返回 false 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li>树只包含根结点、左子结点和右子结点</li>
<li><code>-100 &lt;= Node.val &lt;= 100</code></li>
</ul>

View File

@ -0,0 +1,43 @@
欢迎各位勇者来到力扣城,本次试炼主题为「力扣泡泡龙」。
游戏初始状态的泡泡形如二叉树 `root`,每个节点值对应了该泡泡的分值。勇者最多可以击破一个节点泡泡,要求满足:
- 被击破的节点泡泡 **至多** 只有一个子节点泡泡
- 当被击破的节点泡泡有子节点泡泡时,则子节点泡泡将取代被击破泡泡的位置
> 注:即整棵子树泡泡上移
请问在击破一个节点泡泡操作或无击破操作后,二叉泡泡树的最大「层和」是多少。
**注意:**
- 「层和」为同一高度的所有节点的分值之和
**示例 1**
> 输入:`root = [6,0,3,null,8]`
>
> 输出:`11`
>
> 解释:勇者的最佳方案如图所示
>![image.png](https://pic.leetcode-cn.com/1648180809-XSWPLu-image.png){:height="100px"}
**示例 2**
> 输入:`root = [5,6,2,4,null,null,1,3,5]`
>
> 输出:`9`
>
> 解释:勇者击破 6 节点,此时「层和」最大为 3+5+1 = 9
>![image.png](https://pic.leetcode-cn.com/1648180769-TLpYop-image.png){:height="200px"}
**示例 3**
> 输入:`root = [-5,1,7]`
>
> 输出:`8`
>
> 解释:勇者不击破节点,「层和」最大为 1+7 = 8
**提示**
- `2 <= 树中节点个数 <= 10^5`
- `-10000 <= 树中节点的值 <= 10000`

View File

@ -0,0 +1,44 @@
<p>给你一个下标从 <strong>0</strong> 开始的字符串 <code>expression</code> ,格式为 <code>"&lt;num1&gt;+&lt;num2&gt;"</code> ,其中 <code>&lt;num1&gt;</code><code>&lt;num2&gt;</code> 表示正整数。</p>
<p>请你向 <code>expression</code> 中添加一对括号,使得在添加之后, <code>expression</code> 仍然是一个有效的数学表达式,并且计算后可以得到 <strong>最小</strong> 可能值。左括号 <strong>必须</strong> 添加在 <code>'+'</code> 的左侧,而右括号必须添加在 <code>'+'</code> 的右侧。</p>
<p>返回添加一对括号后形成的表达式&nbsp;<code>expression</code> ,且满足<em> </em><code>expression</code><em> </em>计算得到 <strong>最小</strong> 可能值<em></em>如果存在多个答案都能产生相同结果,返回任意一个答案。</p>
<p>生成的输入满足:<code>expression</code> 的原始值和添加满足要求的任一对括号之后 <code>expression</code> 的值,都符合 32-bit 带符号整数范围。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>expression = "247+38"
<strong>输出:</strong>"2(47+38)"
<strong>解释:</strong>表达式计算得到 2 * (47 + 38) = 2 * 85 = 170 。
注意 "2(4)7+38" 不是有效的结果,因为右括号必须添加在 <code>'+' 的右侧。</code>
可以证明 170 是最小可能值。
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>expression = "12+34"
<strong>输出:</strong>"1(2+3)4"
<strong>解释:</strong>表达式计算得到 1 * (2 + 3) * 4 = 1 * 5 * 4 = 20 。
</pre>
<p><strong>示例 3</strong></p>
<pre><strong>输入:</strong>expression = "999+999"
<strong>输出:</strong>"(999+999)"
<strong>解释:</strong>表达式计算得到 999 + 999 = 1998 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>3 &lt;= expression.length &lt;= 10</code></li>
<li><code>expression</code> 仅由数字 <code>'1'</code><code>'9'</code><code>'+'</code> 组成</li>
<li><code>expression</code> 由数字开始和结束</li>
<li><code>expression</code> 恰好仅含有一个 <code>'+'</code>.</li>
<li><code>expression</code> 的原始值和添加满足要求的任一对括号之后 <code>expression</code> 的值,都符合 32-bit 带符号整数范围</li>
</ul>

View File

@ -0,0 +1,31 @@
<p>给你一个二维整数数组 <code>nums</code> ,其中 <code>nums[i]</code> 是由 <strong>不同</strong> 正整数组成的一个非空数组,按 <strong>升序排列</strong> 返回一个数组,数组中的每个元素在 <code>nums</code>&nbsp;<strong>所有数组</strong> 中都出现过。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>nums = [[<em><strong>3</strong></em>,1,2,<em><strong>4</strong></em>,5],[1,2,<em><strong>3</strong></em>,<em><strong>4</strong></em>],[<em><strong>3</strong></em>,<em><strong>4</strong></em>,5,6]]
<strong>输出:</strong>[3,4]
<strong>解释:</strong>
nums[0] = [<em><strong>3</strong></em>,1,2,<em><strong>4</strong></em>,5]nums[1] = [1,2,<em><strong>3</strong></em>,<em><strong>4</strong></em>]nums[2] = [<em><strong>3</strong></em>,<em><strong>4</strong></em>,5,6],在 nums 中每个数组中都出现的数字是 3 和 4 ,所以返回 [3,4] 。</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>nums = [[1,2,3],[4,5,6]]
<strong>输出:</strong>[]
<strong>解释:</strong>
不存在同时出现在 nums[0] 和 nums[1] 的整数,所以返回一个空列表 [] 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 1000</code></li>
<li><code>1 &lt;= sum(nums[i].length) &lt;= 1000</code></li>
<li><code>1 &lt;= nums[i][j] &lt;= 1000</code></li>
<li><code>nums[i]</code> 中的所有值 <strong>互不相同</strong></li>
</ul>

View File

@ -0,0 +1,54 @@
欢迎各位勇者来到力扣城,本次试炼主题为「夺回据点」。
魔物了占领若干据点,这些据点被若干条道路相连接,`roads[i] = [x, y]` 表示编号 `x`、`y` 的两个据点通过一条道路连接。
现在勇者要将按照以下原则将这些据点逐一夺回:
- 在开始的时候,勇者可以花费资源先夺回一些据点,初始夺回第 `j` 个据点所需消耗的资源数量为 `cost[j]`
- 接下来,勇者在不消耗资源情况下,每次可以夺回**一个**和「已夺回据点」相连接的魔物据点,并对其进行夺回
> 注:为了防止魔物暴动,勇者在每一次夺回据点后(包括花费资源夺回据点后),需要保证剩余的所有魔物据点之间是相连通的(不经过「已夺回据点」)。
请返回勇者夺回所有据点需要消耗的最少资源数量。
**注意:**
- 输入保证初始所有据点都是连通的,且不存在重边和自环
**示例 1**
>输入:
>`cost = [1,2,3,4,5,6]`
>`roads = [[0,1],[0,2],[1,3],[2,3],[1,2],[2,4],[2,5]]`
>
>输出:`6`
>
>解释:
>勇者消耗资源 `6` 夺回据点 `0``4`,魔物据点 `1、2、3、5` 相连通;
>第一次夺回据点 `1`,魔物据点 `2、3、5` 相连通;
>第二次夺回据点 `3`,魔物据点 `2、5` 相连通;
>第三次夺回据点 `2`,剩余魔物据点 `5`
>第四次夺回据点 `5`,无剩余魔物据点;
>因此最少需要消耗资源为 `6`,可占领所有据点。
![image.png](https://pic.leetcode-cn.com/1648706944-KJstUN-image.png){:height=170px}
**示例 2**
>输入:
>`cost = [3,2,1,4]`
>`roads = [[0,2],[2,3],[3,1]]`
>
>输出:`2`
>
>解释:
>勇者消耗资源 `2` 夺回据点 `1`,魔物据点 `0、2、3` 相连通;
>第一次夺回据点 `3`,魔物据点 `2、0` 相连通;
>第二次夺回据点 `2`,剩余魔物据点 `0`
>第三次夺回据点 `0`,无剩余魔物据点;
>因此最少需要消耗资源为 `2`,可占领所有据点。
![image.png](https://pic.leetcode-cn.com/1648707186-LJRwzU-image.png){:height=60px}
**提示:**
- `1 <= roads.length, cost.length <= 10^5`
- `0 <= roads[i][0], roads[i][1] < cost.length`
- `1 <= cost[i] <= 10^9`

View File

@ -0,0 +1,42 @@
各位勇者请注意,力扣太空城发布陨石雨红色预警。
太空城中的一些舱室将要受到陨石雨的冲击,这些舱室按照编号 `0 ~ N` 的顺序依次排列。为了阻挡陨石损毁舱室,太空城可以使用能量展开防护屏障,具体消耗如下:
- 选择一个舱室开启屏障,能量消耗为 `2`
- 选择相邻两个舱室开启联合屏障,能量消耗为 `3`
- 对于已开启的**一个**屏障,**多维持一时刻**,能量消耗为 `1`
已知陨石雨的影响范围和到达时刻,`time[i]` 和 `position[i]` 分别表示该陨石的到达时刻和冲击位置。请返回太空舱能够守护所有舱室所需要的最少能量。
**注意:**
- 同一时间,一个舱室不能被多个屏障覆盖
- 陨石雨仅在到达时刻对冲击位置处的舱室有影响
**示例 1**
>输入:`time = [1,2,1], position = [6,3,3]`
>
>输出:`5`
>
>解释:
> 时刻 1分别开启编号 3、6 舱室的屏障,能量消耗 2*2 = 4
> 时刻 2维持编号 3 舱室的屏障,能量消耗 1
> 因此,最少需要能量 5
**示例 2**
>输入:`time = [1,1,1,2,2,3,5], position = [1,2,3,1,2,1,3]`
>
>输出:`9`
>
>解释:
> 时刻 1开启编号 1、2 舱室的联合屏障,能量消耗 3
> 时刻 1开启编号 3 舱室的屏障,能量消耗 2
> 时刻 2维持编号 1、2 舱室的联合屏障,能量消耗 1
> 时刻 3维持编号 1、2 舱室的联合屏障,能量消耗 1
> 时刻 5重新开启编号 3 舱室的联合屏障,能量消耗 2
> 因此,最少需要能量 9
**提示:**
+ `1 <= time.length == position.length <= 500`
+ `1 <= time[i] <= 5`
+ `0 <= position[i] <= 100`

View File

@ -0,0 +1,33 @@
<p>给你一个下标从 <strong>0</strong> 开始的整数数组 <code>tasks</code> ,其中 <code>tasks[i]</code> 表示任务的难度级别。在每一轮中,你可以完成 2 个或者 3 个 <strong>相同难度级别</strong> 的任务。</p>
<p>返回完成所有任务需要的 <strong>最少</strong> 轮数,如果无法完成所有任务,返回<em> </em><code>-1</code><em> </em></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>tasks = [2,2,3,3,2,4,4,4,4,4]
<strong>输出:</strong>4
<strong>解释:</strong>要想完成所有任务,一个可能的计划是:
- 第一轮,完成难度级别为 2 的 3 个任务。
- 第二轮,完成难度级别为 3 的 2 个任务。
- 第三轮,完成难度级别为 4 的 3 个任务。
- 第四轮,完成难度级别为 4 的 2 个任务。
可以证明,无法在少于 4 轮的情况下完成所有任务,所以答案为 4 。
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>tasks = [2,3,3]
<strong>输出:</strong>-1
<strong>解释:</strong>难度级别为 2 的任务只有 1 个,但每一轮执行中,只能选择完成 2 个或者 3 个相同难度级别的任务。因此,无法完成所有任务,答案为 -1 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= tasks.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= tasks[i] &lt;= 10<sup>9</sup></code></li>
</ul>

View File

@ -0,0 +1,43 @@
欢迎各位勇者来到力扣新手村,在开始试炼之前,请各位勇者先进行「宝石补给」。
每位勇者初始都拥有一些能量宝石, `gem[i]` 表示第 `i` 位勇者的宝石数量。现在这些勇者们进行了一系列的赠送,`operations[j] = [x, y]` 表示在第 `j` 次的赠送中 第 `x` 位勇者将自己一半的宝石(需向下取整)赠送给第 `y` 位勇者。
在完成所有的赠送后,请找到拥有**最多**宝石的勇者和拥有**最少**宝石的勇者,并返回他们二者的宝石数量**之差**。
**注意:**
- 赠送将按顺序逐步进行。
**示例 1**
>输入:`gem = [3,1,2], operations = [[0,2],[2,1],[2,0]]`
>
>输出:`2`
>
>解释:
>第 1 次操作,勇者 `0` 将一半的宝石赠送给勇者 `2` `gem = [2,1,3]`
>第 2 次操作,勇者 `2` 将一半的宝石赠送给勇者 `1` `gem = [2,2,2]`
>第 3 次操作,勇者 `2` 将一半的宝石赠送给勇者 `0` `gem = [3,2,1]`
>返回 3 - 1 = 2
**示例 2**
>输入:`gem = [100,0,50,100], operations = [[0,2],[0,1],[3,0],[3,0]]`
>
>输出:`75`
>
>解释:
>第 1 次操作,勇者 `0` 将一半的宝石赠送给勇者 `2` `gem = [50,0,100,100]`
>第 2 次操作,勇者 `0` 将一半的宝石赠送给勇者 `1` `gem = [25,25,100,100]`
>第 3 次操作,勇者 `3` 将一半的宝石赠送给勇者 `0` `gem = [75,25,100,50]`
>第 4 次操作,勇者 `3` 将一半的宝石赠送给勇者 `0` `gem = [100,25,100,25]`
>返回 100 - 25 = 75
**示例 3**
>输入:`gem = [0,0,0,0], operations = [[1,2],[3,1],[1,2]]`
>
>输出:`0`
**提示:**
- `2 <= gem.length <= 10^3`
- `0 <= gem[i] <= 10^3`
- `0 <= operations.length <= 10^4`
- `operations[i].length == 2`
- `0 <= operations[i][0], operations[i][1] < gem.length`

View File

@ -0,0 +1,57 @@
欢迎各位勇者来到力扣城,本次试炼主题为「打地鼠」。
![middle_img_v2_d5d09656-0616-4a80-845e-ece461c5ba9g.png](https://pic.leetcode-cn.com/1650273183-nZIijm-middle_img_v2_d5d09656-0616-4a80-845e-ece461c5ba9g.png){:height="200px"}
勇者面前有一个大小为 `3*3` 的打地鼠游戏机,地鼠将随机出现在各个位置,`moles[i] = [t,x,y]` 表示在第 `t` 秒会有地鼠出现在 `(x,y)` 位置上,并于第 `t+1` 秒该地鼠消失。
勇者有一把可敲打地鼠的锤子,初始时刻(即第 `0` 秒)锤子位于正中间的格子 `(1,1)`,锤子的使用规则如下:
- 锤子每经过 `1` 秒可以往上、下、左、右中的一个方向移动一格,也可以不移动
- 锤子只可敲击所在格子的地鼠,**敲击不耗时**
请返回勇者**最多**能够敲击多少只地鼠。
**注意:**
- 输入用例保证在相同时间相同位置最多仅有一只地鼠
**示例 1**
>输入: `moles = [[1,1,0],[2,0,1],[4,2,2]]`
>
>输出: `2`
>
>解释:
>第 0 秒,锤子位于 (1,1)
>第 1 秒,锤子移动至 (1,0) 并敲击地鼠
>第 2 秒,锤子移动至 (2,0)
>第 3 秒,锤子移动至 (2,1)
>第 4 秒,锤子移动至 (2,2) 并敲击地鼠
>因此勇者最多可敲击 2 只地鼠
**示例 2**
>输入:`moles = [[2,0,2],[5,2,0],[4,1,0],[1,2,1],[3,0,2]]`
>
>输出:`3`
>
>解释:
>第 0 秒,锤子位于 (1,1)
>第 1 秒,锤子移动至 (2,1) 并敲击地鼠
>第 2 秒,锤子移动至 (1,1)
>第 3 秒,锤子移动至 (1,0)
>第 4 秒,锤子在 (1,0) 不移动并敲击地鼠
>第 5 秒,锤子移动至 (2,0) 并敲击地鼠
>因此勇者最多可敲击 3 只地鼠
**示例 3**
>输入:`moles = [[0,1,0],[0,0,1]]`
>
>输出:`0`
>
>解释:
>第 0 秒,锤子初始位于 (1,1),此时并不能敲击 (1,0)、(0,1) 位置处的地鼠
**提示:**
+ `1 <= moles.length <= 10^5`
+ `moles[i].length == 3`
+ `0 <= moles[i][0] <= 10^9`
+ `0 <= moles[i][1], moles[i][2] < 3`

View File

@ -0,0 +1,32 @@
<p>给你一个长度为 <code>n</code>&nbsp;的整数数组&nbsp;<code>nums</code>&nbsp;,请你返回 <code>nums</code>&nbsp;中最 <strong>接近</strong>&nbsp;<code>0</code>&nbsp;的数字。如果有多个答案,请你返回它们中的 <strong>最大值</strong>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><b>输入:</b>nums = [-4,-2,1,4,8]
<b>输出:</b>1
<strong>解释:</strong>
-4 到 0 的距离为 |-4| = 4 。
-2 到 0 的距离为 |-2| = 2 。
1 到 0 的距离为 |1| = 1 。
4 到 0 的距离为 |4| = 4 。
8 到 0 的距离为 |8| = 8 。
所以,数组中距离 0 最近的数字为 1 。
</pre>
<p><strong>示例 2</strong></p>
<pre><b>输入:</b>nums = [2,-1,1]
<b>输出:</b>1
<b>解释:</b>1 和 -1 都是距离 0 最近的数字,所以返回较大值 1 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= n &lt;= 1000</code></li>
<li><code>-10<sup>5</sup> &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
</ul>

View File

@ -0,0 +1,32 @@
<p>给你一个正整数 <code>num</code> 。你可以交换 <code>num</code><strong>奇偶性</strong> 相同的任意两位数字(即,都是奇数或者偶数)。</p>
<p>返回交换 <strong>任意</strong> 次之后 <code>num</code><strong>最大</strong> 可能值<em></em></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>num = 1234
<strong>输出:</strong>3412
<strong>解释:</strong>交换数字 3 和数字 1 ,结果得到 3214 。
交换数字 2 和数字 4 ,结果得到 3412 。
注意,可能存在其他交换序列,但是可以证明 3412 是最大可能值。
注意,不能交换数字 4 和数字 1 ,因为它们奇偶性不同。
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>num = 65875
<strong>输出:</strong>87655
<strong>解释:</strong>交换数字 8 和数字 6 ,结果得到 85675 。
交换数字 5 和数字 7 ,结果得到 87655 。
注意,可能存在其他交换序列,但是可以证明 87655 是最大可能值。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= num &lt;= 10<sup>9</sup></code></li>
</ul>

View File

@ -0,0 +1,43 @@
欢迎各位勇者来到力扣城,本次试炼主题为「搭桥过河」。
勇者面前有一段长度为 `num` 的河流,河流可以划分为若干河道。每条河道上恰有一块浮木,`wood[i]` 记录了第 `i` 条河道上的浮木初始的覆盖范围。
- 当且仅当浮木与相邻河道的浮木覆盖范围有重叠时,勇者才可以在两条浮木间移动
- 勇者 **仅能在岸上** 通过花费一点「自然之力」,使任意一条浮木沿着河流移动一个单位距离
请问勇者跨越这条河流,最少需要花费多少「自然之力」。
**示例 1**
> 输入: `num = 10, wood = [[1,2],[4,7],[8,9]]`
> 输出: `3`
> 解释:如下图所示,
> 将 [1,2] 浮木移动至 [3,4],花费 2「自然之力」
> 将 [8,9] 浮木移动至 [7,8],花费 1「自然之力」
> 此时勇者可以顺着 [3,4]->[4,7]->[7,8] 跨越河流,
> 因此,勇者最少需要花费 3 点「自然之力」跨越这条河流
![wood (2).gif](https://pic.leetcode-cn.com/1648196478-ophADL-wood%20\(2\).gif){:width=650px}
**示例 2**
> 输入: `num = 10, wood = [[1,5],[1,1],[10,10],[6,7],[7,8]]`
> 输出: `10`
> 解释:
> 将 [1,5] 浮木移动至 [2,6],花费 1「自然之力」
> 将 [1,1] 浮木移动至 [6,6],花费 5「自然之力」
> 将 [10,10] 浮木移动至 [6,6],花费 4「自然之力」
> 此时勇者可以顺着 [2,6]->[6,6]->[6,6]->[6,7]->[7,8] 跨越河流,
> 因此,勇者最少需要花费 10 点「自然之力」跨越这条河流
**示例 3**
> 输入: `num = 5, wood = [[1,2],[2,4]]`
> 输出: `0`
> 解释:勇者不需要移动浮木,仍可以跨越这条河流
**提示:**
- `1 <= num <= 10^9`
- `1 <= wood.length <= 10^5`
- `wood[i].length == 2`
- `1 <= wood[i][0] <= wood[i][1] <= num`

View File

@ -0,0 +1,41 @@
欢迎各位勇者来到力扣城,城内设有烹饪锅供勇者制作料理,为自己恢复状态。
勇者背包内共有编号为 `0 ~ 4` 的五种食材,其中 `materials[j]` 表示第 `j` 种食材的数量。通过这些食材可以制作若干料理,`cookbooks[i][j]` 表示制作第 `i` 种料理需要第 `j` 种食材的数量,而 `attribute[i] = [x,y]` 表示第 `i` 道料理的美味度 `x` 和饱腹感 `y`
在饱腹感不小于 `limit` 的情况下,请返回勇者可获得的最大美味度。如果无法满足饱腹感要求,则返回 `-1`
**注意:**
- 每种料理只能制作一次。
**示例 1**
>输入:`materials = [3,2,4,1,2]`
>`cookbooks = [[1,1,0,1,2],[2,1,4,0,0],[3,2,4,1,0]]`
>`attribute = [[3,2],[2,4],[7,6]]`
>`limit = 5`
>
>输出:`7`
>
>解释:
>食材数量可以满足以下两种方案:
>方案一:制作料理 0 和料理 1可获得饱腹感 2+4、美味度 3+2
>方案二:仅制作料理 2 可饱腹感为 6、美味度为 7
>因此在满足饱腹感的要求下,可获得最高美味度 7
**示例 2**
>输入:`materials = [10,10,10,10,10]`
>`cookbooks = [[1,1,1,1,1],[3,3,3,3,3],[10,10,10,10,10]]`
>`attribute = [[5,5],[6,6],[10,10]]`
>`limit = 1`
>
>输出:`11`
>
>解释:通过制作料理 0 和 1可满足饱腹感并获得最高美味度 11
**提示:**
+ `materials.length == 5`
+ `1 <= cookbooks.length == attribute.length <= 8`
+ `cookbooks[i].length == 5`
+ `attribute[i].length == 2`
+ `0 <= materials[i], cookbooks[i][j], attribute[i][j] <= 20`
+ `1 <= limit <= 100`

View File

@ -0,0 +1,41 @@
<p>给你一棵 <strong></strong>(即一个连通、无向、无环图),根节点是节点 <code>0</code> ,这棵树由编号从 <code>0</code><code>n - 1</code><code>n</code> 个节点组成。用下标从 <strong>0</strong> 开始、长度为 <code>n</code> 的数组 <code>parent</code> 来表示这棵树,其中 <code>parent[i]</code> 是节点 <code>i</code> 的父节点,由于节点 <code>0</code> 是根节点,所以 <code>parent[0] == -1</code></p>
<p>另给你一个字符串 <code>s</code> ,长度也是 <code>n</code> ,其中 <code>s[i]</code> 表示分配给节点 <code>i</code> 的字符。</p>
<p>请你找出路径上任意一对相邻节点都没有分配到相同字符的 <strong>最长路径</strong> ,并返回该路径的长度。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/03/25/testingdrawio.png" style="width: 201px; height: 241px;" /></p>
<pre>
<strong>输入:</strong>parent = [-1,0,0,1,1,2], s = "abacbe"
<strong>输出:</strong>3
<strong>解释:</strong>任意一对相邻节点字符都不同的最长路径是0 -&gt; 1 -&gt; 3 。该路径的长度是 3 ,所以返回 3 。
可以证明不存在满足上述条件且比 3 更长的路径。
</pre>
<p><strong>示例 2</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/03/25/graph2drawio.png" style="width: 201px; height: 221px;" /></p>
<pre>
<strong>输入:</strong>parent = [-1,0,0,0], s = "aabc"
<strong>输出:</strong>3
<strong>解释:</strong>任意一对相邻节点字符都不同的最长路径是2 -&gt; 0 -&gt; 3 。该路径的长度为 3 ,所以返回 3 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>n == parent.length == s.length</code></li>
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
<li>对所有 <code>i &gt;= 1</code> <code>0 &lt;= parent[i] &lt;= n - 1</code> 均成立</li>
<li><code>parent[0] == -1</code></li>
<li><code>parent</code> 表示一棵有效的树</li>
<li><code>s</code> 仅由小写英文字母组成</li>
</ul>

View File

@ -0,0 +1,47 @@
欢迎各位勇者来到力扣城,本次试炼主题为「积木拼接」。
勇者面前有 `6` 片积木(厚度均为 1每片积木的形状记录于二维字符串数组 `shapes` 中,`shapes[i]` 表示第 `i` 片积木,其中 `1` 表示积木对应位置无空缺,`0` 表示积木对应位置有空缺。
例如 `["010","111","010"]` 对应积木形状为
![image.png](https://pic.leetcode-cn.com/1616125620-nXMCxX-image.png)
拼接积木的规则如下:
- 积木片可以旋转、翻面
- 积木片边缘必须完全吻合才能拼接在一起
- **每片积木片 `shapes[i]` 的中心点在拼接时必须处于正方体对应面的中心点**
例如 `3*3`、`4*4` 的积木片的中心点如图所示(红色点):
![middle_img_v2_c2d91eb5-9beb-4c06-9726-f7dae149d86g.png](https://pic.leetcode-cn.com/1650509082-wObiEp-middle_img_v2_c2d91eb5-9beb-4c06-9726-f7dae149d86g.png){:height="150px"}
请返回这 6 片积木能否拼接成一个**严丝合缝的正方体**且每片积木正好对应正方体的一个面。
**注意:**
- 输入确保每片积木均无空心情况(即输入数据保证对于大小 `N*N``shapes[i]`,内部的 `(N-2)*(N-2)` 的区域必然均为 1
- 输入确保每片积木的所有 `1` 位置均连通
**示例 1**
>输入:`shapes = [["000","110","000"],["110","011","000"],["110","011","110"],["000","010","111"],["011","111","011"],["011","010","000"]]`
>
>输出:`true`
>
>解释:
![cube.gif](https://pic.leetcode-cn.com/1616125823-hkXAeN-cube.gif)
**示例 2**
>输入:`shapes = [["101","111","000"],["000","010","111"],["010","011","000"],["010","111","010"],["101","111","010"],["000","010","011"]]`
>
>输出:`false`
>
>解释:
>由于每片积木片的中心点在拼接时必须处于正方体对应面的中心点,积木片 `["010","011","000"]` 不能作为 `["100","110","000"]` 使用,因此无法构成正方体
**提示:**
- `shapes.length == 6`
- `shapes[i].length == shapes[j].length`
- `shapes[i].length == shapes[i][j].length`
- `3 <= shapes[i].length <= 10`

View File

@ -0,0 +1,52 @@
<p>给你一个二维整数数组&nbsp;<code>rectangles</code>&nbsp;,其中&nbsp;<code>rectangles[i] = [l<sub>i</sub>, h<sub>i</sub>]</code>&nbsp;表示第&nbsp;<code>i</code>&nbsp;个矩形长为&nbsp;<code>l<sub>i</sub></code>&nbsp;高为&nbsp;<code>h<sub>i</sub></code>&nbsp;。给你一个二维整数数组&nbsp;<code>points</code>&nbsp;,其中&nbsp;<code>points[j] = [x<sub>j</sub>, y<sub>j</sub>]</code>&nbsp;是坐标为&nbsp;<code>(x<sub>j</sub>, y<sub>j</sub>)</code>&nbsp;的一个点。</p>
<p>&nbsp;<code>i</code>&nbsp;个矩形的 <strong>左下角</strong>&nbsp;&nbsp;<code>(0, 0)</code>&nbsp;处,<strong>右上角</strong>&nbsp;&nbsp;<code>(l<sub>i</sub>, h<sub>i</sub>)</code>&nbsp;</p>
<p>请你返回一个整数数组<em>&nbsp;</em><code>count</code>&nbsp;,长度为&nbsp;<code>points.length</code>,其中<em>&nbsp;</em><code>count[j]</code><strong>包含</strong><em>&nbsp;</em><code>j</code>&nbsp;个点的矩形数目。</p>
<p>如果&nbsp;<code>0 &lt;= x<sub>j</sub> &lt;= l<sub>i</sub></code>&nbsp;<code>0 &lt;= y<sub>j</sub> &lt;= h<sub>i</sub></code>&nbsp;,那么我们说第&nbsp;<code>i</code>&nbsp;个矩形包含第&nbsp;<code>j</code>&nbsp;个点。如果一个点刚好在矩形的 <strong>边上</strong>&nbsp;,这个点也被视为被矩形包含。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/03/02/example1.png" style="width: 300px; height: 509px;"></p>
<pre><b>输入:</b>rectangles = [[1,2],[2,3],[2,5]], points = [[2,1],[1,4]]
<b>输出:</b>[2,1]
<b>解释:</b>
第一个矩形不包含任何点。
第二个矩形只包含一个点 (2, 1) 。
第三个矩形包含点 (2, 1) 和 (1, 4) 。
包含点 (2, 1) 的矩形数目为 2 。
包含点 (1, 4) 的矩形数目为 1 。
所以,我们返回 [2, 1] 。
</pre>
<p><strong>示例 2</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/03/02/example2.png" style="width: 300px; height: 312px;"></p>
<pre><b>输入:</b>rectangles = [[1,1],[2,2],[3,3]], points = [[1,3],[1,1]]
<b>输出:</b>[1,3]
<strong>解释:
</strong>第一个矩形只包含点 (1, 1) 。
第二个矩形只包含点 (1, 1) 。
第三个矩形包含点 (1, 3) 和 (1, 1) 。
包含点 (1, 3) 的矩形数目为 1 。
包含点 (1, 1) 的矩形数目为 3 。
所以,我们返回 [1, 3] 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= rectangles.length, points.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>rectangles[i].length == points[j].length == 2</code></li>
<li><code>1 &lt;= l<sub>i</sub>, x<sub>j</sub> &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= h<sub>i</sub>, y<sub>j</sub> &lt;= 100</code></li>
<li>所有&nbsp;<code>rectangles</code>&nbsp;<strong>互不相同</strong>&nbsp;</li>
<li>所有&nbsp;<code>points</code> <strong>互不相同</strong>&nbsp;</li>
</ul>

View File

@ -0,0 +1,47 @@
<p>给你一个二维整数数组 <code>circles</code> ,其中 <code>circles[i] = [x<sub>i</sub>, y<sub>i</sub>, r<sub>i</sub>]</code> 表示网格上圆心为 <code>(x<sub>i</sub>, y<sub>i</sub>)</code> 且半径为 <code>r<sub>i</sub></code> 的第 <code>i</code> 个圆,返回出现在<strong> 至少一个 </strong>圆内的 <strong>格点数目</strong></p>
<p><strong>注意:</strong></p>
<ul>
<li><strong>格点</strong> 是指整数坐标对应的点。</li>
<li><strong>圆周上的点</strong> 也被视为出现在圆内的点。</li>
</ul>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/03/02/exa-11.png" style="width: 300px; height: 300px;" /></p>
<pre>
<strong>输入:</strong>circles = [[2,2,1]]
<strong>输出:</strong>5
<strong>解释:</strong>
给定的圆如上图所示。
出现在圆内的格点为 (1, 2)、(2, 1)、(2, 2)、(2, 3) 和 (3, 2),在图中用绿色标识。
像 (1, 1) 和 (1, 3) 这样用红色标识的点,并未出现在圆内。
因此,出现在至少一个圆内的格点数目是 5 。</pre>
<p><strong>示例 2</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/03/02/exa-22.png" style="width: 300px; height: 300px;" /></p>
<pre>
<strong>输入:</strong>circles = [[2,2,2],[3,4,1]]
<strong>输出:</strong>16
<strong>解释:</strong>
给定的圆如上图所示。
共有 16 个格点出现在至少一个圆内。
其中部分点的坐标是 (0, 2)、(2, 0)、(2, 4)、(3, 2) 和 (4, 4) 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= circles.length &lt;= 200</code></li>
<li><code>circles[i].length == 3</code></li>
<li><code>1 &lt;= x<sub>i</sub>, y<sub>i</sub> &lt;= 100</code></li>
<li><code>1 &lt;= r<sub>i</sub> &lt;= min(x<sub>i</sub>, y<sub>i</sub>)</code></li>
</ul>

View File

@ -0,0 +1,56 @@
<p>给你一个&nbsp;<code>n</code>&nbsp;个节点的&nbsp;<strong>无向图</strong>&nbsp;,节点编号为&nbsp;<code>0</code>&nbsp;&nbsp;<code>n - 1</code>&nbsp;</p>
<p>给你一个下标从 <strong>0</strong>&nbsp;开始的整数数组&nbsp;<code>scores</code>&nbsp;,其中&nbsp;<code>scores[i]</code>&nbsp;是第 <code>i</code>&nbsp;个节点的分数。同时给你一个二维整数数组&nbsp;<code>edges</code>&nbsp;,其中&nbsp;<code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>]</code>&nbsp;,表示节点&nbsp;<code>a<sub>i</sub></code>&nbsp;<code>b<sub>i</sub></code>&nbsp;之间有一条&nbsp;<strong>无向</strong>&nbsp;边。</p>
<p>一个合法的节点序列如果满足以下条件,我们称它是 <strong>合法的</strong>&nbsp;</p>
<ul>
<li>序列中每&nbsp;<b>相邻</b>&nbsp;节点之间有边相连。</li>
<li>序列中没有节点出现超过一次。</li>
</ul>
<p>节点序列的分数定义为序列中节点分数之 <strong></strong></p>
<p>请你返回一个长度为 <code>4</code>&nbsp;的合法节点序列的最大分数。如果不存在这样的序列,请你返回 <code>-1</code>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/04/15/ex1new3.png" style="width: 290px; height: 215px;" /></p>
<pre>
<b>输入:</b>scores = [5,2,9,8,4], edges = [[0,1],[1,2],[2,3],[0,2],[1,3],[2,4]]
<b>输出:</b>24
<b>解释:</b>上图为输入的图,节点序列为 [0,1,2,3] 。
节点序列的分数为 5 + 2 + 9 + 8 = 24 。
观察可知,没有其他节点序列得分和超过 24 。
注意节点序列 [3,1,2,0] 和 [1,0,2,3] 也是合法的,且分数为 24 。
序列 [0,3,2,4] 不是合法的,因为没有边连接节点 0 和 3 。
</pre>
<p><strong>示例 2</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/03/17/ex2.png" style="width: 333px; height: 151px;" /></p>
<pre>
<b>输入:</b>scores = [9,20,6,4,11,12], edges = [[0,3],[5,3],[2,4],[1,3]]
<b>输出:</b>-1
<b>解释:</b>上图为输入的图。
没有长度为 4 的合法序列,所以我们返回 -1 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>n == scores.length</code></li>
<li><code>4 &lt;= n &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>1 &lt;= scores[i] &lt;= 10<sup>8</sup></code></li>
<li><code>0 &lt;= edges.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>edges[i].length == 2</code></li>
<li><code>0 &lt;= a<sub>i</sub>, b<sub>i</sub> &lt;= n - 1</code></li>
<li><code>a<sub>i</sub> != b<sub>i</sub></code></li>
<li>不会有重边。</li>
</ul>

View File

@ -0,0 +1,58 @@
<p>Alice 是&nbsp;<code>n</code>&nbsp;个花园的园丁,她想通过种花,最大化她所有花园的总美丽值。</p>
<p>给你一个下标从 <strong>0</strong>&nbsp;开始大小为 <code>n</code>&nbsp;的整数数组&nbsp;<code>flowers</code>&nbsp;,其中&nbsp;<code>flowers[i]</code>&nbsp;是第 <code>i</code>&nbsp;个花园里已经种的花的数目。已经种了的花 <strong>不能</strong>&nbsp;移走。同时给你&nbsp;<code>newFlowers</code>&nbsp;,表示 Alice 额外可以种花的&nbsp;<strong>最大数目</strong>&nbsp;。同时给你的还有整数&nbsp;<code>target</code>&nbsp;<code>full</code>&nbsp;&nbsp;<code>partial</code>&nbsp;</p>
<p>如果一个花园有 <strong>至少</strong>&nbsp;<code>target</code>&nbsp;朵花,那么这个花园称为 <strong>完善的</strong>&nbsp;,花园的 <strong>总美丽值</strong>&nbsp;为以下分数之 <strong></strong> </p>
<ul>
<li><b>完善</b> 花园数目乘以&nbsp;<code>full</code>.</li>
<li>剩余 <strong>不完善</strong>&nbsp;花园里,花的 <strong>最少数目</strong>&nbsp;乘以&nbsp;<code>partial</code>&nbsp;。如果没有不完善花园,那么这一部分的值为&nbsp;<code>0</code>&nbsp;</li>
</ul>
<p>请你返回 Alice 种最多 <code>newFlowers</code>&nbsp;朵花以后,能得到的<strong>&nbsp;最大</strong>&nbsp;总美丽值。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><b>输入:</b>flowers = [1,3,1,1], newFlowers = 7, target = 6, full = 12, partial = 1
<b>输出:</b>14
<b>解释:</b>Alice 可以按以下方案种花
- 在第 0 个花园种 2 朵花
- 在第 1 个花园种 3 朵花
- 在第 2 个花园种 1 朵花
- 在第 3 个花园种 1 朵花
花园里花的数目为 [3,6,2,2] 。总共种了 2 + 3 + 1 + 1 = 7 朵花。
只有 1 个花园是完善的。
不完善花园里花的最少数目是 2 。
所以总美丽值为 1 * 12 + 2 * 1 = 12 + 2 = 14 。
没有其他方案可以让花园总美丽值超过 14 。
</pre>
<p><strong>示例 2</strong></p>
<pre><b>输入:</b>flowers = [2,4,5,3], newFlowers = 10, target = 5, full = 2, partial = 6
<b>输出:</b>30
<b>解释:</b>Alice 可以按以下方案种花
- 在第 0 个花园种 3 朵花
- 在第 1 个花园种 0 朵花
- 在第 2 个花园种 0 朵花
- 在第 3 个花园种 2 朵花
花园里花的数目为 [5,4,5,5] 。总共种了 3 + 0 + 0 + 2 = 5 朵花。
有 3 个花园是完善的。
不完善花园里花的最少数目为 4 。
所以总美丽值为 3 * 2 + 4 * 6 = 6 + 24 = 30 。
没有其他方案可以让花园总美丽值超过 30 。
注意Alice可以让所有花园都变成完善的但这样她的总美丽值反而更小。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= flowers.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= flowers[i], target &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= newFlowers &lt;= 10<sup>10</sup></code></li>
<li><code>1 &lt;= full, partial &lt;= 10<sup>5</sup></code></li>
</ul>

View File

@ -0,0 +1,37 @@
<p>给你一个下标从 <strong>0</strong>&nbsp;开始的二维整数数组&nbsp;<code>flowers</code>&nbsp;,其中&nbsp;<code>flowers[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>&nbsp;表示第&nbsp;<code>i</code>&nbsp;朵花的 <strong>花期</strong>&nbsp;&nbsp;<code>start<sub>i</sub></code>&nbsp;&nbsp;<code>end<sub>i</sub></code>&nbsp;(都 <strong>包含</strong>)。同时给你一个下标从 <strong>0</strong>&nbsp;开始大小为 <code>n</code>&nbsp;的整数数组&nbsp;<code>persons</code>&nbsp;<code>persons[i]</code>&nbsp;是第&nbsp;<code>i</code>&nbsp;个人来看花的时间。</p>
<p>请你返回一个大小为 <code>n</code>&nbsp;的整数数组<em>&nbsp;</em><code>answer</code>&nbsp;,其中&nbsp;<code>answer[i]</code>是第&nbsp;<code>i</code>&nbsp;个人到达时在花期内花的&nbsp;<strong>数目</strong>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/03/02/ex1new.jpg" style="width: 550px; height: 216px;"></p>
<pre><b>输入:</b>flowers = [[1,6],[3,7],[9,12],[4,13]], persons = [2,3,7,11]
<b>输出:</b>[1,2,2,2]
<strong>解释:</strong>上图展示了每朵花的花期时间,和每个人的到达时间。
对每个人,我们返回他们到达时在花期内花的数目。
</pre>
<p><strong>示例 2</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/03/02/ex2new.jpg" style="width: 450px; height: 195px;"></p>
<pre><b>输入:</b>flowers = [[1,10],[3,3]], persons = [3,3,2]
<b>输出:</b>[2,2,1]
<b>解释:</b>上图展示了每朵花的花期时间,和每个人的到达时间。
对每个人,我们返回他们到达时在花期内花的数目。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= flowers.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>flowers[i].length == 2</code></li>
<li><code>1 &lt;= start<sub>i</sub> &lt;= end<sub>i</sub> &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= persons.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>1 &lt;= persons[i] &lt;= 10<sup>9</sup></code></li>
</ul>

View File

@ -0,0 +1,47 @@
<p>给你一个由若干数字(<code>0</code> - <code>9</code>)组成的字符串 <code>s</code> ,和一个整数。</p>
<p>如果 <code>s</code> 的长度大于 <code>k</code> ,则可以执行一轮操作。在一轮操作中,需要完成以下工作:</p>
<ol>
<li><code>s</code> <strong>拆分 </strong>成长度为 <code>k</code> 的若干 <strong>连续数字组</strong> ,使得前 <code>k</code> 个字符都分在第一组,接下来的 <code>k</code> 个字符都分在第二组,依此类推。<strong>注意</strong>,最后一个数字组的长度可以小于 <code>k</code></li>
<li>用表示每个数字组中所有数字之和的字符串来 <strong>替换</strong> 对应的数字组。例如,<code>"346"</code> 会替换为 <code>"13"</code> ,因为 <code>3 + 4 + 6 = 13</code></li>
<li><strong>合并</strong> 所有组以形成一个新字符串。如果新字符串的长度大于 <code>k</code> 则重复第一步。</li>
</ol>
<p>返回在完成所有轮操作后的 <code>s</code></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>s = "11111222223", k = 3
<strong>输出:</strong>"135"
<strong>解释:</strong>
- 第一轮,将 s 分成:"111"、"112"、"222" 和 "23" 。
接着计算每一组的数字和1 + 1 + 1 = 3、1 + 1 + 2 = 4、2 + 2 + 2 = 6 和 2 + 3 = 5 。
&nbsp; 这样s 在第一轮之后变成 "3" + "4" + "6" + "5" = "3465" 。
- 第二轮,将 s 分成:"346" 和 "5" 。
&nbsp; 接着计算每一组的数字和3 + 4 + 6 = 13 、5 = 5 。
&nbsp; 这样s 在第二轮之后变成 "13" + "5" = "135" 。
现在s.length &lt;= k ,所以返回 "135" 作为答案。
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>s = "00000000", k = 3
<strong>输出:</strong>"000"
<strong>解释:</strong>
将 "000", "000", and "00".
接着计算每一组的数字和0 + 0 + 0 = 0 、0 + 0 + 0 = 0 和 0 + 0 = 0 。
s 变为 "0" + "0" + "0" = "000" ,其长度等于 k ,所以返回 "000" 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 100</code></li>
<li><code>2 &lt;= k &lt;= 100</code></li>
<li><code>s</code> 仅由数字(<code>0</code> - <code>9</code>)组成。</li>
</ul>

View File

@ -0,0 +1,49 @@
<p>一个 ATM 机器,存有&nbsp;<code>5</code>&nbsp;种面值的钞票:<code>20</code>&nbsp;<code>50</code>&nbsp;<code>100</code>&nbsp;<code>200</code>&nbsp;&nbsp;<code>500</code>&nbsp;美元。初始时ATM 机是空的。用户可以用它存或者取任意数目的钱。</p>
<p>取款时,机器会优先取 <b>较大</b>&nbsp;数额的钱。</p>
<ul>
<li>比方说,你想取&nbsp;<code>$300</code>&nbsp;,并且机器里有&nbsp;<code>2</code>&nbsp;<code>$50</code>&nbsp;的钞票,<code>1</code>&nbsp;&nbsp;<code>$100</code>&nbsp;的钞票和<code>1</code>&nbsp;&nbsp;<code>$200</code>&nbsp;的钞票,那么机器会取出&nbsp;<code>$100</code>&nbsp;<code>$200</code>&nbsp;的钞票。</li>
<li>但是,如果你想取&nbsp;<code>$600</code>&nbsp;,机器里有&nbsp;<code>3</code>&nbsp;&nbsp;<code>$200</code>&nbsp;的钞票和<code>1</code>&nbsp;&nbsp;<code>$500</code>&nbsp;的钞票,那么取款请求会被拒绝,因为机器会先取出&nbsp;<code>$500</code>&nbsp;的钞票,然后无法取出剩余的&nbsp;<code>$100</code>&nbsp;。注意,因为有&nbsp;<code>$500</code>&nbsp;钞票的存在,机器&nbsp;<strong>不能</strong>&nbsp;&nbsp;<code>$200</code>&nbsp;的钞票。</li>
</ul>
<p>请你实现 ATM 类:</p>
<ul>
<li><code>ATM()</code>&nbsp;初始化 ATM 对象。</li>
<li><code>void deposit(int[] banknotesCount)</code>&nbsp;分别存入&nbsp;<code>$20</code>&nbsp;<code>$50</code><code>$100</code><code>$200</code>&nbsp;&nbsp;<code>$500</code>&nbsp;钞票的数目。</li>
<li><code>int[] withdraw(int amount)</code>&nbsp;返回一个长度为&nbsp;<code>5</code>&nbsp;的数组,分别表示&nbsp;<code>$20</code>&nbsp;<code>$50</code><code>$100</code>&nbsp;<code>$200</code>&nbsp;&nbsp;<code>$500</code>&nbsp;钞票的数目,并且更新 ATM 机里取款后钞票的剩余数量。如果无法取出指定数额的钱,请返回&nbsp;<code>[-1]</code>&nbsp;(这种情况下 <strong></strong>&nbsp;取出任何钞票)。</li>
</ul>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>
["ATM", "deposit", "withdraw", "deposit", "withdraw", "withdraw"]
[[], [[0,0,1,2,1]], [600], [[0,1,0,1,1]], [600], [550]]
<strong>输出:</strong>
[null, null, [0,0,1,0,1], null, [-1], [0,1,0,0,1]]
<strong>解释:</strong>
ATM atm = new ATM();
atm.deposit([0,0,1,2,1]); // 存入 1 张 $100 2 张 $200 和 1 张 $500 的钞票。
atm.withdraw(600); // 返回 [0,0,1,0,1] 。机器返回 1 张 $100 和 1 张 $500 的钞票。机器里剩余钞票的数量为 [0,0,0,2,0] 。
atm.deposit([0,1,0,1,1]); // 存入 1 张 $50 1 张 $200 和 1 张 $500 的钞票。
// 机器中剩余钞票数量为 [0,1,0,3,1] 。
atm.withdraw(600); // 返回 [-1] 。机器会尝试取出 $500 的钞票,然后无法得到剩余的 $100 ,所以取款请求会被拒绝。
// 由于请求被拒绝,机器中钞票的数量不会发生改变。
atm.withdraw(550); // 返回 [0,1,0,0,1] ,机器会返回 1 张 $50 的钞票和 1 张 $500 的钞票。</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>banknotesCount.length == 5</code></li>
<li><code>0 &lt;= banknotesCount[i] &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= amount &lt;= 10<sup>9</sup></code></li>
<li><strong>总共</strong>&nbsp;最多有&nbsp;<code>5000</code>&nbsp;&nbsp;<code>withdraw</code>&nbsp;<code>deposit</code>&nbsp;的调用。</li>
<li><span style="">函数 </span><code>withdraw</code>&nbsp;<code>deposit</code>&nbsp;至少各有 <strong>一次&nbsp;</strong>调用。</li>
</ul>

View File

@ -0,0 +1,54 @@
<p>给你一个二维整数数组 <code>grid</code> ,大小为 <code>m x n</code>,其中每个单元格都含一个正整数。</p>
<p><strong>转角路径</strong> 定义为:包含至多一个弯的一组相邻单元。具体而言,路径应该完全 <strong>向水平方向</strong> 或者 <strong>向竖直方向</strong> 移动过弯(如果存在弯),而不能访问之前访问过的单元格。在过弯之后,路径应当完全朝 <strong>另一个</strong> 方向行进:如果之前是向水平方向,那么就应该变为向竖直方向;反之亦然。当然,同样不能访问之前已经访问过的单元格。</p>
<p>一条路径的 <strong>乘积</strong> 定义为:路径上所有值的乘积。</p>
<p>请你从 <code>grid</code> 中找出一条乘积中尾随零数目最多的转角路径,并返回该路径中尾随零的数目。</p>
<p>注意:</p>
<ul>
<li><strong>水平</strong> 移动是指向左或右移动。</li>
<li><strong>竖直 </strong>移动是指向上或下移动。</li>
</ul>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/03/23/ex1new2.jpg" style="width: 577px; height: 190px;" /></p>
<pre>
<strong>输入:</strong>grid = [[23,17,15,3,20],[8,1,20,27,11],[9,4,6,2,21],[40,9,1,10,6],[22,7,4,5,3]]
<strong>输出:</strong>3
<strong>解释:</strong>左侧的图展示了一条有效的转角路径。
其乘积为 15 * 20 * 6 * 1 * 10 = 18000 ,共计 3 个尾随零。
可以证明在这条转角路径的乘积中尾随零数目最多。
中间的图不是一条有效的转角路径,因为它有不止一个弯。
右侧的图也不是一条有效的转角路径,因为它需要重复访问已经访问过的单元格。
</pre>
<p><strong>示例 2</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/03/25/ex2.jpg" style="width: 150px; height: 157px;" /></p>
<pre>
<strong>输入:</strong>grid = [[4,3,2],[7,6,1],[8,8,8]]
<strong>输出:</strong>0
<strong>解释:</strong>网格如上图所示。
不存在乘积含尾随零的转角路径。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>m == grid.length</code></li>
<li><code>n == grid[i].length</code></li>
<li><code>1 &lt;= m, n &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= m * n &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= grid[i][j] &lt;= 1000</code></li>
</ul>

View File

@ -0,0 +1,42 @@
欢迎各位勇者来到力扣新手村,本次训练内容为「采集果实」。
在新手村中,各位勇者需要采集一些果实来制作药剂。`time[i]` 表示勇者每次采集 `1limit` 颗第 `i` 种类型的果实需要的时间(即每次最多可以采集 `limit` 颗果实)。
当前勇者需要完成「采集若干批果实」的任务, `fruits[j] = [type, num]` 表示第 `j` 批需要采集 `num``type` 类型的果实。采集规则如下:
- 按 `fruits` 给定的顺序**依次**采集每一批次
- 采集完当前批次的果实才能开始采集下一批次
- 勇者完成当前批次的采集后将**清空背包**(即多余的果实将清空)
请计算并返回勇者完成采集任务最少需要的时间。
**示例 1**
>输入:`time = [2,3,2], fruits = [[0,2],[1,4],[2,1]], limit = 3`
>
>输出:`10`
>
>解释:
>由于单次最多采集 3 颗
>第 0 批需要采集 2 颗第 0 类型果实,需要采集 1 次,耗时为 2\*1=2
>第 1 批需要采集 4 颗第 1 类型果实,需要采集 2 次,耗时为 3\*2=6
>第 2 批需要采集 1 颗第 2 类型果实,需要采集 1 次,耗时为 2\*1=2
>返回总耗时 2+6+2=10
**示例 2**
>输入:`time = [1], fruits = [[0,3],[0,5]], limit = 2`
>
>输出:`5`
>
>解释:
>由于单次最多采集 2 颗
>第 0 批需要采集 3 颗第 0 类型果实,需要采集 2 次,耗时为 1\*2=2
>第 1 批需要采集 5 颗第 0 类型果实,需要采集 3 次,耗时为 1\*3=3
>需按照顺序依次采集,返回 2+3=5
**提示:**
- `1 <= time.length <= 100`
- `1 <= time[i] <= 100`
- `1 <= fruits.length <= 10^3`
- `0 <= fruits[i][0] < time.length`
- `1 <= fruits[i][1] < 10^3`
- `1 <= limit <= 100`

View File

@ -0,0 +1,34 @@
<p>You are given an array of non-negative integers <code>nums</code> and an integer <code>k</code>. In one operation, you may choose <strong>any</strong> element from <code>nums</code> and <strong>increment</strong> it by <code>1</code>.</p>
<p>Return<em> the <strong>maximum</strong> <strong>product</strong> of </em><code>nums</code><em> after <strong>at most</strong> </em><code>k</code><em> operations. </em>Since the answer may be very large, return it <b>modulo</b> <code>10<sup>9</sup> + 7</code>. Note that you should maximize the product before taking the modulo.&nbsp;</p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [0,4], k = 5
<strong>Output:</strong> 20
<strong>Explanation:</strong> Increment the first number 5 times.
Now nums = [5, 4], with a product of 5 * 4 = 20.
It can be shown that 20 is maximum product possible, so we return 20.
Note that there may be other ways to increment nums to have the maximum product.
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> nums = [6,3,3,2], k = 2
<strong>Output:</strong> 216
<strong>Explanation:</strong> Increment the second number 1 time and increment the fourth number 1 time.
Now nums = [6, 4, 3, 3], with a product of 6 * 4 * 3 * 3 = 216.
It can be shown that 216 is maximum product possible, so we return 216.
Note that there may be other ways to increment nums to have the maximum product.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= nums.length, k &lt;= 10<sup>5</sup></code></li>
<li><code>0 &lt;= nums[i] &lt;= 10<sup>6</sup></code></li>
</ul>

View File

@ -0,0 +1,24 @@
Given two integers <code>num1</code> and <code>num2</code>, return <em>the <strong>sum</strong> of the two integers</em>.
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> num1 = 12, num2 = 5
<strong>Output:</strong> 17
<strong>Explanation:</strong> num1 is 12, num2 is 5, and their sum is 12 + 5 = 17, so 17 is returned.
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> num1 = -10, num2 = 4
<strong>Output:</strong> -6
<strong>Explanation:</strong> num1 + num2 = -6, so -6 is returned.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>-100 &lt;= num1, num2 &lt;= 100</code></li>
</ul>

View File

@ -0,0 +1,31 @@
<p>You are given an integer <code>total</code> indicating the amount of money you have. You are also given two integers <code>cost1</code> and <code>cost2</code> indicating the price of a pen and pencil respectively. You can spend <strong>part or all</strong> of your money to buy multiple quantities (or none) of each kind of writing utensil.</p>
<p>Return <em>the <strong>number of distinct ways</strong> you can buy some number of pens and pencils.</em></p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> total = 20, cost1 = 10, cost2 = 5
<strong>Output:</strong> 9
<strong>Explanation:</strong> The price of a pen is 10 and the price of a pencil is 5.
- If you buy 0 pens, you can buy 0, 1, 2, 3, or 4 pencils.
- If you buy 1 pen, you can buy 0, 1, or 2 pencils.
- If you buy 2 pens, you cannot buy any pencils.
The total number of ways to buy pens and pencils is 5 + 3 + 1 = 9.
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> total = 5, cost1 = 10, cost2 = 10
<strong>Output:</strong> 1
<strong>Explanation:</strong> The price of both pens and pencils are 10, which cost more than total, so you cannot buy any writing utensils. Therefore, there is only 1 way: buy 0 pens and 0 pencils.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= total, cost1, cost2 &lt;= 10<sup>6</sup></code></li>
</ul>

View File

@ -0,0 +1,30 @@
<p>You are given the <code>root</code> of a <strong>binary tree</strong> that consists of exactly <code>3</code> nodes: the root, its left child, and its right child.</p>
<p>Return <code>true</code> <em>if the value of the root is equal to the <strong>sum</strong> of the values of its two children, or </em><code>false</code><em> otherwise</em>.</p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2022/04/08/graph3drawio.png" style="width: 281px; height: 199px;" />
<pre>
<strong>Input:</strong> root = [10,4,6]
<strong>Output:</strong> true
<strong>Explanation:</strong> The values of the root, its left child, and its right child are 10, 4, and 6, respectively.
10 is equal to 4 + 6, so we return true.
</pre>
<p><strong>Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2022/04/08/graph3drawio-1.png" style="width: 281px; height: 199px;" />
<pre>
<strong>Input:</strong> root = [5,3,1]
<strong>Output:</strong> false
<strong>Explanation:</strong> The values of the root, its left child, and its right child are 5, 3, and 1, respectively.
5 is not equal to 3 + 1, so we return false.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li>The tree consists only of the root, its left child, and its right child.</li>
<li><code>-100 &lt;= Node.val &lt;= 100</code></li>
</ul>

View File

@ -0,0 +1,45 @@
<p>You are given a <strong>0-indexed</strong> string <code>expression</code> of the form <code>&quot;&lt;num1&gt;+&lt;num2&gt;&quot;</code> where <code>&lt;num1&gt;</code> and <code>&lt;num2&gt;</code> represent positive integers.</p>
<p>Add a pair of parentheses to <code>expression</code> such that after the addition of parentheses, <code>expression</code> is a <strong>valid</strong> mathematical expression and evaluates to the <strong>smallest</strong> possible value. The left parenthesis <strong>must</strong> be added to the left of <code>&#39;+&#39;</code> and the right parenthesis <strong>must</strong> be added to the right of <code>&#39;+&#39;</code>.</p>
<p>Return <code>expression</code><em> after adding a pair of parentheses such that </em><code>expression</code><em> evaluates to the <strong>smallest</strong> possible value.</em> If there are multiple answers that yield the same result, return any of them.</p>
<p>The input has been generated such that the original value of <code>expression</code>, and the value of <code>expression</code> after adding any pair of parentheses that meets the requirements fits within a signed 32-bit integer.</p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> expression = &quot;247+38&quot;
<strong>Output:</strong> &quot;2(47+38)&quot;
<strong>Explanation:</strong> The <code>expression</code> evaluates to 2 * (47 + 38) = 2 * 85 = 170.
Note that &quot;2(4)7+38&quot; is invalid because the right parenthesis must be to the right of the <code>&#39;+&#39;</code>.
It can be shown that 170 is the smallest possible value.
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> expression = &quot;12+34&quot;
<strong>Output:</strong> &quot;1(2+3)4&quot;
<strong>Explanation:</strong> The expression evaluates to 1 * (2 + 3) * 4 = 1 * 5 * 4 = 20.
</pre>
<p><strong>Example 3:</strong></p>
<pre>
<strong>Input:</strong> expression = &quot;999+999&quot;
<strong>Output:</strong> &quot;(999+999)&quot;
<strong>Explanation:</strong> The <code>expression</code> evaluates to 999 + 999 = 1998.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>3 &lt;= expression.length &lt;= 10</code></li>
<li><code>expression</code> consists of digits from <code>&#39;1&#39;</code> to <code>&#39;9&#39;</code> and <code>&#39;+&#39;</code>.</li>
<li><code>expression</code> starts and ends with digits.</li>
<li><code>expression</code> contains exactly one <code>&#39;+&#39;</code>.</li>
<li>The original value of <code>expression</code>, and the value of <code>expression</code> after adding any pair of parentheses that meets the requirements fits within a signed 32-bit integer.</li>
</ul>

View File

@ -0,0 +1,28 @@
Given a 2D integer array <code>nums</code> where <code>nums[i]</code> is a non-empty array of <strong>distinct</strong> positive integers, return <em>the list of integers that are present in <strong>each array</strong> of</em> <code>nums</code><em> sorted in <strong>ascending order</strong></em>.
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [[<u><strong>3</strong></u>,1,2,<u><strong>4</strong></u>,5],[1,2,<u><strong>3</strong></u>,<u><strong>4</strong></u>],[<u><strong>3</strong></u>,<u><strong>4</strong></u>,5,6]]
<strong>Output:</strong> [3,4]
<strong>Explanation:</strong>
The only integers present in each of nums[0] = [<u><strong>3</strong></u>,1,2,<u><strong>4</strong></u>,5], nums[1] = [1,2,<u><strong>3</strong></u>,<u><strong>4</strong></u>], and nums[2] = [<u><strong>3</strong></u>,<u><strong>4</strong></u>,5,6] are 3 and 4, so we return [3,4].</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> nums = [[1,2,3],[4,5,6]]
<strong>Output:</strong> []
<strong>Explanation:</strong>
There does not exist any integer present both in nums[0] and nums[1], so we return an empty list [].
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 1000</code></li>
<li><code>1 &lt;= sum(nums[i].length) &lt;= 1000</code></li>
<li><code>1 &lt;= nums[i][j] &lt;= 1000</code></li>
<li>All the values of <code>nums[i]</code> are <strong>unique</strong>.</li>
</ul>

View File

@ -0,0 +1,33 @@
<p>You are given a <strong>0-indexed</strong> integer array <code>tasks</code>, where <code>tasks[i]</code> represents the difficulty level of a task. In each round, you can complete either 2 or 3 tasks of the <strong>same difficulty level</strong>.</p>
<p>Return <em>the <strong>minimum</strong> rounds required to complete all the tasks, or </em><code>-1</code><em> if it is not possible to complete all the tasks.</em></p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> tasks = [2,2,3,3,2,4,4,4,4,4]
<strong>Output:</strong> 4
<strong>Explanation:</strong> To complete all the tasks, a possible plan is:
- In the first round, you complete 3 tasks of difficulty level 2.
- In the second round, you complete 2 tasks of difficulty level 3.
- In the third round, you complete 3 tasks of difficulty level 4.
- In the fourth round, you complete 2 tasks of difficulty level 4.
It can be shown that all the tasks cannot be completed in fewer than 4 rounds, so the answer is 4.
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> tasks = [2,3,3]
<strong>Output:</strong> -1
<strong>Explanation:</strong> There is only 1 task of difficulty level 2, but in each round, you can only complete either 2 or 3 tasks of the same difficulty level. Hence, you cannot complete all the tasks, and the answer is -1.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= tasks.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= tasks[i] &lt;= 10<sup>9</sup></code></li>
</ul>

View File

@ -0,0 +1,31 @@
<p>Given an integer array <code>nums</code> of size <code>n</code>, return <em>the number with the value <strong>closest</strong> to </em><code>0</code><em> in </em><code>nums</code>. If there are multiple answers, return <em>the number with the <strong>largest</strong> value</em>.</p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [-4,-2,1,4,8]
<strong>Output:</strong> 1
<strong>Explanation:</strong>
The distance from -4 to 0 is |-4| = 4.
The distance from -2 to 0 is |-2| = 2.
The distance from 1 to 0 is |1| = 1.
The distance from 4 to 0 is |4| = 4.
The distance from 8 to 0 is |8| = 8.
Thus, the closest number to 0 in the array is 1.
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> nums = [2,-1,1]
<strong>Output:</strong> 1
<strong>Explanation:</strong> 1 and -1 are both the closest numbers to 0, so 1 being larger is returned.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= n &lt;= 1000</code></li>
<li><code>-10<sup>5</sup> &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
</ul>

View File

@ -0,0 +1,32 @@
<p>You are given a positive integer <code>num</code>. You may swap any two digits of <code>num</code> that have the same <strong>parity</strong> (i.e. both odd digits or both even digits).</p>
<p>Return<em> the <strong>largest</strong> possible value of </em><code>num</code><em> after <strong>any</strong> number of swaps.</em></p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> num = 1234
<strong>Output:</strong> 3412
<strong>Explanation:</strong> Swap the digit 3 with the digit 1, this results in the number 3214.
Swap the digit 2 with the digit 4, this results in the number 3412.
Note that there may be other sequences of swaps but it can be shown that 3412 is the largest possible number.
Also note that we may not swap the digit 4 with the digit 1 since they are of different parities.
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> num = 65875
<strong>Output:</strong> 87655
<strong>Explanation:</strong> Swap the digit 8 with the digit 6, this results in the number 85675.
Swap the first digit 5 with the digit 7, this results in the number 87655.
Note that there may be other sequences of swaps but it can be shown that 87655 is the largest possible number.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= num &lt;= 10<sup>9</sup></code></li>
</ul>

View File

@ -0,0 +1,35 @@
<p>You are given a <strong>tree</strong> (i.e. a connected, undirected graph that has no cycles) <strong>rooted</strong> at node <code>0</code> consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code>. The tree is represented by a <strong>0-indexed</strong> array <code>parent</code> of size <code>n</code>, where <code>parent[i]</code> is the parent of node <code>i</code>. Since node <code>0</code> is the root, <code>parent[0] == -1</code>.</p>
<p>You are also given a string <code>s</code> of length <code>n</code>, where <code>s[i]</code> is the character assigned to node <code>i</code>.</p>
<p>Return <em>the length of the <strong>longest path</strong> in the tree such that no pair of <strong>adjacent</strong> nodes on the path have the same character assigned to them.</em></p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/25/testingdrawio.png" style="width: 201px; height: 241px;" />
<pre>
<strong>Input:</strong> parent = [-1,0,0,1,1,2], s = &quot;abacbe&quot;
<strong>Output:</strong> 3
<strong>Explanation:</strong> The longest path where each two adjacent nodes have different characters in the tree is the path: 0 -&gt; 1 -&gt; 3. The length of this path is 3, so 3 is returned.
It can be proven that there is no longer path that satisfies the conditions.
</pre>
<p><strong>Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/25/graph2drawio.png" style="width: 201px; height: 221px;" />
<pre>
<strong>Input:</strong> parent = [-1,0,0,0], s = &quot;aabc&quot;
<strong>Output:</strong> 3
<strong>Explanation:</strong> The longest path where each two adjacent nodes have different characters is the path: 2 -&gt; 0 -&gt; 3. The length of this path is 3, so 3 is returned.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>n == parent.length == s.length</code></li>
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
<li><code>0 &lt;= parent[i] &lt;= n - 1</code> for all <code>i &gt;= 1</code></li>
<li><code>parent[0] == -1</code></li>
<li><code>parent</code> represents a valid tree.</li>
<li><code>s</code> consists of only lowercase English letters.</li>
</ul>

View File

@ -0,0 +1,48 @@
<p>You are given a 2D integer array <code>rectangles</code> where <code>rectangles[i] = [l<sub>i</sub>, h<sub>i</sub>]</code> indicates that <code>i<sup>th</sup></code> rectangle has a length of <code>l<sub>i</sub></code> and a height of <code>h<sub>i</sub></code>. You are also given a 2D integer array <code>points</code> where <code>points[j] = [x<sub>j</sub>, y<sub>j</sub>]</code> is a point with coordinates <code>(x<sub>j</sub>, y<sub>j</sub>)</code>.</p>
<p>The <code>i<sup>th</sup></code> rectangle has its <strong>bottom-left corner</strong> point at the coordinates <code>(0, 0)</code> and its <strong>top-right corner</strong> point at <code>(l<sub>i</sub>, h<sub>i</sub>)</code>.</p>
<p>Return<em> an integer array </em><code>count</code><em> of length </em><code>points.length</code><em> where </em><code>count[j]</code><em> is the number of rectangles that <strong>contain</strong> the </em><code>j<sup>th</sup></code><em> point.</em></p>
<p>The <code>i<sup>th</sup></code> rectangle <strong>contains</strong> the <code>j<sup>th</sup></code> point if <code>0 &lt;= x<sub>j</sub> &lt;= l<sub>i</sub></code> and <code>0 &lt;= y<sub>j</sub> &lt;= h<sub>i</sub></code>. Note that points that lie on the <strong>edges</strong> of a rectangle are also considered to be contained by that rectangle.</p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/02/example1.png" style="width: 300px; height: 509px;" />
<pre>
<strong>Input:</strong> rectangles = [[1,2],[2,3],[2,5]], points = [[2,1],[1,4]]
<strong>Output:</strong> [2,1]
<strong>Explanation:</strong>
The first rectangle contains no points.
The second rectangle contains only the point (2, 1).
The third rectangle contains the points (2, 1) and (1, 4).
The number of rectangles that contain the point (2, 1) is 2.
The number of rectangles that contain the point (1, 4) is 1.
Therefore, we return [2, 1].
</pre>
<p><strong>Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/02/example2.png" style="width: 300px; height: 312px;" />
<pre>
<strong>Input:</strong> rectangles = [[1,1],[2,2],[3,3]], points = [[1,3],[1,1]]
<strong>Output:</strong> [1,3]
<strong>Explanation:
</strong>The first rectangle contains only the point (1, 1).
The second rectangle contains only the point (1, 1).
The third rectangle contains the points (1, 3) and (1, 1).
The number of rectangles that contain the point (1, 3) is 1.
The number of rectangles that contain the point (1, 1) is 3.
Therefore, we return [1, 3].
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= rectangles.length, points.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>rectangles[i].length == points[j].length == 2</code></li>
<li><code>1 &lt;= l<sub>i</sub>, x<sub>j</sub> &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= h<sub>i</sub>, y<sub>j</sub> &lt;= 100</code></li>
<li>All the <code>rectangles</code> are <strong>unique</strong>.</li>
<li>All the <code>points</code> are <strong>unique</strong>.</li>
</ul>

View File

@ -0,0 +1,41 @@
<p>Given a 2D integer array <code>circles</code> where <code>circles[i] = [x<sub>i</sub>, y<sub>i</sub>, r<sub>i</sub>]</code> represents the center <code>(x<sub>i</sub>, y<sub>i</sub>)</code> and radius <code>r<sub>i</sub></code> of the <code>i<sup>th</sup></code> circle drawn on a grid, return <em>the <strong>number of lattice points</strong> </em><em>that are present inside <strong>at least one</strong> circle</em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>A <strong>lattice point</strong> is a point with integer coordinates.</li>
<li>Points that lie <strong>on the circumference of a circle</strong> are also considered to be inside it.</li>
</ul>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/02/exa-11.png" style="width: 300px; height: 300px;" />
<pre>
<strong>Input:</strong> circles = [[2,2,1]]
<strong>Output:</strong> 5
<strong>Explanation:</strong>
The figure above shows the given circle.
The lattice points present inside the circle are (1, 2), (2, 1), (2, 2), (2, 3), and (3, 2) and are shown in green.
Other points such as (1, 1) and (1, 3), which are shown in red, are not considered inside the circle.
Hence, the number of lattice points present inside at least one circle is 5.</pre>
<p><strong>Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/02/exa-22.png" style="width: 300px; height: 300px;" />
<pre>
<strong>Input:</strong> circles = [[2,2,2],[3,4,1]]
<strong>Output:</strong> 16
<strong>Explanation:</strong>
The figure above shows the given circles.
There are exactly 16 lattice points which are present inside at least one circle.
Some of them are (0, 2), (2, 0), (2, 4), (3, 2), and (4, 4).
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= circles.length &lt;= 200</code></li>
<li><code>circles[i].length == 3</code></li>
<li><code>1 &lt;= x<sub>i</sub>, y<sub>i</sub> &lt;= 100</code></li>
<li><code>1 &lt;= r<sub>i</sub> &lt;= min(x<sub>i</sub>, y<sub>i</sub>)</code></li>
</ul>

View File

@ -0,0 +1,50 @@
<p>There is an <strong>undirected</strong> graph with <code>n</code> nodes, numbered from <code>0</code> to <code>n - 1</code>.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>scores</code> of length <code>n</code> where <code>scores[i]</code> denotes the score of node <code>i</code>. You are also given a 2D integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists an <strong>undirected</strong> edge connecting nodes <code>a<sub>i</sub></code> and <code>b<sub>i</sub></code>.</p>
<p>A node sequence is <b>valid</b> if it meets the following conditions:</p>
<ul>
<li>There is an edge connecting every pair of <strong>adjacent</strong> nodes in the sequence.</li>
<li>No node appears more than once in the sequence.</li>
</ul>
<p>The score of a node sequence is defined as the <strong>sum</strong> of the scores of the nodes in the sequence.</p>
<p>Return <em>the <strong>maximum score</strong> of a valid node sequence with a length of </em><code>4</code><em>. </em>If no such sequence exists, return<em> </em><code>-1</code>.</p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2022/04/15/ex1new3.png" style="width: 290px; height: 215px;" />
<pre>
<strong>Input:</strong> scores = [5,2,9,8,4], edges = [[0,1],[1,2],[2,3],[0,2],[1,3],[2,4]]
<strong>Output:</strong> 24
<strong>Explanation:</strong> The figure above shows the graph and the chosen node sequence [0,1,2,3].
The score of the node sequence is 5 + 2 + 9 + 8 = 24.
It can be shown that no other node sequence has a score of more than 24.
Note that the sequences [3,1,2,0] and [1,0,2,3] are also valid and have a score of 24.
The sequence [0,3,2,4] is not valid since no edge connects nodes 0 and 3.
</pre>
<p><strong>Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/17/ex2.png" style="width: 333px; height: 151px;" />
<pre>
<strong>Input:</strong> scores = [9,20,6,4,11,12], edges = [[0,3],[5,3],[2,4],[1,3]]
<strong>Output:</strong> -1
<strong>Explanation:</strong> The figure above shows the graph.
There are no valid node sequences of length 4, so we return -1.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>n == scores.length</code></li>
<li><code>4 &lt;= n &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>1 &lt;= scores[i] &lt;= 10<sup>8</sup></code></li>
<li><code>0 &lt;= edges.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>edges[i].length == 2</code></li>
<li><code>0 &lt;= a<sub>i</sub>, b<sub>i</sub> &lt;= n - 1</code></li>
<li><code>a<sub>i</sub> != b<sub>i</sub></code></li>
<li>There are no duplicate edges.</li>
</ul>

View File

@ -0,0 +1,58 @@
<p>Alice is a caretaker of <code>n</code> gardens and she wants to plant flowers to maximize the total beauty of all her gardens.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>flowers</code> of size <code>n</code>, where <code>flowers[i]</code> is the number of flowers already planted in the <code>i<sup>th</sup></code> garden. Flowers that are already planted <strong>cannot</strong> be removed. You are then given another integer <code>newFlowers</code>, which is the <strong>maximum</strong> number of flowers that Alice can additionally plant. You are also given the integers <code>target</code>, <code>full</code>, and <code>partial</code>.</p>
<p>A garden is considered <strong>complete</strong> if it has <strong>at least</strong> <code>target</code> flowers. The <strong>total beauty</strong> of the gardens is then determined as the <strong>sum</strong> of the following:</p>
<ul>
<li>The number of <strong>complete</strong> gardens multiplied by <code>full</code>.</li>
<li>The <strong>minimum</strong> number of flowers in any of the <strong>incomplete</strong> gardens multiplied by <code>partial</code>. If there are no incomplete gardens, then this value will be <code>0</code>.</li>
</ul>
<p>Return <em>the <strong>maximum</strong> total beauty that Alice can obtain after planting at most </em><code>newFlowers</code><em> flowers.</em></p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> flowers = [1,3,1,1], newFlowers = 7, target = 6, full = 12, partial = 1
<strong>Output:</strong> 14
<strong>Explanation:</strong> Alice can plant
- 2 flowers in the 0<sup>th</sup> garden
- 3 flowers in the 1<sup>st</sup> garden
- 1 flower in the 2<sup>nd</sup> garden
- 1 flower in the 3<sup>rd</sup> garden
The gardens will then be [3,6,2,2]. She planted a total of 2 + 3 + 1 + 1 = 7 flowers.
There is 1 garden that is complete.
The minimum number of flowers in the incomplete gardens is 2.
Thus, the total beauty is 1 * 12 + 2 * 1 = 12 + 2 = 14.
No other way of planting flowers can obtain a total beauty higher than 14.
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> flowers = [2,4,5,3], newFlowers = 10, target = 5, full = 2, partial = 6
<strong>Output:</strong> 30
<strong>Explanation:</strong> Alice can plant
- 3 flowers in the 0<sup>th</sup> garden
- 0 flowers in the 1<sup>st</sup> garden
- 0 flowers in the 2<sup>nd</sup> garden
- 2 flowers in the 3<sup>rd</sup> garden
The gardens will then be [5,4,5,5]. She planted a total of 3 + 0 + 0 + 2 = 5 flowers.
There are 3 gardens that are complete.
The minimum number of flowers in the incomplete gardens is 4.
Thus, the total beauty is 3 * 2 + 4 * 6 = 6 + 24 = 30.
No other way of planting flowers can obtain a total beauty higher than 30.
Note that Alice could make all the gardens complete but in this case, she would obtain a lower total beauty.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= flowers.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= flowers[i], target &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= newFlowers &lt;= 10<sup>10</sup></code></li>
<li><code>1 &lt;= full, partial &lt;= 10<sup>5</sup></code></li>
</ul>

View File

@ -0,0 +1,33 @@
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>flowers</code>, where <code>flowers[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means the <code>i<sup>th</sup></code> flower will be in <strong>full bloom</strong> from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> (<strong>inclusive</strong>). You are also given a <strong>0-indexed</strong> integer array <code>persons</code> of size <code>n</code>, where <code>persons[i]</code> is the time that the <code>i<sup>th</sup></code> person will arrive to see the flowers.</p>
<p>Return <em>an integer array </em><code>answer</code><em> of size </em><code>n</code><em>, where </em><code>answer[i]</code><em> is the <strong>number</strong> of flowers that are in full bloom when the </em><code>i<sup>th</sup></code><em> person arrives.</em></p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/02/ex1new.jpg" style="width: 550px; height: 216px;" />
<pre>
<strong>Input:</strong> flowers = [[1,6],[3,7],[9,12],[4,13]], persons = [2,3,7,11]
<strong>Output:</strong> [1,2,2,2]
<strong>Explanation: </strong>The figure above shows the times when the flowers are in full bloom and when the people arrive.
For each person, we return the number of flowers in full bloom during their arrival.
</pre>
<p><strong>Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/02/ex2new.jpg" style="width: 450px; height: 195px;" />
<pre>
<strong>Input:</strong> flowers = [[1,10],[3,3]], persons = [3,3,2]
<strong>Output:</strong> [2,2,1]
<strong>Explanation:</strong> The figure above shows the times when the flowers are in full bloom and when the people arrive.
For each person, we return the number of flowers in full bloom during their arrival.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= flowers.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>flowers[i].length == 2</code></li>
<li><code>1 &lt;= start<sub>i</sub> &lt;= end<sub>i</sub> &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= persons.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>1 &lt;= persons[i] &lt;= 10<sup>9</sup></code></li>
</ul>

View File

@ -0,0 +1,47 @@
<p>You are given a string <code>s</code> consisting of digits and an integer <code>k</code>.</p>
<p>A <strong>round</strong> can be completed if the length of <code>s</code> is greater than <code>k</code>. In one round, do the following:</p>
<ol>
<li><strong>Divide</strong> <code>s</code> into <strong>consecutive groups</strong> of size <code>k</code> such that the first <code>k</code> characters are in the first group, the next <code>k</code> characters are in the second group, and so on. <strong>Note</strong> that the size of the last group can be smaller than <code>k</code>.</li>
<li><strong>Replace</strong> each group of <code>s</code> with a string representing the sum of all its digits. For example, <code>&quot;346&quot;</code> is replaced with <code>&quot;13&quot;</code> because <code>3 + 4 + 6 = 13</code>.</li>
<li><strong>Merge</strong> consecutive groups together to form a new string. If the length of the string is greater than <code>k</code>, repeat from step <code>1</code>.</li>
</ol>
<p>Return <code>s</code> <em>after all rounds have been completed</em>.</p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = &quot;11111222223&quot;, k = 3
<strong>Output:</strong> &quot;135&quot;
<strong>Explanation:</strong>
- For the first round, we divide s into groups of size 3: &quot;111&quot;, &quot;112&quot;, &quot;222&quot;, and &quot;23&quot;.
Then we calculate the digit sum of each group: 1 + 1 + 1 = 3, 1 + 1 + 2 = 4, 2 + 2 + 2 = 6, and 2 + 3 = 5.
&nbsp; So, s becomes &quot;3&quot; + &quot;4&quot; + &quot;6&quot; + &quot;5&quot; = &quot;3465&quot; after the first round.
- For the second round, we divide s into &quot;346&quot; and &quot;5&quot;.
&nbsp; Then we calculate the digit sum of each group: 3 + 4 + 6 = 13, 5 = 5.
&nbsp; So, s becomes &quot;13&quot; + &quot;5&quot; = &quot;135&quot; after second round.
Now, s.length &lt;= k, so we return &quot;135&quot; as the answer.
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> s = &quot;00000000&quot;, k = 3
<strong>Output:</strong> &quot;000&quot;
<strong>Explanation:</strong>
We divide s into &quot;000&quot;, &quot;000&quot;, and &quot;00&quot;.
Then we calculate the digit sum of each group: 0 + 0 + 0 = 0, 0 + 0 + 0 = 0, and 0 + 0 = 0.
s becomes &quot;0&quot; + &quot;0&quot; + &quot;0&quot; = &quot;000&quot;, whose length is equal to k, so we return &quot;000&quot;.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 100</code></li>
<li><code>2 &lt;= k &lt;= 100</code></li>
<li><code>s</code> consists of digits only.</li>
</ul>

View File

@ -0,0 +1,54 @@
<p>There is an ATM machine that stores banknotes of <code>5</code> denominations: <code>20</code>, <code>50</code>, <code>100</code>, <code>200</code>, and <code>500</code> dollars. Initially the ATM is empty. The user can use the machine to deposit or withdraw any amount of money.</p>
<p>When withdrawing, the machine prioritizes using banknotes of <strong>larger</strong> values.</p>
<ul>
<li>For example, if you want to withdraw <code>$300</code> and there are <code>2</code> <code>$50</code> banknotes, <code>1</code> <code>$100</code> banknote, and <code>1</code> <code>$200</code> banknote, then the machine will use the <code>$100</code> and <code>$200</code> banknotes.</li>
<li>However, if you try to withdraw <code>$600</code> and there are <code>3</code> <code>$200</code> banknotes and <code>1</code> <code>$500</code> banknote, then the withdraw request will be rejected because the machine will first try to use the <code>$500</code> banknote and then be unable to use banknotes to complete the remaining <code>$100</code>. Note that the machine is <strong>not</strong> allowed to use the <code>$200</code> banknotes instead of the <code>$500</code> banknote.</li>
</ul>
<p>Implement the ATM class:</p>
<ul>
<li><code>ATM()</code> Initializes the ATM object.</li>
<li><code>void deposit(int[] banknotesCount)</code> Deposits new banknotes in the order <code>$20</code>, <code>$50</code>, <code>$100</code>, <code>$200</code>, and <code>$500</code>.</li>
<li><code>int[] withdraw(int amount)</code> Returns an array of length <code>5</code> of the number of banknotes that will be handed to the user in the order <code>$20</code>, <code>$50</code>, <code>$100</code>, <code>$200</code>, and <code>$500</code>, and update the number of banknotes in the ATM after withdrawing. Returns <code>[-1]</code> if it is not possible (do <strong>not</strong> withdraw any banknotes in this case).</li>
</ul>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input</strong>
[&quot;ATM&quot;, &quot;deposit&quot;, &quot;withdraw&quot;, &quot;deposit&quot;, &quot;withdraw&quot;, &quot;withdraw&quot;]
[[], [[0,0,1,2,1]], [600], [[0,1,0,1,1]], [600], [550]]
<strong>Output</strong>
[null, null, [0,0,1,0,1], null, [-1], [0,1,0,0,1]]
<strong>Explanation</strong>
ATM atm = new ATM();
atm.deposit([0,0,1,2,1]); // Deposits 1 $100 banknote, 2 $200 banknotes,
// and 1 $500 banknote.
atm.withdraw(600); // Returns [0,0,1,0,1]. The machine uses 1 $100 banknote
// and 1 $500 banknote. The banknotes left over in the
// machine are [0,0,0,2,0].
atm.deposit([0,1,0,1,1]); // Deposits 1 $50, $200, and $500 banknote.
// The banknotes in the machine are now [0,1,0,3,1].
atm.withdraw(600); // Returns [-1]. The machine will try to use a $500 banknote
// and then be unable to complete the remaining $100,
// so the withdraw request will be rejected.
// Since the request is rejected, the number of banknotes
// in the machine is not modified.
atm.withdraw(550); // Returns [0,1,0,0,1]. The machine uses 1 $50 banknote
// and 1 $500 banknote.</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>banknotesCount.length == 5</code></li>
<li><code>0 &lt;= banknotesCount[i] &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= amount &lt;= 10<sup>9</sup></code></li>
<li>At most <code>5000</code> calls <strong>in total</strong> will be made to <code>withdraw</code> and <code>deposit</code>.</li>
<li>At least <strong>one</strong> call will be made to each function <code>withdraw</code> and <code>deposit</code>.</li>
</ul>

View File

@ -0,0 +1,48 @@
<p>You are given a 2D integer array <code>grid</code> of size <code>m x n</code>, where each cell contains a positive integer.</p>
<p>A <strong>cornered path</strong> is defined as a set of adjacent cells with <strong>at most</strong> one turn. More specifically, the path should exclusively move either <strong>horizontally</strong> or <strong>vertically</strong> up to the turn (if there is one), without returning to a previously visited cell. After the turn, the path will then move exclusively in the <strong>alternate</strong> direction: move vertically if it moved horizontally, and vice versa, also without returning to a previously visited cell.</p>
<p>The <strong>product</strong> of a path is defined as the product of all the values in the path.</p>
<p>Return <em>the <strong>maximum</strong> number of <strong>trailing zeros</strong> in the product of a cornered path found in </em><code>grid</code>.</p>
<p>Note:</p>
<ul>
<li><strong>Horizontal</strong> movement means moving in either the left or right direction.</li>
<li><strong>Vertical</strong> movement means moving in either the up or down direction.</li>
</ul>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/23/ex1new2.jpg" style="width: 577px; height: 190px;" />
<pre>
<strong>Input:</strong> grid = [[23,17,15,3,20],[8,1,20,27,11],[9,4,6,2,21],[40,9,1,10,6],[22,7,4,5,3]]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The grid on the left shows a valid cornered path.
It has a product of 15 * 20 * 6 * 1 * 10 = 18000 which has 3 trailing zeros.
It can be shown that this is the maximum trailing zeros in the product of a cornered path.
The grid in the middle is not a cornered path as it has more than one turn.
The grid on the right is not a cornered path as it requires a return to a previously visited cell.
</pre>
<p><strong>Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/25/ex2.jpg" style="width: 150px; height: 157px;" />
<pre>
<strong>Input:</strong> grid = [[4,3,2],[7,6,1],[8,8,8]]
<strong>Output:</strong> 0
<strong>Explanation:</strong> The grid is shown in the figure above.
There are no cornered paths in the grid that result in a product with a trailing zero.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>m == grid.length</code></li>
<li><code>n == grid[i].length</code></li>
<li><code>1 &lt;= m, n &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= m * n &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= grid[i][j] &lt;= 1000</code></li>
</ul>

File diff suppressed because it is too large Load Diff

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

View File

@ -0,0 +1,59 @@
{
"data": {
"question": {
"questionId": "2376",
"questionFrontendId": "2238",
"boundTopicId": null,
"title": "Number of Times a Driver Was a Passenger",
"titleSlug": "number-of-times-a-driver-was-a-passenger",
"content": null,
"translatedTitle": null,
"translatedContent": null,
"isPaidOnly": true,
"difficulty": "Medium",
"likes": 12,
"dislikes": 1,
"isLiked": null,
"similarQuestions": "[{\"title\": \"Hopper Company Queries I\", \"titleSlug\": \"hopper-company-queries-i\", \"difficulty\": \"Hard\", \"translatedTitle\": null}, {\"title\": \"Hopper Company Queries II\", \"titleSlug\": \"hopper-company-queries-ii\", \"difficulty\": \"Hard\", \"translatedTitle\": null}, {\"title\": \"Hopper Company Queries III\", \"titleSlug\": \"hopper-company-queries-iii\", \"difficulty\": \"Hard\", \"translatedTitle\": null}]",
"exampleTestcases": null,
"categoryTitle": "Database",
"contributors": [],
"topicTags": [
{
"name": "Database",
"slug": "database",
"translatedName": null,
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": null,
"stats": "{\"totalAccepted\": \"397\", \"totalSubmission\": \"503\", \"totalAcceptedRaw\": 397, \"totalSubmissionRaw\": 503, \"acRate\": \"78.9%\"}",
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "{\"headers\":{\"Rides\":[\"ride_id\",\"driver_id\",\"passenger_id\"]},\"rows\":{\"Rides\":[[1,7,1],[2,7,2],[3,11,1],[4,11,7],[5,11,7],[6,11,3]]}}",
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Rides (ride_id int, driver_id int, passenger_id int)\"\n ],\n \"mssql\": [\n \"Create table Rides (ride_id int, driver_id int, passenger_id int)\"\n ],\n \"oraclesql\": [\n \"Create table Rides (ride_id int, driver_id int, passenger_id int)\"\n ],\n \"database\": true\n}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [
"Create table If Not Exists Rides (ride_id int, driver_id int, passenger_id int)",
"Truncate table Rides",
"insert into Rides (ride_id, driver_id, passenger_id) values ('1', '7', '1')",
"insert into Rides (ride_id, driver_id, passenger_id) values ('2', '7', '2')",
"insert into Rides (ride_id, driver_id, passenger_id) values ('3', '11', '1')",
"insert into Rides (ride_id, driver_id, passenger_id) values ('4', '11', '7')",
"insert into Rides (ride_id, driver_id, passenger_id) values ('5', '11', '7')",
"insert into Rides (ride_id, driver_id, passenger_id) values ('6', '11', '3')"
],
"enableRunCode": true,
"enableTestMode": false,
"enableDebugger": false,
"envInfo": "{\"mysql\": [\"MySQL\", \"<p><code>MySQL 8.0</code>.</p>\"], \"mssql\": [\"MS SQL Server\", \"<p><code>mssql server 2019</code>.</p>\"], \"oraclesql\": [\"Oracle\", \"<p><code>Oracle Sql 11.2</code>.</p>\"]}",
"libraryUrl": null,
"adminUrl": null,
"challengeQuestion": null,
"__typename": "QuestionNode"
}
}
}

View File

@ -0,0 +1,57 @@
{
"data": {
"question": {
"questionId": "2371",
"questionFrontendId": "2230",
"boundTopicId": null,
"title": "The Users That Are Eligible for Discount",
"titleSlug": "the-users-that-are-eligible-for-discount",
"content": null,
"translatedTitle": null,
"translatedContent": null,
"isPaidOnly": true,
"difficulty": "Easy",
"likes": 5,
"dislikes": 2,
"isLiked": null,
"similarQuestions": "[{\"title\": \"The Number of Users That Are Eligible for Discount\", \"titleSlug\": \"the-number-of-users-that-are-eligible-for-discount\", \"difficulty\": \"Easy\", \"translatedTitle\": null}]",
"exampleTestcases": null,
"categoryTitle": "Database",
"contributors": [],
"topicTags": [
{
"name": "Database",
"slug": "database",
"translatedName": null,
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": null,
"stats": "{\"totalAccepted\": \"466\", \"totalSubmission\": \"925\", \"totalAcceptedRaw\": 466, \"totalSubmissionRaw\": 925, \"acRate\": \"50.4%\"}",
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "{\"headers\": {\"Purchases\": [\"user_id\", \"time_stamp\", \"amount\"]}, \"startDate\": \"2022-03-08\", \"endDate\": \"2022-03-20\", \"minAmount\": 1000, \"rows\": {\"Purchases\": [[1, \"2022-04-20 09:03:00\", 4416], [2, \"2022-03-19 19:24:02\", 678], [3, \"2022-03-18 12:03:09\", 4523], [3, \"2022-03-30 09:43:42\", 626]]}}",
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Purchases (user_id int, time_stamp datetime, amount int)\"\n ],\n \"mssql\": [\n \"Create table Purchases (user_id int, time_stamp datetime, amount int)\"\n ],\n \"oraclesql\": [\n \"Create table Purchases (user_id int, time_stamp date, amount int)\",\n \"ALTER SESSION SET nls_date_format='YYYY-MM-DD HH24:MI:SS'\"\n ],\n \"database\": true,\n \"manual\": true\n}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [
"Create table If Not Exists Purchases (user_id int, time_stamp datetime, amount int)",
"Truncate table Purchases",
"insert into Purchases (user_id, time_stamp, amount) values ('1', '2022-04-20 09:03:00', '4416')",
"insert into Purchases (user_id, time_stamp, amount) values ('2', '2022-03-19 19:24:02', '678')",
"insert into Purchases (user_id, time_stamp, amount) values ('3', '2022-03-18 12:03:09', '4523')",
"insert into Purchases (user_id, time_stamp, amount) values ('3', '2022-03-30 09:43:42', '626')"
],
"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"
}
}
}

View File

@ -0,0 +1,59 @@
{
"data": {
"question": {
"questionId": "2370",
"questionFrontendId": "2228",
"boundTopicId": null,
"title": "Users With Two Purchases Within Seven Days",
"titleSlug": "users-with-two-purchases-within-seven-days",
"content": null,
"translatedTitle": null,
"translatedContent": null,
"isPaidOnly": true,
"difficulty": "Medium",
"likes": 8,
"dislikes": 3,
"isLiked": null,
"similarQuestions": "[{\"title\": \"Biggest Window Between Visits\", \"titleSlug\": \"biggest-window-between-visits\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"exampleTestcases": "{\"headers\":{\"Purchases\":[\"purchase_id\",\"user_id\",\"purchase_date\"]},\"rows\":{\"Purchases\":[[4,2,\"2022-03-13\"],[1,5,\"2022-02-11\"],[3,7,\"2022-06-19\"],[6,2,\"2022-03-20\"],[5,7,\"2022-06-19\"],[2,2,\"2022-06-08\"]]}}",
"categoryTitle": "Database",
"contributors": [],
"topicTags": [
{
"name": "Database",
"slug": "database",
"translatedName": null,
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": null,
"stats": "{\"totalAccepted\": \"657\", \"totalSubmission\": \"1.4K\", \"totalAcceptedRaw\": 657, \"totalSubmissionRaw\": 1363, \"acRate\": \"48.2%\"}",
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "{\"headers\":{\"Purchases\":[\"purchase_id\",\"user_id\",\"purchase_date\"]},\"rows\":{\"Purchases\":[[4,2,\"2022-03-13\"],[1,5,\"2022-02-11\"],[3,7,\"2022-06-19\"],[6,2,\"2022-03-20\"],[5,7,\"2022-06-19\"],[2,2,\"2022-06-08\"]]}}",
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Purchases (purchase_id int, user_id int, purchase_date date)\"\n ],\n \"mssql\": [\n \"Create table Purchases (purchase_id int, user_id int, purchase_date date)\"\n ],\n \"oraclesql\": [\n \"Create table Purchases (purchase_id int, user_id int, purchase_date date)\",\n \"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"\n ],\n \"database\": true\n}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [
"Create table If Not Exists Purchases (purchase_id int, user_id int, purchase_date date)",
"Truncate table Purchases",
"insert into Purchases (purchase_id, user_id, purchase_date) values ('4', '2', '2022-03-13')",
"insert into Purchases (purchase_id, user_id, purchase_date) values ('1', '5', '2022-02-11')",
"insert into Purchases (purchase_id, user_id, purchase_date) values ('3', '7', '2022-06-19')",
"insert into Purchases (purchase_id, user_id, purchase_date) values ('6', '2', '2022-03-20')",
"insert into Purchases (purchase_id, user_id, purchase_date) values ('5', '7', '2022-06-19')",
"insert into Purchases (purchase_id, user_id, purchase_date) values ('2', '2', '2022-06-08')"
],
"enableRunCode": true,
"enableTestMode": false,
"enableDebugger": false,
"envInfo": "{\"mysql\": [\"MySQL\", \"<p><code>MySQL 8.0</code>.</p>\"], \"mssql\": [\"MS SQL Server\", \"<p><code>mssql server 2019</code>.</p>\"], \"oraclesql\": [\"Oracle\", \"<p><code>Oracle Sql 11.2</code>.</p>\"]}",
"libraryUrl": null,
"adminUrl": null,
"challengeQuestion": null,
"__typename": "QuestionNode"
}
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Some files were not shown because too many files have changed in this diff Show More