Skip to content
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

feat: update lc problems #4277

Merged
merged 1 commit into from
Mar 21, 2025
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
15 changes: 15 additions & 0 deletions solution/0100-0199/0195.Tenth Line/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,41 @@ tags:
<p>Assume that <code>file.txt</code> has the following content:</p>

<pre>

Line 1

Line 2

Line 3

Line 4

Line 5

Line 6

Line 7

Line 8

Line 9

Line 10

</pre>

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

<pre>

Line 10

</pre>

<div class="spoilers"><b>Note:</b><br />

1. If the file contains less than 10 lines, what should you output?<br />

2. There&#39;s at least three different solutions. Try to explore all possibilities.</div>

<!-- description:end -->
Expand Down
4 changes: 2 additions & 2 deletions solution/0400-0499/0486.Predict the Winner/Solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ impl Solution {
return f[i][j];
}
f[i][j] = std::cmp::max(
nums[i] - Self::dfs(nums, f, i + 1, j),
nums[j] - Self::dfs(nums, f, i, j - 1)
nums[i] - Self::dfs(nums, f, i + 1, j),
nums[j] - Self::dfs(nums, f, i, j - 1),
);
f[i][j]
}
Expand Down
20 changes: 18 additions & 2 deletions solution/0700-0799/0799.Champagne Tower/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,51 @@ tags:
<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>

<p>&nbsp;</p>

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

<pre>

<strong>Input:</strong> poured = 1, query_row = 1, query_glass = 1

<strong>Output:</strong> 0.00000

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

</pre>

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

<pre>

<strong>Input:</strong> poured = 2, query_row = 1, query_glass = 1

<strong>Output:</strong> 0.50000

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

</pre>

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

<pre>

<strong>Input:</strong> poured = 100000009, query_row = 33, query_glass = 17

<strong>Output:</strong> 1.00000

</pre>

<p>&nbsp;</p>

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

<ul>
<li><code>0 &lt;=&nbsp;poured &lt;= 10<sup>9</sup></code></li>
<li><code>0 &lt;= query_glass &lt;= query_row&nbsp;&lt; 100</code></li>

<li><code>0 &lt;=&nbsp;poured &lt;= 10<sup>9</sup></code></li>

<li><code>0 &lt;= query_glass &lt;= query_row&nbsp;&lt; 100</code></li>

</ul>

<!-- description:end -->
Expand Down
13 changes: 12 additions & 1 deletion solution/1100-1199/1108.Defanging an IP Address/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,29 @@ tags:
<p>A <em>defanged&nbsp;IP address</em>&nbsp;replaces every period <code>&quot;.&quot;</code> with <code>&quot;[.]&quot;</code>.</p>

<p>&nbsp;</p>

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

<pre><strong>Input:</strong> address = "1.1.1.1"

<strong>Output:</strong> "1[.]1[.]1[.]1"

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

<pre><strong>Input:</strong> address = "255.100.50.0"

<strong>Output:</strong> "255[.]100[.]50[.]0"

</pre>

<p>&nbsp;</p>

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

<ul>
<li>The given <code>address</code> is a valid IPv4 address.</li>

<li>The given <code>address</code> is a valid IPv4 address.</li>

</ul>

<!-- description:end -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,25 @@ tags:
<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>

<ul>
<li>It is the empty string, or</li>
<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>
<li>It can be written as&nbsp;<code>(A)</code>, where&nbsp;<code>A</code>&nbsp;is a VPS.</li>

<li>It is the empty string, or</li>

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

<li>It can be written as&nbsp;<code>(A)</code>, where&nbsp;<code>A</code>&nbsp;is a VPS.</li>

</ul>

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

<ul>
<li><code>depth(&quot;&quot;) = 0</code></li>
<li><code>depth(A + B) = max(depth(A), depth(B))</code>, where <code>A</code> and <code>B</code> are VPS&#39;s</li>
<li><code>depth(&quot;(&quot; + A + &quot;)&quot;) = 1 + depth(A)</code>, where <code>A</code> is a VPS.</li>

<li><code>depth(&quot;&quot;) = 0</code></li>

<li><code>depth(A + B) = max(depth(A), depth(B))</code>, where <code>A</code> and <code>B</code> are VPS&#39;s</li>

<li><code>depth(&quot;(&quot; + A + &quot;)&quot;) = 1 + depth(A)</code>, where <code>A</code> is a VPS.</li>

</ul>

<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>
Expand Down
32 changes: 25 additions & 7 deletions solution/1100-1199/1138.Alphabet Board Path/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,49 @@ tags:
<p>We may make the following moves:</p>

<ul>
<li><code>&#39;U&#39;</code> moves our position up one row, if the position exists on the board;</li>
<li><code>&#39;D&#39;</code> moves our position down one row, if the position exists on the board;</li>
<li><code>&#39;L&#39;</code> moves our position left one column, if the position exists on the board;</li>
<li><code>&#39;R&#39;</code> moves our position right one column, if the position exists on the board;</li>
<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>

<li><code>&#39;U&#39;</code> moves our position up one row, if the position exists on the board;</li>

<li><code>&#39;D&#39;</code> moves our position down one row, if the position exists on the board;</li>

<li><code>&#39;L&#39;</code> moves our position left one column, if the position exists on the board;</li>

