Skip to content

Commit 63da6ef

Browse files
authored
feat: add solutions to lc problems: No.3162,3164,3166 (doocs#2918)
1 parent d36bce4 commit 63da6ef

File tree

33 files changed

+1435
-70
lines changed

33 files changed

+1435
-70
lines changed

solution/0400-0499/0409.Longest Palindrome/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ tags:
1818

1919
<!-- description:start -->
2020

21-
<p>Given a string <code>s</code> which consists of lowercase or uppercase letters, return <em>the length of the <strong>longest palindrome</strong></em>&nbsp;that can be built with those letters.</p>
21+
<p>Given a string <code>s</code> which consists of lowercase or uppercase letters, return the length of the <strong>longest <span data-keyword="palindrome-string">palindrome</span></strong>&nbsp;that can be built with those letters.</p>
2222

23-
<p>Letters are <strong>case sensitive</strong>, for example,&nbsp;<code>&quot;Aa&quot;</code> is not considered a palindrome here.</p>
23+
<p>Letters are <strong>case sensitive</strong>, for example, <code>&quot;Aa&quot;</code> is not considered a palindrome.</p>
2424

2525
<p>&nbsp;</p>
2626
<p><strong class="example">Example 1:</strong></p>

solution/0400-0499/0430.Flatten a Multilevel Doubly Linked List/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ After flattening the multilevel linked list it becomes:
6464
<p>&nbsp;</p>
6565
<p><strong>How the multilevel linked list is represented in test cases:</strong></p>
6666

67-
<p>We use the multilevel linked list from <strong class="example">Example 1</strong> above:</p>
67+
<p>We use the multilevel linked list from <strong>Example 1</strong> above:</p>
6868

6969
<pre>
7070
1---2---3---4---5---6--NULL

solution/2800-2899/2856.Minimum Array Length After Pair Removals/README_EN.md

+42-33
Original file line numberDiff line numberDiff line change
@@ -23,56 +23,65 @@ tags:
2323

2424
<!-- description:start -->
2525

26-
<p>You are given a <strong>0-indexed</strong> <strong>sorted</strong> array of integers <code>nums</code>.</p>
26+
<p>Given an integer array <code>num</code> sorted in non-decreasing order.</p>
2727

2828
<p>You can perform the following operation any number of times:</p>
2929

3030
<ul>
31-
<li>Choose <strong>two</strong> indices, <code>i</code> and <code>j</code>, where <code>i &lt; j</code>, such that <code>nums[i] &lt; nums[j]</code>.</li>
31+
<li>Choose <strong>two</strong> indices, <code>i</code> and <code>j</code>, where <code>nums[i] &lt; nums[j]</code>.</li>
3232
<li>Then, remove the elements at indices <code>i</code> and <code>j</code> from <code>nums</code>. The remaining elements retain their original order, and the array is re-indexed.</li>
3333
</ul>
3434

35-
<p>Return <em>an integer that denotes the <strong>minimum</strong> length of </em><code>nums</code><em> after performing the operation any number of times (<strong>including zero</strong>).</em></p>
36-
37-
<p>Note that <code>nums</code> is sorted in <strong>non-decreasing</strong> order.</p>
35+
<p>Return the <strong>minimum</strong> length of <code>nums</code> after applying the operation zero or more times.</p>
3836

3937
<p>&nbsp;</p>
4038
<p><strong class="example">Example 1:</strong></p>
4139

42-
<pre>
43-
<strong>Input:</strong> nums = [1,3,4,9]
44-
<strong>Output:</strong> 0
45-
<strong>Explanation:</strong> Initially, nums = [1, 3, 4, 9].
46-
In the first operation, we can choose index 0 and 1 because nums[0] &lt; nums[1] &lt;=&gt; 1 &lt; 3.
47-
Remove indices 0 and 1, and nums becomes [4, 9].
48-
For the next operation, we can choose index 0 and 1 because nums[0] &lt; nums[1] &lt;=&gt; 4 &lt; 9.
49-
Remove indices 0 and 1, and nums becomes an empty array [].
50-
Hence, the minimum length achievable is 0.</pre>
40+
<div class="example-block">
41+
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,3,4]</span></p>
42+
43+
<p><strong>Output:</strong> <span class="example-io">0</span></p>
44+
45+
<p><strong>Explanation:</strong></p>
46+
47+
<p><img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2800-2899/2856.Minimum%20Array%20Length%20After%20Pair%20Removals/images/tcase1.gif" style="width: 160px; height: 70px;" /></p>
48+
</div>
5149

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

