Skip to content

Commit

Permalink
feat: add solutions to lc problem: No.2912 (#1884)
Browse files Browse the repository at this point in the history
No.2912.Number of Ways to Reach Destination in the Grid

---------

Co-authored-by: Doocs Bot <[email protected]>
  • Loading branch information
yanglbme and idoocs authored Oct 26, 2023
1 parent c9c6625 commit 939d0df
Show file tree
Hide file tree
Showing 24 changed files with 617 additions and 123 deletions.
4 changes: 2 additions & 2 deletions solution/0100-0199/0101.Symmetric Tree/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
<p>&nbsp;</p>

<p><strong>示例 1:</strong></p>
<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;" />
<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;" />
<pre>
<strong>输入:</strong>root = [1,2,2,3,4,4,3]
<strong>输出:</strong>true
</pre>

<p><strong>示例 2:</strong></p>
<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;" />
<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;" />
<pre>
<strong>输入:</strong>root = [1,2,2,null,3,null,3]
<strong>输出:</strong>false
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [158. 用 Read4 读取 N 个字符 II](https://leetcode.cn/problems/read-n-characters-given-read4-ii-call-multiple-times)
# [158. 用 Read4 读取 N 个字符 II - 多次调用](https://leetcode.cn/problems/read-n-characters-given-read4-ii-call-multiple-times)

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

Expand Down
2 changes: 1 addition & 1 deletion solution/0500-0599/0560.Subarray Sum Equals K/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ passenger_id 是该表的主键。

<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>

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,42 @@

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

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

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

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

<p>&nbsp;</p>

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

<pre><b>输入:</b>beans = [4,<em><strong>1</strong></em>,6,5]
<pre>
<b>输入:</b>beans = [4,<u><strong>1</strong></u>,6,5]
<b>输出:</b>4
<b>解释:</b>
- 我们从有 1 个魔法豆的袋子中拿出 1 颗魔法豆。
剩下袋子中魔法豆的数目为:[4,<em><b>0</b></em>,6,5]
剩下袋子中魔法豆的数目为:[4,<u><strong>0</strong></u>,6,5]
- 然后我们从有 6 个魔法豆的袋子中拿出 2 个魔法豆。
剩下袋子中魔法豆的数目为:[4,0,<em><strong>4</strong></em>,5]
剩下袋子中魔法豆的数目为:[4,0,<u><strong>4</strong></u>,5]
- 然后我们从有 5 个魔法豆的袋子中拿出 1 个魔法豆。
剩下袋子中魔法豆的数目为:[4,0,4,<em><b>4</b></em>]
剩下袋子中魔法豆的数目为:[4,0,4,<u><strong>4</strong></u>]
总共拿出了 1 + 2 + 1 = 4 个魔法豆,剩下非空袋子中魔法豆的数目相等。
没有比取出 4 个魔法豆更少的方案。
</pre>

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

<pre><b>输入:</b>beans = [<em><strong>2</strong></em>,10,<em><strong>3</strong></em>,<em><strong>2</strong></em>]
<pre>
<b>输入:</b>beans = [<u><strong>2</strong></u>,10,<u><strong>3</strong></u>,<u><strong>2</strong></u>]
<b>输出:</b>7
<strong>解释:</strong>
- 我们从有 2 个魔法豆的其中一个袋子中拿出 2 个魔法豆。
剩下袋子中魔法豆的数目为:[<em><strong>0</strong></em>,10,3,2]
剩下袋子中魔法豆的数目为:[<u><strong>0</strong></u>,10,3,2]
- 然后我们从另一个有 2 个魔法豆的袋子中拿出 2 个魔法豆。
剩下袋子中魔法豆的数目为:[0,10,3,<em><strong>0</strong></em>]
剩下袋子中魔法豆的数目为:[0,10,3,<u><strong>0</strong></u>]
- 然后我们从有 3 个魔法豆的袋子中拿出 3 个魔法豆。
剩下袋子中魔法豆的数目为:[0,10,<em><strong>0</strong></em>,0]
剩下袋子中魔法豆的数目为:[0,10,<u><strong>0</strong></u>,0]
总共拿出了 2 + 2 + 3 = 7 个魔法豆,剩下非空袋子中魔法豆的数目相等。
没有比取出 7 个魔法豆更少的方案。
</pre>
Expand Down
19 changes: 10 additions & 9 deletions solution/2600-2699/2652.Sum Multiples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,32 @@

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

<pre><strong>输入:</strong>n = 7
<pre>
<strong>输入:</strong>n = 7
<strong>输出:</strong>21
<strong>解释:</strong>在 <code>[1, 7]</code> 范围内能被 3、<code>5</code><code>7 整除的所有整数分别是</code><code> 3、5、6、7</code> 。数字之和为 <code>21</code>
<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>。
</pre>

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

<pre><strong>输入:</strong>n = 10
<pre>
<strong>输入:</strong>n = 10
<strong>输出:</strong>40
<strong>解释:</strong>在 <code>[1, 10]</code> 范围内能被 3、<code>5</code><code>7 整除的所有整数分别是</code><code> 3、5、6、7、9、10</code> 。数字之和为 <code>40</code>
<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>。
</pre>

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

<pre><strong>输入:</strong>n = 9
<pre>
<strong>输入:</strong>n = 9
<strong>输出:</strong>30
<strong>解释:</strong>在 <code>[1, 9]</code> 范围内能被 3、<code>5</code><code>7 整除的所有整数分别是</code><code> 3、5、6、7、9</code> 。数字之和为 <code>30</code>
<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>。
</pre>

<p>&nbsp;</p>

<p><strong>提示:</strong></p>

<ul>
<li><code>1 &lt;= n &lt;= 10<sup>3</sup></code></li>
<li>1 &lt;= n &lt;= 10<sup>3</sup></li>
</ul>

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

[English Version](/solution/2900-2999/2907.Maximum%20Profitable%20Triplets%20With%20Increasing%20Prices%20I/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> 的 <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>

<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>,其中 <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>如果我们选择满足上述条件的索引 <code>i</code><code>j</code> <code>k</code> 的商品,那么利润就是 <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>返回我们能得到的最大利润,如果无法选择三件满足条件的商品,则返回 <code>-1</code></p>

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

<p><strong class="example">示例 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><b>示例 2:</b></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,j 和 k 满足 i &lt; j &lt; k,条件都成立。
因此我们能得到的最大利润就是三件最赚钱的商品,它们的索引分别是 1,3 和 4。
答案就是它们的利润之和,即 5 + 4 + 6 = 15</pre>

<p><strong class="example">Example 3:</strong></p>
<p><b>示例 3:</b></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;= 2000</code></li>
Expand Down
Loading

0 comments on commit 939d0df

Please sign in to comment.