<li><code>&#39;R&#39;</code> moves our position right one column, if the position exists on the board;</li>

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

</ul>

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

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

<p>&nbsp;</p>

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

<pre><strong>Input:</strong> target = "leet"

<strong>Output:</strong> "DDR!UURRR!!DDD!"

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

<pre><strong>Input:</strong> target = "code"

<strong>Output:</strong> "RR!DDRR!UUL!R!"

</pre>

<p>&nbsp;</p>

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

<ul>
<li><code>1 &lt;= target.length &lt;= 100</code></li>
<li><code>target</code> consists only of English lowercase letters.</li>

<li><code>1 &lt;= target.length &lt;= 100</code></li>

<li><code>target</code> consists only of English lowercase letters.</li>

</ul>

<!-- description:end -->
Expand Down
18 changes: 15 additions & 3 deletions solution/1100-1199/1139.Largest 1-Bordered Square/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,39 @@ tags:
<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>

<p>&nbsp;</p>

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

<pre>

<strong>Input:</strong> grid = [[1,1,1],[1,0,1],[1,1,1]]

<strong>Output:</strong> 9

</pre>

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

<pre>

<strong>Input:</strong> grid = [[1,1,0,0]]

<strong>Output:</strong> 1

</pre>

<p>&nbsp;</p>

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

<ul>
<li><code>1 &lt;= grid.length &lt;= 100</code></li>
<li><code>1 &lt;= grid[0].length &lt;= 100</code></li>
<li><code>grid[i][j]</code> is <code>0</code> or <code>1</code></li>

<li><code>1 &lt;= grid.length &lt;= 100</code></li>

<li><code>1 &lt;= grid[0].length &lt;= 100</code></li>

<li><code>grid[i][j]</code> is <code>0</code> or <code>1</code></li>

</ul>

<!-- description:end -->
Expand Down
26 changes: 22 additions & 4 deletions solution/1100-1199/1184.Distance Between Bus Stops/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ tags:
<p>Return the shortest distance between the given&nbsp;<code>start</code>&nbsp;and <code>destination</code>&nbsp;stops.</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/1100-1199/1184.Distance%20Between%20Bus%20Stops/images/untitled-diagram-1.jpg" style="width: 388px; height: 240px;" /></p>

<pre>

<strong>Input:</strong> distance = [1,2,3,4], start = 0, destination = 1

<strong>Output:</strong> 1

<strong>Explanation:</strong> Distance between 0 and 1 is 1 or 9, minimum is 1.</pre>

<p>&nbsp;</p>
Expand All @@ -41,9 +45,13 @@ tags:
<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>

<pre>

<strong>Input:</strong> distance = [1,2,3,4], start = 0, destination = 2

<strong>Output:</strong> 3

<strong>Explanation:</strong> Distance between 0 and 2 is 3 or 7, minimum is 3.

</pre>

<p>&nbsp;</p>
Expand All @@ -53,19 +61,29 @@ tags:
<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>

<pre>

<strong>Input:</strong> distance = [1,2,3,4], start = 0, destination = 3

<strong>Output:</strong> 4

<strong>Explanation:</strong> Distance between 0 and 3 is 6 or 4, minimum is 4.

</pre>

<p>&nbsp;</p>

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

<ul>
<li><code>1 &lt;= n&nbsp;&lt;= 10^4</code></li>
<li><code>distance.length == n</code></li>
<li><code>0 &lt;= start, destination &lt; n</code></li>
<li><code>0 &lt;= distance[i] &lt;= 10^4</code></li>

<li><code>1 &lt;= n&nbsp;&lt;= 10^4</code></li>

<li><code>distance.length == n</code></li>

<li><code>0 &lt;= start, destination &lt; n</code></li>

<li><code>0 &lt;= distance[i] &lt;= 10^4</code></li>

</ul>

<!-- description:end -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,53 @@ tags:
<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>

<ul>
<li><code>p[0] = start</code></li>
<li><code>p[i]</code> and <code>p[i+1]</code>&nbsp;differ by only one bit in their binary representation.</li>
<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>

<li><code>p[0] = start</code></li>

<li><code>p[i]</code> and <code>p[i+1]</code>&nbsp;differ by only one bit in their binary representation.</li>

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

</ul>

<p>&nbsp;</p>

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

<pre>

<strong>Input:</strong> n = 2, start = 3

<strong>Output:</strong> [3,2,0,1]

<strong>Explanation:</strong> The binary representation of the permutation is (11,10,00,01).

All the adjacent element differ by one bit. Another valid permutation is [3,1,0,2]

</pre>

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

<pre>

<strong>Input:</strong> n = 3, start = 2

<strong>Output:</strong> [2,6,7,5,4,0,1,3]

<strong>Explanation:</strong> The binary representation of the permutation is (010,110,111,101,100,000,001,011).

</pre>

<p>&nbsp;</p>

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

<ul>
<li><code>1 &lt;= n &lt;= 16</code></li>
<li><code>0 &lt;= start&nbsp;&lt;&nbsp;2 ^ n</code></li>

<li><code>1 &lt;= n &lt;= 16</code></li>

<li><code>0 &lt;= start&nbsp;&lt;&nbsp;2 ^ n</code></li>

</ul>

<!-- description:end -->
Expand Down
Loading
Loading