Skip to content

feat: update lc problems #3634

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
Oct 11, 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
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ tags:

<p>Design an algorithm to serialize and deserialize a binary tree. There is no restriction on how your serialization/deserialization algorithm should work. You just need to ensure that a binary tree can be serialized to a string and this string can be deserialized to the original tree structure.</p>

<p><strong>Clarification:</strong> The input/output format is the same as <a href="https://support.leetcode.com/hc/en-us/articles/360011883654-What-does-1-null-2-3-mean-in-binary-tree-representation-" target="_blank">how LeetCode serializes a binary tree</a>. You do not necessarily need to follow this format, so please be creative and come up with different approaches yourself.</p>
<p><strong>Clarification:</strong> The input/output format is the same as <a href="https://support.leetcode.com/hc/en-us/articles/32442719377939-How-to-create-test-cases-on-LeetCode#h_01J5EGREAW3NAEJ14XC07GRW1A" target="_blank">how LeetCode serializes a binary tree</a>. You do not necessarily need to follow this format, so please be creative and come up with different approaches yourself.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
Expand Down
2 changes: 1 addition & 1 deletion solution/0500-0599/0593.Valid Square/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ tags:

<pre>
<strong>输入:</strong> p1 = [0,0], p2 = [1,1], p3 = [1,0], p4 = [0,1]
<strong>输出:</strong> True
<strong>输出:</strong> true
</pre>

<p><strong>示例 2:</strong></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tags:

<p>和谐数组是指一个数组里元素的最大值和最小值之间的差别 <strong>正好是 <code>1</code></strong> 。</p>

<p>给你一个整数数组 <code>nums</code> ,请你在所有可能的子序列中找到最长的和谐子序列的长度。</p>
<p>给你一个整数数组 <code>nums</code> ,请你在所有可能的 <span data-keyword="subsequence-array">子序列</span> 中找到最长的和谐子序列的长度。</p>

<p>数组的 <strong>子序列</strong> 是一个由数组派生出来的序列,它可以通过删除一些元素或不删除元素、且不改变其余元素的顺序而得到。</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ tags:

<p>We define a harmonious array as an array where the difference between its maximum value and its minimum value is <b>exactly</b> <code>1</code>.</p>

<p>Given an integer array <code>nums</code>, return <em>the length of its longest harmonious subsequence among all its possible subsequences</em>.</p>

<p>A <strong>subsequence</strong> of array is a sequence that can be derived from the array by deleting some or no elements without changing the order of the remaining elements.</p>
<p>Given an integer array <code>nums</code>, return the length of its longest harmonious <span data-keyword="subsequence-array">subsequence</span> among all its possible subsequences.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
Expand Down
29 changes: 16 additions & 13 deletions solution/0900-0999/0975.Odd Even Jump/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,29 @@ tags:

<!-- description:start -->

<p>给定一个整数数组 <code>A</code>,你可以从某一起始索引出发,跳跃一定次数。在你跳跃的过程中,第 1、3、5... 次跳跃称为奇数跳跃,而第 2、4、6... 次跳跃称为偶数跳跃。</p>
<p>给定一个整数数组 <code>arr</code>,你可以从某一起始索引出发,跳跃一定次数。在你跳跃的过程中,第 1、3、5... 次跳跃称为奇数跳跃,而第 2、4、6... 次跳跃称为偶数跳跃。</p>

<p>你可以按以下方式从索引 <code>i</code>&nbsp;向后跳转到索引 <code>j</code>(其中 <code>i &lt; j</code>):</p>

<ul>
<li>在进行奇数跳跃时(如,第&nbsp;1,3,5... 次跳跃),你将会跳到索引 <code>j</code>,使得 <code>A[i] &lt;=&nbsp;A[j]</code>,<code>A[j]</code> 是可能的最小值。如果存在多个这样的索引 <code>j</code>,你只能跳到满足要求的<strong>最小</strong>索引 <code>j</code> 上。</li>
<li>在进行偶数跳跃时(如,第&nbsp;2,4,6... 次跳跃),你将会跳到索引&nbsp;<code>j</code>,使得 <code>A[i] &gt;= A[j]</code>,<code>A[j]</code> 是可能的最大值。如果存在多个这样的索引 <code>j</code>,你只能跳到满足要求的<strong>最小</strong>索引 <code>j</code>&nbsp;上。</li>
<li>在进行奇数跳跃时(如,第&nbsp;1,3,5... 次跳跃),你将会跳到索引 <code>j</code>,使得 <code>arr[i] &lt;=&nbsp;arr[j]</code>,<code>arr[j]</code> 的值尽可能小。如果存在多个这样的索引 <code>j</code>,你只能跳到满足要求的<strong>最小</strong>索引 <code>j</code> 上。</li>
<li>在进行偶数跳跃时(如,第&nbsp;2,4,6... 次跳跃),你将会跳到索引&nbsp;<code>j</code>,使得 <code>arr[i] &gt;= arr[j]</code>,<code>arr[j]</code> 的值尽可能大。如果存在多个这样的索引 <code>j</code>,你只能跳到满足要求的<strong>最小</strong>索引 <code>j</code>&nbsp;上。</li>
<li>(对于某些索引 <code>i</code>,可能无法进行合乎要求的跳跃。)</li>
</ul>

