Skip to content

Commit 44b6f1a

Browse files
committed
deploy: 8d6b198
1 parent 6814ef2 commit 44b6f1a

File tree

5 files changed

+549
-156
lines changed

5 files changed

+549
-156
lines changed

en/lc/1585/index.html

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

4061340613
<li class="md-nav__item">
40614-
<a href="#solution-1" class="md-nav__link">
40614+
<a href="#solution-1-bubble-sort" class="md-nav__link">
4061540615
<span class="md-ellipsis">
40616-
Solution 1
40616+
Solution 1: Bubble Sort
4061740617
</span>
4061840618
</a>
4061940619

@@ -81450,7 +81450,12 @@ <h2 id="description">Description</h2>
8145081450
<h2 id="solutions">Solutions</h2>
8145181451
<!-- solution:start -->
8145281452

81453-
<h3 id="solution-1">Solution 1</h3>
81453+
<h3 id="solution-1-bubble-sort">Solution 1: Bubble Sort</h3>
81454+
<p>The problem is essentially equivalent to determining whether any substring of length 2 in string $s$ can be swapped using bubble sort to obtain $t$.</p>
81455+
<p>Therefore, we use an array $pos$ of length 10 to record the indices of each digit in string $s$, where $pos[i]$ represents the list of indices where digit $i$ appears, sorted in ascending order.</p>
81456+
<p>Next, we iterate through string $t$. For each character $t[i]$ in $t$, we convert it to the digit $x$. We check if $pos[x]$ is empty. If it is, it means that the digit in $t$ does not exist in $s$, so we return <code>false</code>. Otherwise, to swap the character at the first index of $pos[x]$ to index $i$, all indices of digits less than $x$ must be greater than or equal to the first index of $pos[x]. If this condition is not met, we return <code>false</code>. Otherwise, we pop the first index from $pos[x]$ and continue iterating through string $t$.</p>
81457+
<p>After the iteration, we return <code>true</code>.</p>
81458+
<p>The time complexity is $O(n \times C)$, and the space complexity is $O(n)$. Here, $n$ is the length of string $s$, and $C$ is the size of the digit set, which is 10 in this problem.</p>
8145481459
<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>
8145581460
<div class="tabbed-content">
8145681461
<div class="tabbed-block">

0 commit comments

Comments
 (0)