Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update lc problems #1950

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<p><strong>示例 1:</strong></p>

<pre>
<b>输入:</b>beans = [4,<u><strong>1</strong></u>,6,5]
<b>输入:</b>beans = [4,1,6,5]
<b>输出:</b>4
<b>解释:</b>
- 我们从有 1 个魔法豆的袋子中拿出 1 颗魔法豆。
Expand All @@ -33,7 +33,7 @@
<p><strong>示例 2:</strong></p>

<pre>
<b>输入:</b>beans = [<u><strong>2</strong></u>,10,<u><strong>3</strong></u>,<u><strong>2</strong></u>]
<b>输入:</b>beans = [2,10,3,2]
<b>输出:</b>7
<strong>解释:</strong>
- 我们从有 2 个魔法豆的其中一个袋子中拿出 2 个魔法豆。
Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,54 @@
# [2921. Maximum Profitable Triplets With Increasing Prices II](https://leetcode.cn/problems/maximum-profitable-triplets-with-increasing-prices-ii)
# [2921. 具有递增价格的最大利润三元组 II](https://leetcode.cn/problems/maximum-profitable-triplets-with-increasing-prices-ii)

[English Version](/solution/2900-2999/2921.Maximum%20Profitable%20Triplets%20With%20Increasing%20Prices%20II/README_EN.md)

## 题目描述

<!-- 这里写题目描述 -->

<p>Given the <strong>0-indexed</strong> arrays <code>prices</code> and <code>profits</code> of length <code>n</code>. There are <code>n</code> items in an store where the <code>i<sup>th</sup></code> item has a price of <code>prices[i]</code> and a profit of <code>profits[i]</code>.</p>
<p>给定长度为 <code>n</code>&nbsp; 的数组&nbsp;<code>prices</code>&nbsp;和&nbsp;<code>profits</code>&nbsp;(<strong>下标从 0 开始</strong>)。一个商店有&nbsp;<code>n</code>&nbsp;个商品,第&nbsp;<code>i</code>&nbsp;个商品的价格为&nbsp;<code>prices[i]</code>,利润为&nbsp;<code>profits[i]</code></p>

<p>We have to pick three items with the following condition:</p>
<p>需要选择三个商品,满足以下条件:</p>

<ul>
<li><code>prices[i] &lt; prices[j] &lt; prices[k]</code> where <code>i &lt; j &lt; k</code>.</li>
<li><code>prices[i] &lt; prices[j] &lt; prices[k]</code>,其中&nbsp;<code>i &lt; j &lt; k</code></li>
</ul>

<p>If we pick items with indices <code>i</code>, <code>j</code> and <code>k</code> satisfying the above condition, the profit would be <code>profits[i] + profits[j] + profits[k]</code>.</p>
<p>如果选择的商品&nbsp;<code>i</code>, <code>j</code>&nbsp;和&nbsp;<code>k</code>&nbsp;满足以下条件,那么利润将等于&nbsp;<code>profits[i] + profits[j] + profits[k]</code></p>

<p>Return<em> the <strong>maximum profit</strong> we can get, and </em><code>-1</code><em> if it&#39;s not possible to pick three items with the given condition.</em></p>
<p>返回能够获得的<em>&nbsp;<strong>最大利润</strong>,如果不可能满足给定条件,</em>返回<em>&nbsp;</em><code>-1</code><em></em></p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<p><strong>示例 1:</strong></p>

<pre>
<strong>Input:</strong> prices = [10,2,3,4], profits = [100,2,7,10]
<strong>Output:</strong> 19
<strong>Explanation:</strong> We can&#39;t pick the item with index i=0 since there are no indices j and k such that the condition holds.
So the only triplet we can pick, are the items with indices 1, 2 and 3 and it&#39;s a valid pick since prices[1] &lt; prices[2] &lt; prices[3].
The answer would be sum of their profits which is 2 + 7 + 10 = 19.</pre>
<b>输入:</b>prices = [10,2,3,4], profits = [100,2,7,10]
<b>输出:</b>19
<b>解释:</b>不能选择下标 i=0 的商品,因为没有下标 j 和 k 的商品满足条件。
只能选择下标为 1、2、3 的三个商品,这是有效的选择,因为 prices[1] &lt; prices[2] &lt; prices[3]
答案是它们的利润之和,即 2 + 7 + 10 = 19</pre>

<p><strong class="example">Example 2:</strong></p>
<p><strong>示例 2:</strong></p>

