Skip to content

feat: update lc problems #3826

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

Merged
merged 1 commit into from
Nov 30, 2024
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
4 changes: 3 additions & 1 deletion solution/0200-0299/0277.Find the Celebrity/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ tags:

<p>Now you want to find out who the celebrity is or verify that there is not one. You are only allowed to ask questions like: &quot;Hi, A. Do you know B?&quot; to get information about whether A knows B. You need to find out the celebrity (or verify there is not one) by asking as few questions as possible (in the asymptotic sense).</p>

<p>You are given a helper function <code>bool knows(a, b)</code> that tells you whether <code>a</code> knows <code>b</code>. Implement a function <code>int findCelebrity(n)</code>. There will be exactly one celebrity if they are at the party.</p>
<p>You are given an integer <code>n</code> and a helper function <code>bool knows(a, b)</code> that tells you whether <code>a</code> knows <code>b</code>. Implement a function <code>int findCelebrity(n)</code>. There will be exactly one celebrity if they are at the party.</p>

<p>Return <em>the celebrity&#39;s label if there is a celebrity at the party</em>. If there is no celebrity, return <code>-1</code>.</p>

<p><strong>Note</strong> that the <code>n x n</code> 2D array <code>graph</code> given as input is <strong>not</strong> directly available to you, and instead <strong>only</strong> accessible through the helper function <code>knows</code>. <code>graph[i][j] == 1</code> represents person <code>i</code> knows person <code>j</code>, wherease <code>graph[i][j] == 0</code> represents person <code>j</code> does not know person <code>i</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0200-0299/0277.Find%20the%20Celebrity/images/g1.jpg" style="width: 224px; height: 145px;" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ tags:
<li><code>1 &lt;= nestedList.length &lt;= 50</code></li>
<li>嵌套列表中整数的值在范围 <code>[-100, 100]</code></li>
<li>任意整数的最大 <strong>深度</strong> 小于等于 <code>50</code></li>
<li>没有空列表</li>
</ul>

<!-- description:end -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ tags:
<li><code>1 &lt;= nestedList.length &lt;= 50</code></li>
<li>The values of the integers in the nested list is in the range <code>[-100, 100]</code>.</li>
<li>The maximum <strong>depth</strong> of any integer is less than or equal to <code>50</code>.</li>
<li>There are no empty lists.</li>
</ul>

<!-- description:end -->
Expand Down
3 changes: 3 additions & 0 deletions solution/0700-0799/0773.Sliding Puzzle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ difficulty: 困难
edit_url: https://github.com/doocs/leetcode/edit/main/solution/0700-0799/0773.Sliding%20Puzzle/README.md
tags:
- 广度优先搜索
- 记忆化搜索
- 数组
- 动态规划
- 回溯
- 矩阵
---

Expand Down
3 changes: 3 additions & 0 deletions solution/0700-0799/0773.Sliding Puzzle/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ difficulty: Hard
edit_url: https://github.com/doocs/leetcode/edit/main/solution/0700-0799/0773.Sliding%20Puzzle/README_EN.md
tags:
- Breadth-First Search
- Memoization
- Array
- Dynamic Programming
- Backtracking
- Matrix
---

Expand Down
2 changes: 1 addition & 1 deletion solution/0700-0799/0782.Transform to Chessboard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ tags:

<!-- description:start -->

<p>一个&nbsp;<code>n x n</code>&nbsp;的二维网络&nbsp;<code>board</code>&nbsp;仅由&nbsp;<code>0</code>&nbsp;和&nbsp;<code>1</code>&nbsp;组成&nbsp;。每次移动,你能任意交换两列或是两行的位置。</p>
<p>一个&nbsp;<code>n x n</code>&nbsp;的二维网络&nbsp;<code>board</code>&nbsp;仅由&nbsp;<code>0</code>&nbsp;和&nbsp;<code>1</code>&nbsp;组成&nbsp;。每次移动,你能交换任意两列或是两行的位置。</p>

<p>返回 <em>将这个矩阵变为<strong>&nbsp; “棋盘”&nbsp;&nbsp;</strong>所需的最小移动次数&nbsp;</em>。如果不存在可行的变换,输出 <code>-1</code>。</p>

