Skip to content

Commit a742201

Browse files
authored
feat: update lc problems (#4277)
1 parent ec27aeb commit a742201

File tree

53 files changed

+1578
-351
lines changed

Some content is hidden

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

53 files changed

+1578
-351
lines changed

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

+15
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/0400-0499/0486.Predict the Winner/Solution.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ impl Solution {
1313
return f[i][j];
1414
}
1515
f[i][j] = std::cmp::max(
16-
nums[i] - Self::dfs(nums, f, i + 1, j),
17-
nums[j] - Self::dfs(nums, f, i, j - 1)
16+
nums[i] - Self::dfs(nums, f, i + 1, j),
17+
nums[j] - Self::dfs(nums, f, i, j - 1),
1818
);
1919
f[i][j]
2020
}

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

+18-2
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/1100-1199/1108.Defanging an IP Address/README_EN.md

+12-1
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

+14-6
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

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

+15-3
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

+22-4
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 -->

solution/1200-1299/1238.Circular Permutation in Binary Representation/README_EN.md

+23-5
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,53 @@ tags:
2323
<p>Given 2 integers <code>n</code> and <code>start</code>. Your task is return <strong>any</strong> permutation <code>p</code>&nbsp;of <code>(0,1,2.....,2^n -1) </code>such that :</p>
2424

2525
<ul>
26-
<li><code>p[0] = start</code></li>
27-
<li><code>p[i]</code> and <code>p[i+1]</code>&nbsp;differ by only one bit in their binary representation.</li>
28-
<li><code>p[0]</code> and <code>p[2^n -1]</code>&nbsp;must also differ by only one bit in their binary representation.</li>
26+
27+
<li><code>p[0] = start</code></li>
28+
29+
<li><code>p[i]</code> and <code>p[i+1]</code>&nbsp;differ by only one bit in their binary representation.</li>
30+
31+
<li><code>p[0]</code> and <code>p[2^n -1]</code>&nbsp;must also differ by only one bit in their binary representation.</li>
32+
2933
</ul>
3034

3135
<p>&nbsp;</p>
36+
3237
<p><strong class="example">Example 1:</strong></p>
3338

3439
<pre>
40+
3541
<strong>Input:</strong> n = 2, start = 3
42+
3643
<strong>Output:</strong> [3,2,0,1]
44+
3745
<strong>Explanation:</strong> The binary representation of the permutation is (11,10,00,01).
46+
3847
All the adjacent element differ by one bit. Another valid permutation is [3,1,0,2]
48+
3949
</pre>
4050

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

4353
<pre>
54+
4455
<strong>Input:</strong> n = 3, start = 2
56+
4557
<strong>Output:</strong> [2,6,7,5,4,0,1,3]
58+
4659
<strong>Explanation:</strong> The binary representation of the permutation is (010,110,111,101,100,000,001,011).
60+
4761
</pre>
4862

4963
<p>&nbsp;</p>
64+
5065
<p><strong>Constraints:</strong></p>
5166

5267
<ul>
53-
<li><code>1 &lt;= n &lt;= 16</code></li>
54-
<li><code>0 &lt;= start&nbsp;&lt;&nbsp;2 ^ n</code></li>
68+
69+
<li><code>1 &lt;= n &lt;= 16</code></li>
70+
71+
<li><code>0 &lt;= start&nbsp;&lt;&nbsp;2 ^ n</code></li>
72+
5573
</ul>
5674

5775
<!-- description:end -->

0 commit comments

Comments
 (0)