54-
<pre>
55-
<strong>Input:</strong> nums = [2,3,6,9]
56-
<strong>Output:</strong> 0
57-
<strong>Explanation:</strong> Initially, nums = [2, 3, 6, 9].
58-
In the first operation, we can choose index 0 and 2 because nums[0] &lt; nums[2] &lt;=&gt; 2 &lt; 6.
59-
Remove indices 0 and 2, and nums becomes [3, 9].
60-
For the next operation, we can choose index 0 and 1 because nums[0] &lt; nums[1] &lt;=&gt; 3 &lt; 9.
61-
Remove indices 0 and 1, and nums becomes an empty array [].
62-
Hence, the minimum length achievable is 0.
63-
</pre>
52+
<div class="example-block">
53+
<p><strong>Input:</strong> <span class="example-io">nums = [1,1,2,2,3,3]</span></p>
54+
55+
<p><strong>Output:</strong> <span class="example-io">0</span></p>
56+
57+
<p><strong>Explanation:</strong></p>
58+
59+
<p><img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2800-2899/2856.Minimum%20Array%20Length%20After%20Pair%20Removals/images/tcase2.gif" style="width: 240px; height: 70px;" /></p>
60+
</div>
6461

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

67-
<pre>
68-
<strong>Input:</strong> nums = [1,1,2]
69-
<strong>Output:</strong> 1
70-
<strong>Explanation:</strong> Initially, nums = [1, 1, 2].
71-
In an operation, we can choose index 0 and 2 because nums[0] &lt; nums[2] &lt;=&gt; 1 &lt; 2.
72-
Remove indices 0 and 2, and nums becomes [1].
73-
It is no longer possible to perform an operation on the array.
74-
Hence, the minimum achievable length is 1.
75-
</pre>
64+
<div class="example-block">
65+
<p><strong>Input:</strong> <span class="example-io">nums = [1000000000,1000000000]</span></p>
66+
67+
<p><strong>Output:</strong> <span class="example-io">2</span></p>
68+
69+
<p><strong>Explanation:</strong></p>
70+
71+
<p>Since both numbers are equal, they cannot be removed.</p>
72+
</div>
73+
74+
<p><strong class="example">Example 4:</strong></p>
75+
76+
<div class="example-block">
77+
<p><strong>Input:</strong> <span class="example-io">nums = [2,3,4,4,4]</span></p>
78+
79+
<p><strong>Output:</strong> <span class="example-io">1</span></p>
80+
81+
<p><strong>Explanation:</strong></p>
82+
83+
<p><img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2800-2899/2856.Minimum%20Array%20Length%20After%20Pair%20Removals/images/tcase3.gif" style="width: 210px; height: 70px;" /></p>
84+
</div>
7685

7786
<p>&nbsp;</p>
7887
<p><strong>Constraints:</strong></p>

solution/2900-2999/2956.Find Common Elements Between Two Arrays/README_EN.md

+36-18
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,53 @@ tags:
1919

2020
<!-- description:start -->
2121

22-
<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of sizes <code>n</code> and <code>m</code>, respectively.</p>
23-
24-
<p>Consider calculating the following values:</p>
22+
<p>You are given two integer arrays <code>nums1</code> and <code>nums2</code> of sizes <code>n</code> and <code>m</code>, respectively. Calculate the following values:</p>
2523