<p>如果从某一索引开始跳跃一定次数(可能是 0 次或多次),就可以到达数组的末尾(索引 <code>A.length - 1</code>),那么该索引就会被认为是好的起始索引。</p>
<p>如果从某一索引开始跳跃一定次数(可能是 0 次或多次),就可以到达数组的末尾(索引 <code>arr.length - 1</code>),那么该索引就会被认为是好的起始索引。</p>

<p>返回好的起始索引的数量。</p>

<p>&nbsp;</p>

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

<pre><strong>输入:</strong>[10,13,12,14,15]
<pre>
<strong>输入:</strong>[10,13,12,14,15]
<strong>输出:</strong>2
<strong>解释: </strong>
从起始索引 i = 0 出发,我们可以跳到 i = 2,(因为 A[2] 是 A[1],A[2],A[3],A[4] 中大于或等于 A[0] 的最小值),然后我们就无法继续跳下去了。
从起始索引 i = 0 出发,我们可以跳到 i = 2,(因为 arr[2] 是 arr[1],arr[2],arr[3],arr[4] 中大于或等于 arr[0] 的最小值),然后我们就无法继续跳下去了。
从起始索引 i = 1 和 i = 2 出发,我们可以跳到 i = 3,然后我们就无法继续跳下去了。
从起始索引 i = 3 出发,我们可以跳到 i = 4,到达数组末尾。
从起始索引 i = 4 出发,我们已经到达数组末尾。
Expand All @@ -50,16 +51,17 @@ tags:

<p><strong>示例&nbsp;2:</strong></p>

<pre><strong>输入:</strong>[2,3,1,1,4]
<pre>
<strong>输入:</strong>[2,3,1,1,4]
<strong>输出:</strong>3
<strong>解释:</strong>
从起始索引 i=0 出发,我们依次可以跳到 i = 1,i = 2,i = 3:

在我们的第一次跳跃(奇数)中,我们先跳到 i = 1,因为 A[1] 是(A[1],A[2],A[3],A[4])中大于或等于 A[0] 的最小值。
在我们的第一次跳跃(奇数)中,我们先跳到 i = 1,因为 arr[1] 是(arr[1],arr[2],arr[3],arr[4])中大于或等于 arr[0] 的最小值。

在我们的第二次跳跃(偶数)中,我们从 i = 1 跳到 i = 2,因为 A[2] 是(A[2],A[3],A[4])中小于或等于 A[1] 的最大值。A[3] 也是最大的值,但 2 是一个较小的索引,所以我们只能跳到 i = 2,而不能跳到 i = 3。
在我们的第二次跳跃(偶数)中,我们从 i = 1 跳到 i = 2,因为 arr[2] 是(arr[2],arr[3],arr[4])中小于或等于 arr[1] 的最大值。arr[3] 也是最大的值,但 2 是一个较小的索引,所以我们只能跳到 i = 2,而不能跳到 i = 3。

在我们的第三次跳跃(奇数)中,我们从 i = 2 跳到 i = 3,因为 A[3] 是(A[3],A[4])中大于或等于 A[2] 的最小值。
在我们的第三次跳跃(奇数)中,我们从 i = 2 跳到 i = 3,因为 arr[3] 是(arr[3],arr[4])中大于或等于 arr[2] 的最小值。

我们不能从 i = 3 跳到 i = 4,所以起始索引 i = 0 不是好的起始索引。

Expand All @@ -73,7 +75,8 @@ tags:

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

<pre><strong>输入:</strong>[5,1,3,4,2]
<pre>
<strong>输入:</strong>[5,1,3,4,2]
<strong>输出:</strong>3
<strong>解释: </strong>
我们可以从起始索引 1,2,4 出发到达数组末尾。
Expand All @@ -84,8 +87,8 @@ tags:
<p><strong>提示:</strong></p>

<ol>
<li><code>1 &lt;= A.length &lt;= 20000</code></li>
<li><code>0 &lt;= A[i] &lt; 100000</code></li>
<li><code>1 &lt;= arr.length &lt;= 20000</code></li>
<li><code>0 &lt;= arr[i] &lt; 100000</code></li>
</ol>

<!-- description:end -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ tags:
<p><strong>示例 1:</strong></p>

<pre><strong>输入:</strong>n = 234
<strong>输出:</strong>15
<strong>输出:</strong>15
<strong>解释:</strong>
各位数之积 = 2 * 3 * 4 = 24
各位数之和 = 2 + 3 + 4 = 9
各位数之积 = 2 * 3 * 4 = 24
各位数之和 = 2 + 3 + 4 = 9
结果 = 24 - 9 = 15
</pre>

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

<pre><strong>输入:</strong>n = 4421
<strong>输出:</strong>21
<strong>解释:
</strong>各位数之积 = 4 * 4 * 2 * 1 = 32
各位数之和 = 4 + 4 + 2 + 1 = 11
<strong>解释:
</strong>各位数之积 = 4 * 4 * 2 * 1 = 32
各位数之和 = 4 + 4 + 2 + 1 = 11
结果 = 32 - 11 = 21
</pre>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ Given an integer number <code>n</code>, return the difference between the produc