<pre>
<strong>Input:</strong> prices = [1,2,3,4,5], profits = [1,5,3,4,6]
<strong>Output:</strong> 15
<strong>Explanation:</strong> We can select any triplet of items since for each triplet of indices i, j and k such that i &lt; j &lt; k, the condition holds.
Therefore the maximum profit we can get would be the 3 most profitable items which are indices 1, 3 and 4.
The answer would be sum of their profits which is 5 + 4 + 6 = 15.</pre>
<b>输入:</b>prices = [1,2,3,4,5], profits = [1,5,3,4,6]
<b>输出:</b>15
<b>解释:</b>可以选择任意三个商品,因为对于每组满足下标为 i &lt; j &lt; k 的三个商品,条件都成立。
因此,能得到的最大利润就是利润和最大的三个商品,即下标为 1,3 和 4 的商品。
答案就是它们的利润之和,即 5 + 4 + 6 = 15</pre>

<p><strong class="example">Example 3:</strong></p>
<p><strong>示例 3:</strong></p>

<pre>
<strong>Input:</strong> prices = [4,3,2,1], profits = [33,20,19,87]
<strong>Output:</strong> -1
<strong>Explanation:</strong> We can&#39;t select any triplet of indices such that the condition holds, so we return -1.
<b>输入:</b>prices = [4,3,2,1], profits = [33,20,19,87]
<b>输出:</b>-1
<b>解释:</b>找不到任何可以满足条件的三个商品,所以返回 -1.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<p><b>提示:</b></p>