Expand Down
1 change: 1 addition & 0 deletions solution/1600-1699/1683.Invalid Tweets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ tags:
| content | varchar |
+----------------+---------+
在 SQL 中,tweet_id 是这个表的主键。
content 只包含美式键盘上的字符,不包含其它特殊字符。
这个表包含某社交媒体 App 中所有的推文。</pre>

<p>&nbsp;</p>
Expand Down
1 change: 1 addition & 0 deletions solution/1600-1699/1683.Invalid Tweets/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ tags:
| content | varchar |
+----------------+---------+
tweet_id is the primary key (column with unique values) for this table.
content consists of characters on an American Keyboard, and no other special characters.
This table contains all the tweets in a social media app.
</pre>

Expand Down
65 changes: 34 additions & 31 deletions solution/1800-1899/1861.Rotating the Box/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,68 +20,71 @@ tags:

<!-- description:start -->

<p>给你一个 <code>m x n</code> 的字符矩阵 <code>box</code> ,它表示一个箱子的侧视图。箱子的每一个格子可能为:</p>
<p>给你一个&nbsp;<code>m x n</code>&nbsp;的字符矩阵&nbsp;<code>boxGrid</code>&nbsp;,它表示一个箱子的侧视图。箱子的每一个格子可能为:</p>

<ul>
<li><code>'#'</code> 表示石头</li>
<li><code>'*'</code> 表示固定的障碍物</li>
<li><code>'.'</code> 表示空位置</li>
<li><code>'#'</code>&nbsp;表示石头</li>
<li><code>'*'</code>&nbsp;表示固定的障碍物</li>
<li><code>'.'</code>&nbsp;表示空位置</li>
</ul>

<p>这个箱子被 <strong>顺时针旋转 90 度</strong> ,由于重力原因,部分石头的位置会发生改变。每个石头会垂直掉落,直到它遇到障碍物,另一个石头或者箱子的底部。重力 <strong>不会</strong> 影响障碍物的位置,同时箱子旋转不会产生<strong>惯性</strong> ,也就是说石头的水平位置不会发生改变。</p>
<p>这个箱子被 <strong>顺时针旋转 90 度</strong>&nbsp;,由于重力原因,部分石头的位置会发生改变。每个石头会垂直掉落,直到它遇到障碍物,另一个石头或者箱子的底部。重力 <strong>不会</strong>&nbsp;影响障碍物的位置,同时箱子旋转不会产生<strong>惯性</strong>&nbsp;,也就是说石头的水平位置不会发生改变。</p>

<p>题目保证初始时 <code>box</code> 中的石头要么在一个障碍物上,要么在另一个石头上,要么在箱子的底部。</p>
<p>题目保证初始时&nbsp;<code>boxGrid</code>&nbsp;中的石头要么在一个障碍物上,要么在另一个石头上,要么在箱子的底部。</p>

<p>请你返回一个<em> </em><code>n x m</code>的矩阵,表示按照上述旋转后,箱子内的结果。</p>
<p>请你返回一个<em>&nbsp;</em><code>n x m</code>&nbsp;的矩阵,表示按照上述旋转后,箱子内的结果。</p>

<p> </p>
<p>&nbsp;</p>

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

<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1800-1899/1861.Rotating%20the%20Box/images/rotatingtheboxleetcodewithstones.png" style="width: 300px; height: 150px;"></p>
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1800-1899/1861.Rotating%20the%20Box/images/rotatingtheboxleetcodewithstones.png" style="width: 300px; height: 150px;" /></p>

<pre><b>输入:</b>box = [["#",".","#"]]
<pre>
<b>输入:</b>box = [["#",".","#"]]
<b>输出:</b>[["."],
  ["#"],
  ["#"]]
&nbsp; ["#"],
&nbsp; ["#"]]
</pre>

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

<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1800-1899/1861.Rotating%20the%20Box/images/rotatingtheboxleetcode2withstones.png" style="width: 375px; height: 195px;"></p>
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1800-1899/1861.Rotating%20the%20Box/images/rotatingtheboxleetcode2withstones.png" style="width: 375px; height: 195px;" /></p>

<pre><b>输入:</b>box = [["#",".","*","."],
  ["#","#","*","."]]
<pre>
<b>输入:</b>box = [["#",".","*","."],
&nbsp; ["#","#","*","."]]
<b>输出:</b>[["#","."],
  ["#","#"],
  ["*","*"],
  [".","."]]