<pre>
<strong>Input:</strong> n = 234
<strong>Output:</strong> 15
<b>Explanation:</b>
Product of digits = 2 * 3 * 4 = 24
Sum of digits = 2 + 3 + 4 = 9
<strong>Output:</strong> 15
<b>Explanation:</b>
Product of digits = 2 * 3 * 4 = 24
Sum of digits = 2 + 3 + 4 = 9
Result = 24 - 9 = 15
</pre>

Expand All @@ -37,9 +37,9 @@ Result = 24 - 9 = 15
<pre>
<strong>Input:</strong> n = 4421
<strong>Output:</strong> 21
<b>Explanation:
</b>Product of digits = 4 * 4 * 2 * 1 = 32
Sum of digits = 4 + 4 + 2 + 1 = 11
<b>Explanation:
</b>Product of digits = 4 * 4 * 2 * 1 = 32
Sum of digits = 4 + 4 + 2 + 1 = 11
Result = 32 - 11 = 21
</pre>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ tags:

<pre>
<strong>输入:</strong>nums = [555,901,482,1771]
<strong>输出:</strong>1
<strong>输出:</strong>1
<strong>解释: </strong>
只有 1771 是位数为偶数的数字。
</pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ tags:
<pre>
<strong>Input:</strong> nums = [12,345,2,6,7896]
<strong>Output:</strong> 2
<strong>Explanation:
<strong>Explanation:
</strong>12 contains 2 digits (even number of digits).&nbsp;
345 contains 3 digits (odd number of digits).&nbsp;
2 contains 1 digit (odd number of digits).&nbsp;
Expand All @@ -40,7 +40,7 @@ Therefore only 12 and 7896 contain an even number of digits.

<pre>
<strong>Input:</strong> nums = [555,901,482,1771]
<strong>Output:</strong> 1
<strong>Output:</strong> 1
<strong>Explanation: </strong>
Only 1771 contains an even number of digits.
</pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ tags:
<pre>
<strong>Input:</strong> arr = [17,18,5,4,6,1]
<strong>Output:</strong> [18,6,6,6,1,-1]
<strong>Explanation:</strong>
<strong>Explanation:</strong>
- index 0 --&gt; the greatest element to the right of index 0 is index 1 (18).
- index 1 --&gt; the greatest element to the right of index 1 is index 4 (6).
- index 2 --&gt; the greatest element to the right of index 2 is index 4 (6).
Expand Down
2 changes: 1 addition & 1 deletion solution/1400-1499/1470.Shuffle the Array/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ tags:
<p><strong>示例 1:</strong></p>

<pre><strong>输入:</strong>nums = [2,5,1,3,4,7], n = 3
<strong>输出:</strong>[2,3,5,4,1,7]
<strong>输出:</strong>[2,3,5,4,1,7]
<strong>解释:</strong>由于 x<sub>1</sub>=2, x<sub>2</sub>=5, x<sub>3</sub>=1, y<sub>1</sub>=3, y<sub>2</sub>=4, y<sub>3</sub>=7 ,所以答案为 [2,3,5,4,1,7]
</pre>

Expand Down
2 changes: 1 addition & 1 deletion solution/1400-1499/1470.Shuffle the Array/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ tags:

<strong>Input:</strong> nums = [2,5,1,3,4,7], n = 3

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

<strong>Explanation:</strong> Since x<sub>1</sub>=2, x<sub>2</sub>=5, x<sub>3</sub>=1, y<sub>1</sub>=3, y<sub>2</sub>=4, y<sub>3</sub>=7 then the answer is [2,3,5,4,1,7].

Expand Down
2 changes: 1 addition & 1 deletion solution/1400-1499/1473.Paint House III/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Cost of paint all houses (1 + 1 + 1 + 1 + 5) = 9.
<strong>Input:</strong> houses = [0,2,1,2,0], cost = [[1,10],[10,1],[10,1],[1,10],[5,1]], m = 5, n = 2, target = 3
<strong>Output:</strong> 11
<strong>Explanation:</strong> Some houses are already painted, Paint the houses of this way [2,2,1,2,2]
This array contains target = 3 neighborhoods, [{2,2}, {1}, {2,2}].
This array contains target = 3 neighborhoods, [{2,2}, {1}, {2,2}].
Cost of paint the first and last house (10 + 1) = 11.
</pre>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ tags:
<pre>
<strong>Input:</strong> prices = [8,4,6,2,3]
<strong>Output:</strong> [4,2,4,2,3]
<strong>Explanation:</strong>
<strong>Explanation:</strong>
For item 0 with price[0]=8 you will receive a discount equivalent to prices[1]=4, therefore, the final price you will pay is 8 - 4 = 4.
For item 1 with price[1]=4 you will receive a discount equivalent to prices[3]=2, therefore, the final price you will pay is 4 - 2 = 2.
For item 2 with price[2]=6 you will receive a discount equivalent to prices[3]=2, therefore, the final price you will pay is 6 - 2 = 4.
Expand Down
Loading
Loading