2624
<ul>
27-
<li>The number of indices <code>i</code> such that <code>0 &lt;= i &lt; n</code> and <code>nums1[i]</code> occurs <strong>at least</strong> once in <code>nums2</code>.</li>
28-
<li>The number of indices <code>i</code> such that <code>0 &lt;= i &lt; m</code> and <code>nums2[i]</code> occurs <strong>at least</strong> once in <code>nums1</code>.</li>
25+
<li><code>answer1</code> : the number of indices <code>i</code> such that <code>nums1[i]</code> exists in <code>nums2</code>.</li>
26+
<li><code>answer2</code> : the number of indices <code>i</code> such that <code>nums2[i]</code> exists in <code>nums1</code>.</li>
2927
</ul>
3028

31-
<p>Return <em>an integer array </em><code>answer</code><em> of size </em><code>2</code><em> containing the two values <strong>in the above order</strong></em>.</p>
29+
<p>Return <code>[answer1,answer2]</code>.</p>
3230

3331
<p>&nbsp;</p>
3432
<p><strong class="example">Example 1:</strong></p>
3533

36-
<pre>
37-
<strong>Input:</strong> nums1 = [4,3,2,3,1], nums2 = [2,2,5,2,3,6]
38-
<strong>Output:</strong> [3,4]
39-
<strong>Explanation:</strong> We calculate the values as follows:
40-
- The elements at indices 1, 2, and 3 in nums1 occur at least once in nums2. So the first value is 3.
41-
- The elements at indices 0, 1, 3, and 4 in nums2 occur at least once in nums1. So the second value is 4.
42-
</pre>
34+
<div class="example-block">
35+
<p><strong>Input:</strong> <span class="example-io">nums1 = [2,3,2], nums2 = [1,2]</span></p>
36+
37+
<p><strong>Output:</strong> <span class="example-io">[2,1]</span></p>
38+
39+
<p><strong>Explanation:</strong></p>
40+
41+
<p><img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2900-2999/2956.Find%20Common%20Elements%20Between%20Two%20Arrays/images/3488_find_common_elements_between_two_arrays-t1.gif" style="width: 225px; height: 150px;" /></p>
42+
</div>
4343

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

46-
<pre>
47-
<strong>Input:</strong> nums1 = [3,4,2,3], nums2 = [1,5]
48-
<strong>Output:</strong> [0,0]
49-
<strong>Explanation:</strong> There are no common elements between the two arrays, so the two values will be 0.
50-
</pre>
46+
<div class="example-block">
47+
<p><strong>Input:</strong> <span class="example-io">nums1 = [4,3,2,3,1], nums2 = [2,2,5,2,3,6]</span></p>
48+
49+
<p><strong>Output:</strong> <span class="example-io">[3,4]</span></p>
50+
51+
<p><strong>Explanation:</strong></p>
52+
53+
<p>The elements at indices 1, 2, and 3 in <code>nums1</code> exist in <code>nums2</code> as well. So <code>answer1</code> is 3.</p>
54+
55+
<p>The elements at indices 0, 1, 3, and 4 in <code>nums2</code> exist in <code>nums1</code>. So <code>answer2</code> is 4.</p>
56+
</div>
57+
58+
<p><strong class="example">Example 3:</strong></p>
59+
60+
<div class="example-block">
61+
<p><strong>Input:</strong> <span class="example-io">nums1 = [3,4,2,3], nums2 = [1,5]</span></p>
62+
63+
<p><strong>Output:</strong> <span class="example-io">[0,0]</span></p>
64+
65+
<p><strong>Explanation:</strong></p>
66+
67+
<p>No numbers are common between <code>nums1</code> and <code>nums2</code>, so answer is [0,0].</p>
68+
</div>
5169

5270
<p>&nbsp;</p>
5371
<p><strong>Constraints:</strong></p>

0 commit comments

Comments
 (0)