Skip to content

Commit 9fd70f8

Browse files
committed
deploy: e761584
1 parent c44112c commit 9fd70f8

File tree

12 files changed

+65
-182
lines changed

12 files changed

+65
-182
lines changed

en/lc/2340/index.html

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56416,9 +56416,9 @@
5641656416
<ul class="md-nav__list">
5641756417

5641856418
<li class="md-nav__item">
56419-
<a href="#solution-1" class="md-nav__link">
56419+
<a href="#solution-1-maintain-index-of-extremes-case-analysis" class="md-nav__link">
5642056420
<span class="md-ellipsis">
56421-
Solution 1
56421+
Solution 1: Maintain Index of Extremes + Case Analysis
5642256422
</span>
5642356423
</a>
5642456424

@@ -80860,7 +80860,15 @@ <h2 id="description">Description</h2>
8086080860
<h2 id="solutions">Solutions</h2>
8086180861
<!-- solution:start -->
8086280862

80863-
<h3 id="solution-1">Solution 1</h3>
80863+
<h3 id="solution-1-maintain-index-of-extremes-case-analysis">Solution 1: Maintain Index of Extremes + Case Analysis</h3>
80864+
<p>We can use indices $i$ and $j$ to record the index of the first minimum value and the last maximum value in the array $\textit{nums}$, respectively. Traverse the array $\textit{nums}$ to update the values of $i$ and $j$.</p>
80865+
<p>Next, we need to consider the number of swaps.</p>
80866+
<ul>
80867+
<li>If $i = j$, it means the array $\textit{nums}$ is already a valid array, and no swaps are needed. Return $0$.</li>
80868+
<li>If $i &lt; j$, it means the minimum value in the array $\textit{nums}$ is to the left of the maximum value. The number of swaps needed is $i + n - 1 - j$, where $n$ is the length of the array $\textit{nums}$.</li>
80869+
<li>If $i &gt; j$, it means the minimum value in the array $\textit{nums}$ is to the right of the maximum value. The number of swaps needed is $i + n - 1 - j - 1$.</li>
80870+
</ul>
80871+
<p>The time complexity is $O(n)$, where $n$ is the length of the array $\textit{nums}$. The space complexity is $O(1)$.</p>
8086480872
<div class="tabbed-set tabbed-alternate" data-tabs="1:5"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><input id="__tabbed_1_2" name="__tabbed_1" type="radio" /><input id="__tabbed_1_3" name="__tabbed_1" type="radio" /><input id="__tabbed_1_4" name="__tabbed_1" type="radio" /><input id="__tabbed_1_5" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">Python3</label><label for="__tabbed_1_2">Java</label><label for="__tabbed_1_3">C++</label><label for="__tabbed_1_4">Go</label><label for="__tabbed_1_5">TypeScript</label></div>
8086580873
<div class="tabbed-content">
8086680874
<div class="tabbed-block">

en/lc/2341/index.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56437,9 +56437,9 @@
5643756437
<ul class="md-nav__list">
5643856438

5643956439
<li class="md-nav__item">
56440-
<a href="#solution-1" class="md-nav__link">
56440+
<a href="#solution-1-counting" class="md-nav__link">
5644156441
<span class="md-ellipsis">
56442-
Solution 1
56442+
Solution 1: Counting
5644356443
</span>
5644456444
</a>
5644556445

@@ -80871,7 +80871,12 @@ <h2 id="description">Description</h2>
8087180871
<h2 id="solutions">Solutions</h2>
8087280872
<!-- solution:start -->
8087380873