&nbsp; ["#","#"],
&nbsp; ["*","*"],
&nbsp; [".","."]]
</pre>

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

<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1800-1899/1861.Rotating%20the%20Box/images/rotatingtheboxleetcode3withstone.png" style="width: 400px; height: 218px;"></p>
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1800-1899/1861.Rotating%20the%20Box/images/rotatingtheboxleetcode3withstone.png" style="width: 400px; height: 218px;" /></p>

<pre><b>输入:</b>box = [["#","#","*",".","*","."],
  ["#","#","#","*",".","."],
  ["#","#","#",".","#","."]]
<pre>
<b>输入:</b>box = [["#","#","*",".","*","."],
&nbsp; ["#","#","#","*",".","."],
&nbsp; ["#","#","#",".","#","."]]
<b>输出:</b>[[".","#","#"],
  [".","#","#"],
  ["#","#","*"],
  ["#","*","."],
  ["#",".","*"],
  ["#",".","."]]
&nbsp; [".","#","#"],
&nbsp; ["#","#","*"],
&nbsp; ["#","*","."],
&nbsp; ["#",".","*"],
&nbsp; ["#",".","."]]
</pre>

<p> </p>
<p>&nbsp;</p>

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

<ul>
<li><code>m == box.length</code></li>
<li><code>n == box[i].length</code></li>
<li><code>m == boxGrid.length</code></li>
<li><code>n == boxGrid[i].length</code></li>
<li><code>1 &lt;= m, n &lt;= 500</code></li>
<li><code>box[i][j]</code> 只可能是 <code>'#'</code> ,<code>'*'</code> 或者 <code>'.'</code> 。</li>
<li><code>boxGrid[i][j]</code>&nbsp;只可能是&nbsp;<code>'#'</code>&nbsp;,<code>'*'</code>&nbsp;或者&nbsp;<code>'.'</code>&nbsp;。</li>
</ul>

<!-- description:end -->
Expand Down
57 changes: 12 additions & 45 deletions solution/1800-1899/1861.Rotating the Box/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,102 +20,69 @@ tags:

<!-- description:start -->

<p>You are given an <code>m x n</code> matrix of characters <code>box</code> representing a side-view of a box. Each cell of the box is one of the following:</p>
<p>You are given an <code>m x n</code> matrix of characters <code>boxGrid</code> representing a side-view of a box. Each cell of the box is one of the following:</p>

<ul>

<li>A stone <code>&#39;#&#39;</code></li>

<li>A stationary obstacle <code>&#39;*&#39;</code></li>

<li>Empty <code>&#39;.&#39;</code></li>

<li>A stone <code>&#39;#&#39;</code></li>
<li>A stationary obstacle <code>&#39;*&#39;</code></li>
<li>Empty <code>&#39;.&#39;</code></li>
</ul>

<p>The box is rotated <strong>90 degrees clockwise</strong>, causing some of the stones to fall due to gravity. Each stone falls down until it lands on an obstacle, another stone, or the bottom of the box. Gravity <strong>does not</strong> affect the obstacles&#39; positions, and the inertia from the box&#39;s rotation <strong>does not </strong>affect the stones&#39; horizontal positions.</p>

<p>It is <strong>guaranteed</strong> that each stone in <code>box</code> rests on an obstacle, another stone, or the bottom of the box.</p>
<p>It is <strong>guaranteed</strong> that each stone in <code>boxGrid</code> rests on an obstacle, another stone, or the bottom of the box.</p>

<p>Return <em>an </em><code>n x m</code><em> matrix representing the box after the rotation described above</em>.</p>

<p>&nbsp;</p>

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

<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1800-1899/1861.Rotating%20the%20Box/images/rotatingtheboxleetcodewithstones.png" style="width: 300px; height: 150px;" /></p>

<pre>