<ul>
<li><code>3 &lt;= prices.length == profits.length &lt;= 50000</code></li>
Expand Down
40 changes: 21 additions & 19 deletions solution/2900-2999/2922.Market Analysis III/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [2922. Market Analysis III](https://leetcode.cn/problems/market-analysis-iii)
# [2922. 市场分析 III](https://leetcode.cn/problems/market-analysis-iii)

[English Version](/solution/2900-2999/2922.Market%20Analysis%20III/README_EN.md)

Expand All @@ -16,8 +16,8 @@
| join_date | date |
| favorite_brand | varchar |
+----------------+---------+
seller_id is the primary key for this table.
This table contains seller id, join date, and favorite brand of sellers.
seller_id 是该表的主键。
该表包含销售者的 ID, 加入日期以及最喜欢的品牌。
</pre>

<p>Table: <code>Items</code></p>
Expand All @@ -29,8 +29,8 @@ This table contains seller id, join date, and favorite brand of sellers.
| item_id | int |
| item_brand | varchar |
+---------------+---------+
item_id is the primary key for this table.
This table contains item id and item brand.</pre>
item_id 是该表的主键。
该表包含商品 ID 和商品品牌。</pre>

<p>Table: <code>Orders</code></p>

Expand All @@ -43,22 +43,23 @@ This table contains item id and item brand.</pre>
| item_id | int |
| seller_id | int |
+---------------+---------+
order_id is the primary key for this table.
item_id is a foreign key to the Items table.
seller_id is a foreign key to the Users table.
This table contains order id, order date, item id and seller id.</pre>
order_id 是该表的主键。
item_id 是指向 Items 表的外键。
seller_id 是指向 Users 表的外键。
该表包含订单 ID、下单日期、商品 ID 和卖家 ID。</pre>

<p>Write a solution to find the <strong>top seller</strong> who has sold the highest number of<strong> unique</strong> items with a <strong>different</strong> brand than their favorite brand. If there are multiple sellers with the same highest count, return all of them.</p>
<p>编写一个解决方案,找到销售最多与其最喜欢的品牌 <strong>不同</strong> <strong>独特</strong> 商品的&nbsp;<strong>顶级卖家</strong>。如果有多个卖家销售同样数量的商品,则返回所有这些卖家。&nbsp;</p>

<p>Return <em>the result table ordered by</em> <code>seller_id</code> <em>in <strong>ascending</strong> order.</em></p>
<p>返回按&nbsp;<code>seller_id</code><em>&nbsp;<strong>升序排序</strong>&nbsp;的结果表。</em></p>

<p>The result format is in the following example.</p>
<p>结果格式如下示例所示。</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<p><b>示例 1:</b></p>

<pre>
<strong>Input:</strong>
<b>输入:</b>
Users table:
+-----------+------------+----------------+
| seller_id | join_date | favorite_brand |
Expand Down Expand Up @@ -86,17 +87,18 @@ Items table:
| 3 | LG |
| 4 | HP |
+---------+------------+
<strong>Output:</strong>
<b>输出:</b>
+-----------+-----------+
| seller_id | num_items |
+-----------+-----------+
| 2 | 1 |
| 3 | 1 |
+-----------+-----------+
<strong>Explanation:</strong>
- The user with seller_id 2 has sold three items, but only two of them are not marked as a favorite. We will include a unique count of 1 because both of these items are identical.
- The user with seller_id 3 has sold two items, but only one of them is not marked as a favorite. We will include just that non-favorite item in our count.
Since seller_ids 2 and 3 have the same count of one item each, they both will be displayed in the output.</pre>
<b>解释:</b>
- 卖家 ID 为 2 的用户销售了三件商品,但只有两件不被标记为最喜欢的商品。我们将只列入独特计数为 1,因为这两件商品都是相同的。
- 卖家 ID 为 3 的用户销售了两件商品,但只有一件不被标记为最喜欢的商品。我们将只包括那个不被标记为最喜欢的商品列入计数中。
因为卖家 ID 为 2 和 3 的卖家都有一件商品列入计数,所以他们都将显示在输出中。
</pre>

## 解法

Expand Down
5 changes: 3 additions & 2 deletions solution/2900-2999/2923.Find Champion I/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ grid[1][2] == 1 表示 1 队比 2 队强。
<li><code>n == grid.length</code></li>
<li><code>n == grid[i].length</code></li>
<li><code>2 &lt;= n &lt;= 100</code></li>
<li><code>grid[i][j]</code> 的值为 <code>0</code> 或 <code>1</code></li>
<li><code>grid[i][j]</code> 的值为 <code>0</code> 或 <code>1</code><meta charset="UTF-8" /></li>
<li>对于所有&nbsp;<code>i</code>,<code> grid[i][i]</code>&nbsp;等于&nbsp;<code>0.</code></li>
<li>对于满足&nbsp;<code>i != j</code> 的所有 <code>i, j</code> ,<code>grid[i][j] != grid[j][i]</code> 均成立</li>
<li>生成的输出满足:如果 <code>a</code> 队比 <code>b</code> 队强,<code>b</code> 队比 <code>c</code> 队强,那么 <code>a</code> 队比 <code>c</code> 队强</li>
<li>生成的输入满足:如果 <code>a</code> 队比 <code>b</code> 队强,<code>b</code> 队比 <code>c</code> 队强,那么 <code>a</code> 队比 <code>c</code> 队强</li>
</ul>

## 解法
Expand Down
1 change: 1 addition & 0 deletions solution/2900-2999/2923.Find Champion I/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ So team 1 will be the champion.
<li><code>n == grid[i].length</code></li>
<li><code>2 &lt;= n &lt;= 100</code></li>
<li><code>grid[i][j]</code> is either <code>0</code> or <code>1</code>.</li>
<li>For all <code>i grid[i][i]</code> is <code>0.</code></li>
<li>For all <code>i, j</code> that <code>i != j</code>, <code>grid[i][j] != grid[j][i]</code>.</li>
<li>The input is generated such that if team <code>a</code> is stronger than team <code>b</code> and team <code>b</code> is stronger than team <code>c</code>, then team <code>a</code> is stronger than team <code>c</code>.</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
# [2927. Distribute Candies Among Children III](https://leetcode.cn/problems/distribute-candies-among-children-iii)
# [2927. 将糖果分发给孩子 III](https://leetcode.cn/problems/distribute-candies-among-children-iii)

[English Version](/solution/2900-2999/2927.Distribute%20Candies%20Among%20Children%20III/README_EN.md)

## 题目描述

<!-- 这里写题目描述 -->

<p>You are given two positive integers <code>n</code> and <code>limit</code>.</p>
<p>你被给定两个正整数 <code>n</code> <code>limit</code></p>

<p>Return <em>the <strong>total number</strong> of ways to distribute </em><code>n</code> <em>candies among </em><code>3</code><em> children such that no child gets more than </em><code>limit</code><em> candies.</em></p>
<p>返回 <em>在每个孩子得到不超过&nbsp;</em><code>limit</code><em> 个糖果的情况下,将</em> <code>n</code> <em>个糖果分发给</em>&nbsp;<code>3</code> <em>个孩子的&nbsp;<strong>总方法数</strong>。</em></p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<p><b>示例 1:</b></p>

<pre>
<strong>Input:</strong> n = 5, limit = 2
<strong>Output:</strong> 3
<strong>Explanation:</strong> There are 3 ways to distribute 5 candies such that no child gets more than 2 candies: (1, 2, 2), (2, 1, 2) and (2, 2, 1).
<b>输入:</b>n = 5, limit = 2
<b>输出:</b>3
<b>解释:</b>有 3 种方式将 5 个糖果分发给 3 个孩子,使得每个孩子得到不超过 2 个糖果:(1, 2, 2), (2, 1, 2) (2, 2, 1)
</pre>

<p><strong class="example">Example 2:</strong></p>
<p><b>示例 2:</b></p>

<pre>
<strong>Input:</strong> n = 3, limit = 3
<strong>Output:</strong> 10
<strong>Explanation:</strong> There are 10 ways to distribute 3 candies such that no child gets more than 3 candies: (0, 0, 3), (0, 1, 2), (0, 2, 1), (0, 3, 0), (1, 0, 2), (1, 1, 1), (1, 2, 0), (2, 0, 1), (2, 1, 0) and (3, 0, 0).
<b>输入:</b>n = 3, limit = 3
<b>输出:</b>10
<b>解释:</b>有 10 种方式将 3 个糖果分发给 3 个孩子,使得每个孩子得到不超过 3 个糖果:(0, 0, 3), (0, 1, 2), (0, 2, 1), (0, 3, 0), (1, 0, 2), (1, 1, 1), (1, 2, 0), (2, 0, 1), (2, 1, 0) (3, 0, 0)
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<p><b>提示:</b></p>

<ul>
<li><code>1 &lt;= n &lt;= 10<sup>8</sup></code></li>
Expand Down
2 changes: 1 addition & 1 deletion solution/DATABASE_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@
| 2853 | [最高薪水差异](/solution/2800-2899/2853.Highest%20Salaries%20Difference/README.md) | `数据库` | 简单 | 🔒 |
| 2854 | [滚动平均步数](/solution/2800-2899/2854.Rolling%20Average%20Steps/README.md) | `数据库` | 中等 | 🔒 |
| 2893 | [计算每个区间内的订单](/solution/2800-2899/2893.Calculate%20Orders%20Within%20Each%20Interval/README.md) | `数据库` | 中等 | 🔒 |
| 2922 | [Market Analysis III](/solution/2900-2999/2922.Market%20Analysis%20III/README.md) | | 中等 | 🔒 |
| 2922 | [市场分析 III](/solution/2900-2999/2922.Market%20Analysis%20III/README.md) | | 中等 | 🔒 |

## 版权

Expand Down
2 changes: 1 addition & 1 deletion solution/JAVASCRIPT_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
| 2629 | [复合函数](/solution/2600-2699/2629.Function%20Composition/README.md) | | 简单 | |
| 2630 | [记忆函数 II](/solution/2600-2699/2630.Memoize%20II/README.md) | | 困难 | |
| 2631 | [分组](/solution/2600-2699/2631.Group%20By/README.md) | | 中等 | |
| 2632 | [柯里化](/solution/2600-2699/2632.Curry/README.md) | | 困难 | 🔒 |
| 2632 | [柯里化](/solution/2600-2699/2632.Curry/README.md) | | 中等 | 🔒 |
| 2633 | [将对象转换为 JSON 字符串](/solution/2600-2699/2633.Convert%20Object%20to%20JSON%20String/README.md) | | 中等 | 🔒 |
| 2634 | [过滤数组中的元素](/solution/2600-2699/2634.Filter%20Elements%20from%20Array/README.md) | | 简单 | |
| 2635 | [转换数组中的每个元素](/solution/2600-2699/2635.Apply%20Transform%20Over%20Each%20Element%20in%20Array/README.md) | | 简单 | |
Expand Down
2 changes: 1 addition & 1 deletion solution/JAVASCRIPT_README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
| 2629 | [Function Composition](/solution/2600-2699/2629.Function%20Composition/README_EN.md) | | Easy | |
| 2630 | [Memoize II](/solution/2600-2699/2630.Memoize%20II/README_EN.md) | | Hard | |
| 2631 | [Group By](/solution/2600-2699/2631.Group%20By/README_EN.md) | | Medium | |
| 2632 | [Curry](/solution/2600-2699/2632.Curry/README_EN.md) | | Hard | 🔒 |
| 2632 | [Curry](/solution/2600-2699/2632.Curry/README_EN.md) | | Medium | 🔒 |
| 2633 | [Convert Object to JSON String](/solution/2600-2699/2633.Convert%20Object%20to%20JSON%20String/README_EN.md) | | Medium | 🔒 |
| 2634 | [Filter Elements from Array](/solution/2600-2699/2634.Filter%20Elements%20from%20Array/README_EN.md) | | Easy | |
| 2635 | [Apply Transform Over Each Element in Array](/solution/2600-2699/2635.Apply%20Transform%20Over%20Each%20Element%20in%20Array/README_EN.md) | | Easy | |
Expand Down
Loading