Skip to content

Commit 939d0df

Browse files
yanglbmeidoocs
andauthored
feat: add solutions to lc problem: No.2912 (doocs#1884)
No.2912.Number of Ways to Reach Destination in the Grid --------- Co-authored-by: Doocs Bot <doocs-bot@outlook.com>
1 parent c9c6625 commit 939d0df

File tree

24 files changed

+617
-123
lines changed

24 files changed

+617
-123
lines changed

solution/0100-0199/0101.Symmetric Tree/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
<p>&nbsp;</p>
1212

1313
<p><strong>示例 1:</strong></p>
14-
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0101.Symmetric%20Tree/images/symtree1.jpg" style="width: 354px; height: 291px;" />
14+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0101.Symmetric%20Tree/images/1698026966-JDYPDU-image.png" style="width: 354px; height: 291px;" />
1515
<pre>
1616
<strong>输入:</strong>root = [1,2,2,3,4,4,3]
1717
<strong>输出:</strong>true
1818
</pre>
1919

2020
<p><strong>示例 2:</strong></p>
21-
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0101.Symmetric%20Tree/images/symtree2.jpg" style="width: 308px; height: 258px;" />
21+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0101.Symmetric%20Tree/images/1698027008-nPFLbM-image.png" style="width: 308px; height: 258px;" />
2222
<pre>
2323
<strong>输入:</strong>root = [1,2,2,null,3,null,3]
2424
<strong>输出:</strong>false
Loading
Loading

solution/0100-0199/0158.Read N Characters Given read4 II - Call Multiple Times/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# [158. 用 Read4 读取 N 个字符 II](https://leetcode.cn/problems/read-n-characters-given-read4-ii-call-multiple-times)
1+
# [158. 用 Read4 读取 N 个字符 II - 多次调用](https://leetcode.cn/problems/read-n-characters-given-read4-ii-call-multiple-times)
22

33
[English Version](/solution/0100-0199/0158.Read%20N%20Characters%20Given%20read4%20II%20-%20Call%20Multiple%20Times/README_EN.md)
44

solution/0500-0599/0560.Subarray Sum Equals K/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

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

9-
<p>给你一个整数数组 <code>nums</code> 和一个整数&nbsp;<code>k</code> ,请你统计并返回 <em>该数组中和为&nbsp;<code>k</code><strong>&nbsp;</strong>的连续子数组的个数&nbsp;</em>。</p>
9+
<p>给你一个整数数组 <code>nums</code> 和一个整数&nbsp;<code>k</code> ,请你统计并返回 <em>该数组中和为&nbsp;<code>k</code><strong>&nbsp;</strong>的子数组的个数&nbsp;</em>。</p>
1010

1111
<p>子数组是数组中元素的连续非空序列。</p>
1212

solution/2100-2199/2142.The Number of Passengers in Each Bus I/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ passenger_id 是该表的主键。
3838

3939
<p>公交车和乘客到达 LeetCode 站。如果一辆公交车在时间 <code>t<sub>bus</sub></code> 到站,乘客在时间 <code>t<sub>passenger</sub></code> 到站,其中 <code>t<sub>passenger</sub> &lt;= t<sub>bus</sub></code>,该乘客之前没有赶上任何公交车,则该乘客将搭乘该公交车。</p>
4040

41-
<p>编写一个 SQL 来查询使用每条总线的用户数量。</p>
41+
<p>编写一个 SQL 来查询使用每辆公交车的用户数量。</p>
4242

4343
<p>返回按 <code>bus_id</code> <strong>升序排序&nbsp;</strong>的结果表。</p>
4444

solution/2100-2199/2171.Removing Minimum Number of Magic Beans/README.md

+13-11
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,42 @@
66

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

9-
<p>给你一个 <strong></strong>&nbsp;整数数组&nbsp;<code>beans</code>&nbsp;,其中每个整数表示一个袋子里装的魔法豆的数目。</p>
9+
<p>给定一个 <strong>正整数&nbsp;</strong>数组&nbsp;<code>beans</code>&nbsp;,其中每个整数表示一个袋子里装的魔法豆的数目。</p>
1010

11-
<p>请你从每个袋子中&nbsp;<strong>拿出</strong>&nbsp;一些豆子(也可以<strong>&nbsp;不拿出</strong>),使得剩下的 <strong>非空</strong> 袋子中(即 <strong>至少</strong>&nbsp;还有 <strong>一颗</strong>&nbsp;魔法豆的袋子)魔法豆的数目&nbsp;<strong>相等</strong>&nbsp;。一旦魔法豆从袋子中取出,你不能将它放到任何其他的袋子中。</p>
11+
<p>请你从每个袋子中&nbsp;<strong>拿出</strong>&nbsp;一些豆子(也可以<strong>&nbsp;不拿出</strong>),使得剩下的 <strong>非空</strong> 袋子中(即 <strong>至少还有一颗</strong>&nbsp;魔法豆的袋子)魔法豆的数目&nbsp;<strong>相等</strong>。一旦把魔法豆从袋子中取出,你不能再将它放到任何袋子中。</p>
1212

13-
<p>请你返回你需要拿出魔法豆的 <strong>最少数目</strong>。</p>
13+
<p>请返回你需要拿出魔法豆的 <strong>最少数目</strong>。</p>
1414

1515
<p>&nbsp;</p>
1616

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

19-
<pre><b>输入:</b>beans = [4,<em><strong>1</strong></em>,6,5]
19+
<pre>
20+
<b>输入:</b>beans = [4,<u><strong>1</strong></u>,6,5]
2021
<b>输出:</b>4
2122
<b>解释:</b>
2223
- 我们从有 1 个魔法豆的袋子中拿出 1 颗魔法豆。
23-
剩下袋子中魔法豆的数目为:[4,<em><b>0</b></em>,6,5]
24+
剩下袋子中魔法豆的数目为:[4,<u><strong>0</strong></u>,6,5]
2425
- 然后我们从有 6 个魔法豆的袋子中拿出 2 个魔法豆。
25-
剩下袋子中魔法豆的数目为:[4,0,<em><strong>4</strong></em>,5]
26+
剩下袋子中魔法豆的数目为:[4,0,<u><strong>4</strong></u>,5]
2627
- 然后我们从有 5 个魔法豆的袋子中拿出 1 个魔法豆。
27-
剩下袋子中魔法豆的数目为:[4,0,4,<em><b>4</b></em>]
28+
剩下袋子中魔法豆的数目为:[4,0,4,<u><strong>4</strong></u>]
2829
总共拿出了 1 + 2 + 1 = 4 个魔法豆,剩下非空袋子中魔法豆的数目相等。
2930
没有比取出 4 个魔法豆更少的方案。
3031
</pre>
3132

3233
<p><strong>示例 2:</strong></p>
3334

34-
<pre><b>输入:</b>beans = [<em><strong>2</strong></em>,10,<em><strong>3</strong></em>,<em><strong>2</strong></em>]
35+
<pre>
36+
<b>输入:</b>beans = [<u><strong>2</strong></u>,10,<u><strong>3</strong></u>,<u><strong>2</strong></u>]
3537
<b>输出:</b>7
3638
<strong>解释:</strong>
3739
- 我们从有 2 个魔法豆的其中一个袋子中拿出 2 个魔法豆。
38-
剩下袋子中魔法豆的数目为:[<em><strong>0</strong></em>,10,3,2]
40+
剩下袋子中魔法豆的数目为:[<u><strong>0</strong></u>,10,3,2]
3941
- 然后我们从另一个有 2 个魔法豆的袋子中拿出 2 个魔法豆。
40-
剩下袋子中魔法豆的数目为:[0,10,3,<em><strong>0</strong></em>]
42+
剩下袋子中魔法豆的数目为:[0,10,3,<u><strong>0</strong></u>]
4143
- 然后我们从有 3 个魔法豆的袋子中拿出 3 个魔法豆。
42-
剩下袋子中魔法豆的数目为:[0,10,<em><strong>0</strong></em>,0]
44+
剩下袋子中魔法豆的数目为:[0,10,<u><strong>0</strong></u>,0]
4345
总共拿出了 2 + 2 + 3 = 7 个魔法豆,剩下非空袋子中魔法豆的数目相等。
4446
没有比取出 7 个魔法豆更少的方案。
4547
</pre>

solution/2600-2699/2652.Sum Multiples/README.md

+10-9
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,32 @@
1414

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

17-
<pre><strong>输入:</strong>n = 7
17+
<pre>
18+
<strong>输入:</strong>n = 7
1819
<strong>输出:</strong>21
19-
<strong>解释:</strong>在 <code>[1, 7]</code> 范围内能被 3、<code>5</code><code>7 整除的所有整数分别是</code><code> 3、5、6、7</code> 。数字之和为 <code>21</code>
20+
<strong>解释:</strong>在 <code>[1, 7]</code> 范围内能被 <code>3</code>、<code>5</code><code>7</code> 整除的所有整数分别是 <code>3</code>、<code>5</code>、<code>6</code>、<code>7</code> 。数字之和为 <code>21</code>。
2021
</pre>
2122

2223
<p><strong>示例 2:</strong></p>
2324

24-
<pre><strong>输入:</strong>n = 10
25+
<pre>
26+
<strong>输入:</strong>n = 10
2527
<strong>输出:</strong>40
26-
<strong>解释:</strong>在 <code>[1, 10]</code> 范围内能被 3、<code>5</code><code>7 整除的所有整数分别是</code><code> 3、5、6、7、9、10</code> 。数字之和为 <code>40</code>
28+
<strong>解释:</strong>在 <code>[1, 10]</code> 范围内能被 <code>3</code>、<code>5</code><code>7</code> 整除的所有整数分别是 <code>3</code>、<code>5</code>、<code>6</code>、<code>7</code>、<code>9</code>、<code>10</code> 。数字之和为 <code>40</code>。
2729
</pre>
2830

2931
<p><strong>示例 3:</strong></p>
3032

31-
<pre><strong>输入:</strong>n = 9
33+
<pre>
34+
<strong>输入:</strong>n = 9
3235
<strong>输出:</strong>30
33-
<strong>解释:</strong>在 <code>[1, 9]</code> 范围内能被 3、<code>5</code><code>7 整除的所有整数分别是</code><code> 3、5、6、7、9</code> 。数字之和为 <code>30</code>
36+
<strong>解释:</strong>在 <code>[1, 9]</code> 范围内能被 <code>3</code>、<code>5</code><code>7</code> 整除的所有整数分别是 <code>3</code>、<code>5</code>、<code>6</code>、<code>7</code>、<code>9</code> 。数字之和为 <code>30</code>。
3437
</pre>
3538

36-
<p>&nbsp;</p>
37-
3839
<p><strong>提示:</strong></p>
3940

4041
<ul>
41-
<li><code>1 &lt;= n &lt;= 10<sup>3</sup></code></li>
42+
<li>1 &lt;= n &lt;= 10<sup>3</sup></li>
4243
</ul>
4344

4445
## 解法

solution/2900-2999/2907.Maximum Profitable Triplets With Increasing Prices I/README.md

+25-23
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,54 @@
1-
# [2907. Maximum Profitable Triplets With Increasing Prices I](https://leetcode.cn/problems/maximum-profitable-triplets-with-increasing-prices-i)
1+
# [2907. 价格递增的最大利润三元组 I](https://leetcode.cn/problems/maximum-profitable-triplets-with-increasing-prices-i)
22

33
[English Version](/solution/2900-2999/2907.Maximum%20Profitable%20Triplets%20With%20Increasing%20Prices%20I/README_EN.md)
44

55
## 题目描述
66

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

9-
<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>
9+
<p>给定两个长度为 <code>n</code> 的 <b>下标从 0 开始</b>&nbsp;的数组 <code>prices</code> <code>profits</code>。商店里有 <code>n</code> 件商品,其中第 <code>i</code> 件商品的价格为 <code>prices[i]</code>,利润为 <code>profits[i]</code></p>
1010

11-
<p>We have to pick three items with the following condition:</p>
11+
<p>我们必须按照以下条件选择三件商品:</p>
1212

1313
<ul>
14-
<li><code>prices[i] &lt; prices[j] &lt; prices[k]</code> where <code>i &lt; j &lt; k</code>.</li>
14+
<li><code>prices[i] &lt; prices[j] &lt; prices[k]</code>,其中 <code>i &lt; j &lt; k</code></li>
1515
</ul>
1616

17-
<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>
17+
<p>如果我们选择满足上述条件的索引 <code>i</code><code>j</code> <code>k</code> 的商品,那么利润就是 <code>profits[i] + profits[j] + profits[k]</code></p>
1818

19-
<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>
19+
<p>返回我们能得到的最大利润,如果无法选择三件满足条件的商品,则返回 <code>-1</code></p>
2020

2121
<p>&nbsp;</p>
22-
<p><strong class="example">Example 1:</strong></p>
22+
23+
<p><strong class="example">示例 1:</strong></p>
2324

2425
<pre>
25-
<strong>Input:</strong> prices = [10,2,3,4], profits = [100,2,7,10]
26-
<strong>Output:</strong> 19
27-
<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.
28-
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].
29-
The answer would be sum of their profits which is 2 + 7 + 10 = 19.</pre>
26+
<b>输入:</b> prices = [10,2,3,4], profits = [100,2,7,10]
27+
<b>输出:</b> 19
28+
<b>解释:</b> 我们不能选择索引为 i=0 的商品,因为不存在索引 j 和 k 满足条件。
29+
所以我们能选择的唯一三元组是索引为 1,2 和 3 的商品,这是一个有效的选择,因为 prices[1] &lt; prices[2] &lt; prices[3]
30+
答案就是它们的利润之和,即 2 + 7 + 10 = 19</pre>
3031