<strong>Input:</strong> box = [[&quot;#&quot;,&quot;.&quot;,&quot;#&quot;]]

<strong>Input:</strong> boxGrid = [[&quot;#&quot;,&quot;.&quot;,&quot;#&quot;]]
<strong>Output:</strong> [[&quot;.&quot;],

&nbsp; [&quot;#&quot;],

&nbsp; [&quot;#&quot;]]

</pre>

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

<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1800-1899/1861.Rotating%20the%20Box/images/rotatingtheboxleetcode2withstones.png" style="width: 375px; height: 195px;" /></p>

<pre>

<strong>Input:</strong> box = [[&quot;#&quot;,&quot;.&quot;,&quot;*&quot;,&quot;.&quot;],

<strong>Input:</strong> boxGrid = [[&quot;#&quot;,&quot;.&quot;,&quot;*&quot;,&quot;.&quot;],
&nbsp; [&quot;#&quot;,&quot;#&quot;,&quot;*&quot;,&quot;.&quot;]]

<strong>Output:</strong> [[&quot;#&quot;,&quot;.&quot;],

&nbsp; [&quot;#&quot;,&quot;#&quot;],

&nbsp; [&quot;*&quot;,&quot;*&quot;],

&nbsp; [&quot;.&quot;,&quot;.&quot;]]

</pre>

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

<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1800-1899/1861.Rotating%20the%20Box/images/rotatingtheboxleetcode3withstone.png" style="width: 400px; height: 218px;" /></p>

<pre>

<strong>Input:</strong> box = [[&quot;#&quot;,&quot;#&quot;,&quot;*&quot;,&quot;.&quot;,&quot;*&quot;,&quot;.&quot;],

<strong>Input:</strong> boxGrid = [[&quot;#&quot;,&quot;#&quot;,&quot;*&quot;,&quot;.&quot;,&quot;*&quot;,&quot;.&quot;],
&nbsp; [&quot;#&quot;,&quot;#&quot;,&quot;#&quot;,&quot;*&quot;,&quot;.&quot;,&quot;.&quot;],

&nbsp; [&quot;#&quot;,&quot;#&quot;,&quot;#&quot;,&quot;.&quot;,&quot;#&quot;,&quot;.&quot;]]

<strong>Output:</strong> [[&quot;.&quot;,&quot;#&quot;,&quot;#&quot;],

&nbsp; [&quot;.&quot;,&quot;#&quot;,&quot;#&quot;],

&nbsp; [&quot;#&quot;,&quot;#&quot;,&quot;*&quot;],

&nbsp; [&quot;#&quot;,&quot;*&quot;,&quot;.&quot;],

&nbsp; [&quot;#&quot;,&quot;.&quot;,&quot;*&quot;],

&nbsp; [&quot;#&quot;,&quot;.&quot;,&quot;.&quot;]]

</pre>

<p>&nbsp;</p>

<p><strong>Constraints:</strong></p>

<ul>

<li><code>m == box.length</code></li>

<li><code>n == box[i].length</code></li>

<li><code>1 &lt;= m, n &lt;= 500</code></li>

<li><code>box[i][j]</code> is either <code>&#39;#&#39;</code>, <code>&#39;*&#39;</code>, or <code>&#39;.&#39;</code>.</li>

<li><code>m == boxGrid.length</code></li>
<li><code>n == boxGrid[i].length</code></li>
<li><code>1 &lt;= m, n &lt;= 500</code></li>
<li><code>boxGrid[i][j]</code> is either <code>&#39;#&#39;</code>, <code>&#39;*&#39;</code>, or <code>&#39;.&#39;</code>.</li>
</ul>

<!-- description:end -->
Expand Down
25 changes: 13 additions & 12 deletions solution/1800-1899/1891.Cutting Ribbons/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,26 @@ tags:

<!-- description:start -->

<p>给定一个整数数组 <code>ribbons</code> 和一个整数 <code>k</code>,数组每项 <code>ribbons[i]</code> 表示第 <code>i</code> 条绳子的长度。对于每条绳子,你可以将任意切割成一系列长度为<strong>正整数</strong>的部分,或者选择不进行切割。</p>
<p>给定一个整数数组&nbsp;<code>ribbons</code>&nbsp;和一个整数 <code>k</code>,数组每项&nbsp;<code>ribbons[i]</code>&nbsp;表示第&nbsp;<code>i</code>&nbsp;条绳子的长度。对于每条绳子,你可以将任意切割成一系列长度为&nbsp;<strong>正整数&nbsp;</strong>的部分,或者选择不进行切割。</p>

<p>例如,如果给你一条长度为 <code>4</code> 的绳子,你可以:</p>

<ul>
<li>保持绳子的长度为 <code>4</code> 不变;</li>
<li>切割成一条长度为 <code>3</code> 和一条长度为 <code>1</code> 的绳子;</li>
<li>切割成两条长度为 <code>2</code> 的绳子;</li>
<li>切割成一条长度为 <code>2</code> 和两条长度为 <code>1</code> 的绳子;</li>
<li>切割成四条长度为 <code>1</code> 的绳子。</li>
<li>切割成两条长度为 <code>2</code>&nbsp;的绳子;</li>
<li>切割成一条长度为 <code>2</code>&nbsp;和两条长度为 <code>1</code> 的绳子;</li>
<li>切割成四条长度为 <code>1</code>&nbsp;的绳子。</li>
</ul>

<p>你的任务是最终得到 <code>k</code> 条完全一样的绳子,他们的长度均为<strong>相同的正整数</strong>。如果绳子切割后有剩余,你可以直接舍弃掉多余的部分。</p>
<p>你的任务是找出最大 <code>x</code> 值,要求满足可以裁切出恰好 <code>k</code> 条长度均为 <code>x</code> 的绳子。你可以丢弃裁切后剩余的任意长度的绳子。如果不可能切割出&nbsp;<code>k</code> 条相同长度的绳子,返回 0。</p>

<p>对于这 <code>k</code> 根绳子,返回你能得到的绳子<strong>最大</strong>长度;如果你无法得到 <code>k</code> 根相同长度的绳子,返回 <code>0</code>。</p>

<p> </p>
<p>&nbsp;</p>

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

<pre><strong>输入:</strong> ribbons = [9,7,5], k = 3
<pre>
<strong>输入:</strong> ribbons = [9,7,5], k = 3
<strong>输出:</strong> 5
<strong>解释:</strong>
- 把第一条绳子切成两部分,一条长度为 5,一条长度为 4;
Expand All @@ -47,7 +46,8 @@ tags:

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

<pre><strong>输入:</strong> ribbons = [7,5,9], k = 4
<pre>
<strong>输入:</strong> ribbons = [7,5,9], k = 4
<strong>输出:</strong> 4
<strong>解释:</strong>
- 把第一条绳子切成两部分,一条长度为 4,一条长度为 3;
Expand All @@ -58,12 +58,13 @@ tags:

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

<pre><strong>输入:</strong> ribbons = [5,7,9], k = 22
<pre>
<strong>输入:</strong> ribbons = [5,7,9], k = 22
<strong>输出:</strong> 0
<strong>解释:</strong> 由于绳子长度需要为正整数,你无法得到 22 条长度相同的绳子。
</pre>

<p> </p>
<p>&nbsp;</p>

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

Expand Down
4 changes: 1 addition & 3 deletions solution/1800-1899/1891.Cutting Ribbons/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ tags:

</ul>

<p>Your goal is to obtain <code>k</code> ribbons of all the <strong>same positive integer length</strong>. You are allowed to throw away any excess ribbon as a result of cutting.</p>

<p>Return <em>the <strong>maximum</strong> possible positive integer length that you can obtain </em><code>k</code><em> ribbons of</em><em>, or </em><code>0</code><em> if you cannot obtain </em><code>k</code><em> ribbons of the same length</em>.</p>
<p>Your task is to determine the <strong>maximum</strong> length of ribbon, <code>x</code>, that allows you to cut <em>exactly</em> <code>k</code> ribbons, each of length <code>x</code>. You can discard any leftover ribbon from the cuts. If it is <strong>impossible</strong> to cut <code>k</code> ribbons of the same length, return 0.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ tags:
<li><code>n == positions.length</code></li>
<li><code>1 &lt;= n &lt;= 4</code></li>
<li><code>pieces</code>&nbsp;只包含字符串&nbsp;<code>"rook"</code>&nbsp;,<code>"queen"</code>&nbsp;和&nbsp;<code>"bishop"</code>&nbsp;。</li>
<li>棋盘上总共最多只有一个后。</li>
<li>棋盘上最多只有一个后。</li>
<li><code>1 &lt;= r<sub>i</sub>, c<sub>i</sub> &lt;= 8</code></li>
<li>每一个&nbsp;<code>positions[i]</code>&nbsp;互不相同。</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/2000-2099/2064.Mi
rating: 1885
source: 第 266 场周赛 Q3
tags:
- 贪心
- 数组
- 二分查找
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/2000-2099/2064.Mi
rating: 1885
source: Weekly Contest 266 Q3
tags:
- Greedy
- Array
- Binary Search
---
Expand Down
Loading
Loading