Skip to content

Commit 078c02d

Browse files
authored
feat: add new lc problems (#4467)
1 parent ba46ac8 commit 078c02d

File tree

150 files changed

+3630
-172
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+3630
-172
lines changed

solution/0100-0199/0195.Tenth Line/README_EN.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,41 @@ tags:
2323
<p>Assume that <code>file.txt</code> has the following content:</p>
2424

2525
<pre>
26+
2627
Line 1
28+
2729
Line 2
30+
2831
Line 3
32+
2933
Line 4
34+
3035
Line 5
36+
3137
Line 6
38+
3239
Line 7
40+
3341
Line 8
42+
3443
Line 9
44+
3545
Line 10
46+
3647
</pre>
3748

3849
<p>Your script should output the tenth line, which is:</p>
3950

4051
<pre>
52+
4153
Line 10
54+
4255
</pre>
4356

4457
<div class="spoilers"><b>Note:</b><br />
58+
4559
1. If the file contains less than 10 lines, what should you output?<br />
60+
4661
2. There&#39;s at least three different solutions. Try to explore all possibilities.</div>
4762

4863
<!-- description:end -->

solution/0700-0799/0799.Champagne Tower/README_EN.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,51 @@ tags:
2727
<p>Now after pouring some non-negative integer cups of champagne, return how full the <code>j<sup>th</sup></code> glass in the <code>i<sup>th</sup></code> row is (both <code>i</code> and <code>j</code> are 0-indexed.)</p>
2828

2929
<p>&nbsp;</p>
30+
3031
<p><strong class="example">Example 1:</strong></p>
3132

3233
<pre>
34+
3335
<strong>Input:</strong> poured = 1, query_row = 1, query_glass = 1
36+
3437
<strong>Output:</strong> 0.00000
38+
3539
<strong>Explanation:</strong> We poured 1 cup of champange to the top glass of the tower (which is indexed as (0, 0)). There will be no excess liquid so all the glasses under the top glass will remain empty.
40+
3641
</pre>
3742

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

4045
<pre>
46+
4147
<strong>Input:</strong> poured = 2, query_row = 1, query_glass = 1
48+
4249
<strong>Output:</strong> 0.50000
50+
4351
<strong>Explanation:</strong> We poured 2 cups of champange to the top glass of the tower (which is indexed as (0, 0)). There is one cup of excess liquid. The glass indexed as (1, 0) and the glass indexed as (1, 1) will share the excess liquid equally, and each will get half cup of champange.
52+
4453
</pre>
4554

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

4857
<pre>
58+
4959
<strong>Input:</strong> poured = 100000009, query_row = 33, query_glass = 17
60+
5061
<strong>Output:</strong> 1.00000
62+
5163
</pre>
5264

5365
<p>&nbsp;</p>
66+
5467
<p><strong>Constraints:</strong></p>
5568

5669
<ul>
57-
<li><code>0 &lt;=&nbsp;poured &lt;= 10<sup>9</sup></code></li>
58-
<li><code>0 &lt;= query_glass &lt;= query_row&nbsp;&lt; 100</code></li>
70+
71+
<li><code>0 &lt;=&nbsp;poured &lt;= 10<sup>9</sup></code></li>
72+
73+
<li><code>0 &lt;= query_glass &lt;= query_row&nbsp;&lt; 100</code></li>
74+
5975
</ul>
6076

6177
<!-- description:end -->

solution/1000-1099/1061.Lexicographically Smallest Equivalent String/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,23 @@ tags:
4444
<pre>
4545
<strong>输入:</strong>s1 = "parker", s2 = "morris", baseStr = "parser"
4646
<strong>输出:</strong>"makkek"
47-
<strong>解释:</strong>根据 <code>A</code> 和 <code>B 中的等价信息,</code>我们可以将这些字符分为 <code>[m,p]</code>, <code>[a,o]</code>, <code>[k,r,s]</code>, <code>[e,i] 共 4 组</code>。每组中的字符都是等价的,并按字典序排列。所以答案是 <code>"makkek"</code>。
47+
<strong>解释:</strong>根据 <code>A</code> 和 <code>B</code> 中的等价信息,我们可以将这些字符分为 <code>[m,p]</code>, <code>[a,o]</code>, <code>[k,r,s]</code>, <code>[e,i]</code> 共 4 组。每组中的字符都是等价的,并按字典序排列。所以答案是 <code>"makkek"</code>。
4848
</pre>
4949

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

5252
<pre>
5353
<strong>输入:</strong>s1 = "hello", s2 = "world", baseStr = "hold"
5454
<strong>输出:</strong>"hdld"
55-
<strong>解释:</strong>根据 <code>A</code> 和 <code>B 中的等价信息,</code>我们可以将这些字符分为 <code>[h,w]</code>, <code>[d,e,o]</code>, <code>[l,r] 共 3 组</code>。所以只有 S 中的第二个字符 <code>'o'</code> 变成 <code>'d',最后答案为 </code><code>"hdld"</code>。
55+
<strong>解释:</strong>根据 <code>A</code> 和 <code>B</code> 中的等价信息,我们可以将这些字符分为 <code>[h,w]</code>, <code>[d,e,o]</code>, <code>[l,r]</code> 共 3 组。所以只有 S 中的第二个字符 <code>'o'</code> 变成 <code>'d'</code>,最后答案为 <code>"hdld"</code>。
5656
</pre>
5757

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

6060
<pre>
6161
<strong>输入:</strong>s1 = "leetcode", s2 = "programs", baseStr = "sourcecode"
6262
<strong>输出:</strong>"aauaaaaada"
63-
<strong>解释:</strong>我们可以把 AB 中的等价字符分为 <code>[a,o,e,r,s,c]</code>, <code>[l,p]</code>, <code>[g,t]</code> 和 <code>[d,m] 共 4 组</code>,因此 <code>S</code> 中除了 <code>'u'</code> 和 <code>'d'</code> 之外的所有字母都转化成了 <code>'a'</code>,最后答案为 <code>"aauaaaaada"</code>。
63+
<strong>解释:</strong>我们可以把 <code>A</code><code>B</code> 中的等价字符分为 <code>[a,o,e,r,s,c]</code>, <code>[l,p]</code>, <code>[g,t]</code> 和 <code>[d,m]</code> 共 4 组,因此 <code>S</code> 中除了 <code>'u'</code> 和 <code>'d'</code> 之外的所有字母都转化成了 <code>'a'</code>,最后答案为 <code>"aauaaaaada"</code>。
6464
</pre>
6565

6666
<p>&nbsp;</p>

solution/1000-1099/1070.Product Sales Analysis III/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ tags:
3131
(sale_id, year) 是这张表的主键(具有唯一值的列的组合)。
3232
product_id 是产品表的外键(reference 列)。
3333
这张表的每一行都表示:编号 product_id 的产品在某一年的销售额。
34+
一个产品可能在同一年内有多个销售条目。
3435
请注意,价格是按每单位计的。
3536
</pre>
3637

solution/1100-1199/1108.Defanging an IP Address/README_EN.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,29 @@ tags:
2323
<p>A <em>defanged&nbsp;IP address</em>&nbsp;replaces every period <code>&quot;.&quot;</code> with <code>&quot;[.]&quot;</code>.</p>
2424

2525
<p>&nbsp;</p>
26+
2627
<p><strong class="example">Example 1:</strong></p>
28+
2729
<pre><strong>Input:</strong> address = "1.1.1.1"
30+
2831
<strong>Output:</strong> "1[.]1[.]1[.]1"
32+
2933
</pre><p><strong class="example">Example 2:</strong></p>
34+
3035
<pre><strong>Input:</strong> address = "255.100.50.0"
36+
3137
<strong>Output:</strong> "255[.]100[.]50[.]0"
38+
3239
</pre>
40+
3341
<p>&nbsp;</p>
42+
3443
<p><strong>Constraints:</strong></p>
3544

3645
<ul>
37-
<li>The given <code>address</code> is a valid IPv4 address.</li>
46+
47+
<li>The given <code>address</code> is a valid IPv4 address.</li>
48+
3849
</ul>
3950

4051
<!-- description:end -->

solution/1100-1199/1111.Maximum Nesting Depth of Two Valid Parentheses Strings/README_EN.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,25 @@ tags:
2222
<p>A string is a <em>valid parentheses string</em>&nbsp;(denoted VPS) if and only if it consists of <code>&quot;(&quot;</code> and <code>&quot;)&quot;</code> characters only, and:</p>
2323

2424
<ul>
25-
<li>It is the empty string, or</li>
26-
<li>It can be written as&nbsp;<code>AB</code>&nbsp;(<code>A</code>&nbsp;concatenated with&nbsp;<code>B</code>), where&nbsp;<code>A</code>&nbsp;and&nbsp;<code>B</code>&nbsp;are VPS&#39;s, or</li>
27-
<li>It can be written as&nbsp;<code>(A)</code>, where&nbsp;<code>A</code>&nbsp;is a VPS.</li>
25+
26+
<li>It is the empty string, or</li>
27+
28+
<li>It can be written as&nbsp;<code>AB</code>&nbsp;(<code>A</code>&nbsp;concatenated with&nbsp;<code>B</code>), where&nbsp;<code>A</code>&nbsp;and&nbsp;<code>B</code>&nbsp;are VPS&#39;s, or</li>
29+
30+
<li>It can be written as&nbsp;<code>(A)</code>, where&nbsp;<code>A</code>&nbsp;is a VPS.</li>
31+
2832
</ul>
2933

3034
<p>We can&nbsp;similarly define the <em>nesting depth</em> <code>depth(S)</code> of any VPS <code>S</code> as follows:</p>
3135

3236
<ul>
33-
<li><code>depth(&quot;&quot;) = 0</code></li>
34-
<li><code>depth(A + B) = max(depth(A), depth(B))</code>, where <code>A</code> and <code>B</code> are VPS&#39;s</li>
35-
<li><code>depth(&quot;(&quot; + A + &quot;)&quot;) = 1 + depth(A)</code>, where <code>A</code> is a VPS.</li>
37+
38+
<li><code>depth(&quot;&quot;) = 0</code></li>
39+
40+
<li><code>depth(A + B) = max(depth(A), depth(B))</code>, where <code>A</code> and <code>B</code> are VPS&#39;s</li>
41+
42+
<li><code>depth(&quot;(&quot; + A + &quot;)&quot;) = 1 + depth(A)</code>, where <code>A</code> is a VPS.</li>
43+
3644
</ul>
3745

3846
<p>For example,&nbsp; <code>&quot;&quot;</code>,&nbsp;<code>&quot;()()&quot;</code>, and&nbsp;<code>&quot;()(()())&quot;</code>&nbsp;are VPS&#39;s (with nesting depths 0, 1, and 2), and <code>&quot;)(&quot;</code> and <code>&quot;(()&quot;</code> are not VPS&#39;s.</p>

solution/1100-1199/1138.Alphabet Board Path/README_EN.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,49 @@ tags:
2828
<p>We may make the following moves:</p>
2929

3030
<ul>
31-
<li><code>&#39;U&#39;</code> moves our position up one row, if the position exists on the board;</li>
32-
<li><code>&#39;D&#39;</code> moves our position down one row, if the position exists on the board;</li>
33-
<li><code>&#39;L&#39;</code> moves our position left one column, if the position exists on the board;</li>
34-
<li><code>&#39;R&#39;</code> moves our position right one column, if the position exists on the board;</li>
35-
<li><code>&#39;!&#39;</code>&nbsp;adds the character <code>board[r][c]</code> at our current position <code>(r, c)</code>&nbsp;to the&nbsp;answer.</li>
31+
32+
<li><code>&#39;U&#39;</code> moves our position up one row, if the position exists on the board;</li>
33+
34+
<li><code>&#39;D&#39;</code> moves our position down one row, if the position exists on the board;</li>
35+
36+
<li><code>&#39;L&#39;</code> moves our position left one column, if the position exists on the board;</li>
37+
38+
<li><code>&#39;R&#39;</code> moves our position right one column, if the position exists on the board;</li>
39+
40+
<li><code>&#39;!&#39;</code>&nbsp;adds the character <code>board[r][c]</code> at our current position <code>(r, c)</code>&nbsp;to the&nbsp;answer.</li>
41+
3642
</ul>
3743

3844
<p>(Here, the only positions that exist on the board are positions with letters on them.)</p>
3945

4046
<p>Return a sequence of moves that makes our answer equal to <code>target</code>&nbsp;in the minimum number of moves.&nbsp; You may return any path that does so.</p>
4147

4248
<p>&nbsp;</p>
49+
4350
<p><strong class="example">Example 1:</strong></p>
51+
4452
<pre><strong>Input:</strong> target = "leet"
53+
4554
<strong>Output:</strong> "DDR!UURRR!!DDD!"
55+
4656
</pre><p><strong class="example">Example 2:</strong></p>
57+
4758
<pre><strong>Input:</strong> target = "code"
59+
4860
<strong>Output:</strong> "RR!DDRR!UUL!R!"
61+
4962
</pre>
63+
5064
<p>&nbsp;</p>
65+
5166
<p><strong>Constraints:</strong></p>
5267

5368
<ul>
54-
<li><code>1 &lt;= target.length &lt;= 100</code></li>
55-
<li><code>target</code> consists only of English lowercase letters.</li>
69+
70+
<li><code>1 &lt;= target.length &lt;= 100</code></li>
71+
72+
<li><code>target</code> consists only of English lowercase letters.</li>
73+
5674
</ul>
5775

5876
<!-- description:end -->

solution/1100-1199/1139.Largest 1-Bordered Square/README_EN.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,39 @@ tags:
2323
<p>Given a 2D <code>grid</code> of <code>0</code>s and <code>1</code>s, return the number of elements in&nbsp;the largest <strong>square</strong>&nbsp;subgrid that has all <code>1</code>s on its <strong>border</strong>, or <code>0</code> if such a subgrid&nbsp;doesn&#39;t exist in the <code>grid</code>.</p>
2424

2525
<p>&nbsp;</p>
26+
2627
<p><strong class="example">Example 1:</strong></p>
2728

2829
<pre>
30+
2931
<strong>Input:</strong> grid = [[1,1,1],[1,0,1],[1,1,1]]
32+
3033
<strong>Output:</strong> 9
34+
3135
</pre>
3236

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

3539
<pre>
40+
3641
<strong>Input:</strong> grid = [[1,1,0,0]]
42+
3743
<strong>Output:</strong> 1
44+
3845
</pre>
3946

4047
<p>&nbsp;</p>
48+
4149
<p><strong>Constraints:</strong></p>
4250

4351
<ul>
44-
<li><code>1 &lt;= grid.length &lt;= 100</code></li>
45-
<li><code>1 &lt;= grid[0].length &lt;= 100</code></li>
46-
<li><code>grid[i][j]</code> is <code>0</code> or <code>1</code></li>
52+
53+
<li><code>1 &lt;= grid.length &lt;= 100</code></li>
54+
55+
<li><code>1 &lt;= grid[0].length &lt;= 100</code></li>
56+
57+
<li><code>grid[i][j]</code> is <code>0</code> or <code>1</code></li>
58+
4759
</ul>
4860

4961
<!-- description:end -->

solution/1100-1199/1184.Distance Between Bus Stops/README_EN.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,17 @@ tags:
2525
<p>Return the shortest distance between the given&nbsp;<code>start</code>&nbsp;and <code>destination</code>&nbsp;stops.</p>
2626

2727
<p>&nbsp;</p>
28+
2829
<p><strong class="example">Example 1:</strong></p>
2930

3031
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1100-1199/1184.Distance%20Between%20Bus%20Stops/images/untitled-diagram-1.jpg" style="width: 388px; height: 240px;" /></p>
3132

3233
<pre>
34+
3335
<strong>Input:</strong> distance = [1,2,3,4], start = 0, destination = 1
36+
3437
<strong>Output:</strong> 1
38+
3539
<strong>Explanation:</strong> Distance between 0 and 1 is 1 or 9, minimum is 1.</pre>
3640

3741
<p>&nbsp;</p>
@@ -41,9 +45,13 @@ tags:
4145
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1100-1199/1184.Distance%20Between%20Bus%20Stops/images/untitled-diagram-1-1.jpg" style="width: 388px; height: 240px;" /></p>
4246

4347
<pre>
48+
4449
<strong>Input:</strong> distance = [1,2,3,4], start = 0, destination = 2
50+
4551
<strong>Output:</strong> 3
52+
4653
<strong>Explanation:</strong> Distance between 0 and 2 is 3 or 7, minimum is 3.
54+
4755
</pre>
4856

4957
<p>&nbsp;</p>
@@ -53,19 +61,29 @@ tags:
5361
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1100-1199/1184.Distance%20Between%20Bus%20Stops/images/untitled-diagram-1-2.jpg" style="width: 388px; height: 240px;" /></p>
5462

5563
<pre>
64+
5665
<strong>Input:</strong> distance = [1,2,3,4], start = 0, destination = 3
66+
5767
<strong>Output:</strong> 4
68+
5869
<strong>Explanation:</strong> Distance between 0 and 3 is 6 or 4, minimum is 4.
70+
5971
</pre>
6072

6173
<p>&nbsp;</p>
74+
6275
<p><strong>Constraints:</strong></p>
6376

6477
<ul>
65-
<li><code>1 &lt;= n&nbsp;&lt;= 10^4</code></li>
66-
<li><code>distance.length == n</code></li>
67-
<li><code>0 &lt;= start, destination &lt; n</code></li>
68-
<li><code>0 &lt;= distance[i] &lt;= 10^4</code></li>
78+
79+
<li><code>1 &lt;= n&nbsp;&lt;= 10^4</code></li>
80+
81+
<li><code>distance.length == n</code></li>
82+
83+
<li><code>0 &lt;= start, destination &lt; n</code></li>
84+
85+
<li><code>0 &lt;= distance[i] &lt;= 10^4</code></li>
86+
6987
</ul>
7088

7189
<!-- description:end -->

0 commit comments

Comments
 (0)