31-
<p><strong class="example">Example 2:</strong></p>
32+
<p><b>示例 2:</b></p>
3233

3334
<pre>
34-
<strong>Input:</strong> prices = [1,2,3,4,5], profits = [1,5,3,4,6]
35-
<strong>Output:</strong> 15
36-
<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.
37-
Therefore the maximum profit we can get would be the 3 most profitable items which are indices 1, 3 and 4.
38-
The answer would be sum of their profits which is 5 + 4 + 6 = 15.</pre>
35+
<b>输入:</b> prices = [1,2,3,4,5], profits = [1,5,3,4,6]
36+
<b>输出:</b> 15
37+
<b>解释:</b> 我们可以选择任意三件商品,因为对于每个索引三元组 i,j 和 k 满足 i &lt; j &lt; k,条件都成立。
38+
因此我们能得到的最大利润就是三件最赚钱的商品,它们的索引分别是 1,3 和 4。
39+
答案就是它们的利润之和,即 5 + 4 + 6 = 15</pre>
3940

40-
<p><strong class="example">Example 3:</strong></p>
41+
<p><b>示例 3:</b></p>
4142

4243
<pre>
43-
<strong>Input:</strong> prices = [4,3,2,1], profits = [33,20,19,87]
44-
<strong>Output:</strong> -1
45-
<strong>Explanation:</strong> We can&#39;t select any triplet of indices such that the condition holds, so we return -1.
44+
<b>输入:</b> prices = [4,3,2,1], profits = [33,20,19,87]
45+
<b>输出:</b> -1
46+
<b>解释:</b> 我们不能选择任何满足条件的索引三元组,所以我们返回 -1。
4647
</pre>
4748

4849
<p>&nbsp;</p>
49-
<p><strong>Constraints:</strong></p>
50+
51+
<p><b>提示:</b></p>
5052

5153
<ul>
5254
<li><code>3 &lt;= prices.length == profits.length &lt;= 2000</code></li>

0 commit comments

Comments
 (0)