80874-
<h3 id="solution-1">Solution 1</h3>
80874+
<h3 id="solution-1-counting">Solution 1: Counting</h3>
80875+
<p>We can count the occurrences of each number $x$ in the array $\textit{nums}$ and record them in a hash table or array $\textit{cnt}$.</p>
80876+
<p>Then, we traverse $\textit{cnt}$. For each number $x$, if the occurrence count $v$ of $x$ is greater than $1$, we can select two $x$'s from the array to form a pair. We divide $v$ by $2$ and take the floor value to get the number of pairs that can be formed by the current number $x$. We then add this number to the variable $s$.</p>
80877+
<p>The remaining count is the length of the array $\textit{nums}$ minus the number of pairs formed multiplied by $2$, i.e., $n - s \times 2$.</p>
80878+
<p>The answer is $[s, n - s \times 2]$.</p>
80879+
<p>The time complexity is $O(n)$, and the space complexity is $O(C)$. Here, $n$ is the length of the array $\textit{nums}$, and $C$ is the range of numbers in the array $\textit{nums}$, which is $101$ in this problem.</p>
8087580880
<div class="tabbed-set tabbed-alternate" data-tabs="1:9"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><input id="__tabbed_1_2" name="__tabbed_1" type="radio" /><input id="__tabbed_1_3" name="__tabbed_1" type="radio" /><input id="__tabbed_1_4" name="__tabbed_1" type="radio" /><input id="__tabbed_1_5" name="__tabbed_1" type="radio" /><input id="__tabbed_1_6" name="__tabbed_1" type="radio" /><input id="__tabbed_1_7" name="__tabbed_1" type="radio" /><input id="__tabbed_1_8" name="__tabbed_1" type="radio" /><input id="__tabbed_1_9" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">Python3</label><label for="__tabbed_1_2">Java</label><label for="__tabbed_1_3">C++</label><label for="__tabbed_1_4">Go</label><label for="__tabbed_1_5">TypeScript</label><label for="__tabbed_1_6">Rust</label><label for="__tabbed_1_7">JavaScript</label><label for="__tabbed_1_8">C#</label><label for="__tabbed_1_9">C</label></div>
8087680881
<div class="tabbed-content">
8087780882
<div class="tabbed-block">

en/lc/2343/index.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56479,9 +56479,9 @@
5647956479
<ul class="md-nav__list">
5648056480

5648156481
<li class="md-nav__item">
56482-
<a href="#solution-1" class="md-nav__link">
56482+
<a href="#solution-1-simulation" class="md-nav__link">
5648356483
<span class="md-ellipsis">
56484-
Solution 1
56484+
Solution 1: Simulation
5648556485
</span>
5648656486
</a>
5648756487

@@ -80907,7 +80907,9 @@ <h2 id="description">Description</h2>
8090780907
<h2 id="solutions">Solutions</h2>
8090880908
<!-- solution:start -->
8090980909

80910-
<h3 id="solution-1">Solution 1</h3>
80910+
<h3 id="solution-1-simulation">Solution 1: Simulation</h3>
80911+
<p>According to the problem description, we can simulate the cropping process, then sort the cropped strings, and finally find the corresponding number based on the index.</p>
80912+
<p>The time complexity is $O(m \times n \times \log n \times s)$, and the space complexity is $O(n)$. Here, $m$ and $n$ are the lengths of $\textit{nums}$ and $\textit{queries}$ respectively, and $s$ is the length of the string $\textit{nums}[i]$.</p>
8091180913
<div class="tabbed-set tabbed-alternate" data-tabs="1:4"><input checked="checked" id="__tabbed_1_1" name="__tabbed_1" type="radio" /><input id="__tabbed_1_2" name="__tabbed_1" type="radio" /><input id="__tabbed_1_3" name="__tabbed_1" type="radio" /><input id="__tabbed_1_4" name="__tabbed_1" type="radio" /><div class="tabbed-labels"><label for="__tabbed_1_1">Python3</label><label for="__tabbed_1_2">Java</label><label for="__tabbed_1_3">C++</label><label for="__tabbed_1_4">Go</label></div>
8091280914
<div class="tabbed-content">
8091380915
<div class="tabbed-block">

0 commit comments

Comments
 (0)