Skip to content

Commit 06e2fc0

Browse files
committed
deploy: dee676e
1 parent 867f70b commit 06e2fc0

File tree

9 files changed

+1330
-37
lines changed

9 files changed

+1330
-37
lines changed

en/lc/1227/index.html

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79367,14 +79367,8 @@ <h2 id="solutions">Solutions</h2>
7936779367

7936879368
<h3 id="solution-1-mathematics">Solution 1: Mathematics</h3>
7936979369
<p>Let $f(n)$ represent the probability that the $n$th passenger will sit in their own seat when there are $n$ passengers boarding. Consider from the simplest case:</p>
79370-
<ul>
79371-
<li>
7937279370
<p>When $n=1$, there is only 1 passenger and 1 seat, so the first passenger can only sit in the first seat, $f(1)=1$;</p>
79373-
</li>
79374-
<li>
7937579371
<p>When $n=2$, there are 2 seats, each seat has a probability of 0.5 to be chosen by the first passenger. After the first passenger chooses a seat, the second passenger can only choose the remaining seat, so the second passenger has a probability of 0.5 to sit in their own seat, $f(2)=0.5$.</p>
79376-
</li>
79377-
</ul>
7937879372
<p>When $n&gt;2$, how to calculate the value of $f(n)$? Consider the seat chosen by the first passenger, there are three cases.</p>
7937979373
<ul>
7938079374
<li>

en/lc/1394/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79497,7 +79497,7 @@ <h3 id="solution-1-counting">Solution 1: Counting</h3>
7949779497
<span class="normal">11</span>
7949879498
<span class="normal">12</span>
7949979499
<span class="normal">13</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="kd">function</span><span class="w"> </span><span class="nx">findLucky</span><span class="p">(</span><span class="nx">arr</span><span class="o">:</span><span class="w"> </span><span class="kt">number</span><span class="p">[])</span><span class="o">:</span><span class="w"> </span><span class="kt">number</span><span class="w"> </span><span class="p">{</span>
79500-
<span class="w"> </span><span class="kd">const</span><span class="w"> </span><span class="nx">cnt</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ow">new</span><span class="w"> </span><span class="nb">Array</span><span class="p">(</span><span class="mf">510</span><span class="p">).</span><span class="nx">fill</span><span class="p">(</span><span class="mf">0</span><span class="p">);</span>
79500+
<span class="w"> </span><span class="kd">const</span><span class="w"> </span><span class="nx">cnt</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">Array</span><span class="p">(</span><span class="mf">510</span><span class="p">).</span><span class="nx">fill</span><span class="p">(</span><span class="mf">0</span><span class="p">);</span>
7950179501
<span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kd">const</span><span class="w"> </span><span class="nx">x</span><span class="w"> </span><span class="k">of</span><span class="w"> </span><span class="nx">arr</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
7950279502
<span class="w"> </span><span class="o">++</span><span class="nx">cnt</span><span class="p">[</span><span class="nx">x</span><span class="p">];</span>
7950379503
<span class="w"> </span><span class="p">}</span>

en/lc/1419/index.html

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36945,9 +36945,9 @@
3694536945
<ul class="md-nav__list">
3694636946

3694736947
<li class="md-nav__item">
36948-
<a href="#solution-1" class="md-nav__link">
36948+
<a href="#solution-1-counting-simulation" class="md-nav__link">
3694936949
<span class="md-ellipsis">
36950-
Solution 1
36950+
Solution 1: Counting + Simulation
3695136951
</span>
3695236952
</a>
3695336953

@@ -79327,16 +79327,16 @@ <h2 id="description">Description</h2>
7932779327

7932879328
<pre>
7932979329
<strong>Input:</strong> croakOfFrogs = &quot;croakcroak&quot;
79330-
<strong>Output:</strong> 1
79330+
<strong>Output:</strong> 1
7933179331
<strong>Explanation:</strong> One frog yelling &quot;croak<strong>&quot;</strong> twice.
7933279332
</pre>
7933379333

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

7933679336
<pre>
7933779337
<strong>Input:</strong> croakOfFrogs = &quot;crcoakroak&quot;
79338-
<strong>Output:</strong> 2
79339-
<strong>Explanation:</strong> The minimum number of frogs is two.
79338+
<strong>Output:</strong> 2
79339+
<strong>Explanation:</strong> The minimum number of frogs is two.
7934079340
The first frog could yell &quot;<strong>cr</strong>c<strong>oak</strong>roak&quot;.
7934179341
The second frog could yell later &quot;cr<strong>c</strong>oak<strong>roak</strong>&quot;.
7934279342
</pre>
@@ -79362,7 +79362,16 @@ <h2 id="description">Description</h2>
7936279362
<h2 id="solutions">Solutions</h2>
7936379363
<!-- solution:start -->
7936479364

79365-
<h3 id="solution-1">Solution 1</h3>
79365+
<h3 id="solution-1-counting-simulation">Solution 1: Counting + Simulation</h3>
79366+
<p>We note that if the string <code>croakOfFrogs</code> is composed of several valid <code>"croak"</code> characters mixed together, its length must be a multiple of $5$. Therefore, if the length of the string is not a multiple of $5$, we can directly return $-1$.</p>
79367+
<p>Next, we map the letters <code>'c'</code>, <code>'r'</code>, <code>'o'</code>, <code>'a'</code>, <code>'k'</code> to indices $0$ to $4$, respectively, and use an array $cnt$ of length $5$ to record the number of occurrences of each letter in the string <code>croakOfFrogs</code>, where $cnt[i]$ represents the number of occurrences of the letter at index $i$. Additionally, we define an integer variable $x$ to represent the number of frogs that have not completed their croak, and the minimum number of frogs needed $ans$ is the maximum value of $x$.</p>
79368+
<p>We traverse each letter $c$ in the string <code>croakOfFrogs</code>, find the index $i$ corresponding to $c$, and then increment $cnt[i]$ by $1$. Next, depending on the value of $i$, we perform the following operations:</p>
79369+
<ul>
79370+
<li>If $i=0$, then a new frog starts croaking, so we increment $x$ by $1$, and then update $ans = \max(ans, x)$;</li>
79371+
<li>Otherwise, if $cnt[i-1]=0$, it means that there is no frog that can make the sound $c$, and the croak cannot be completed, so we return $-1$. Otherwise, we decrement $cnt[i-1]$ by $1$. If $i=4$, it means that a frog has completed a croak, so we decrement $x$ by $1$.</li>
79372+
</ul>
79373+
<p>After traversing, if $x=0$, it means that all frogs have completed their croaks, and we return $ans$. Otherwise, we return $-1$.</p>
79374+
<p>The time complexity is $O(n)$, and the space complexity is $O(C)$. Where $n$ is the length of the string <code>croakOfFrogs</code>, and $C$ is the size of the character set, in this problem $C=26$.</p>
7936679375
<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>
7936779376
<div class="tabbed-content">
7936879377
<div class="tabbed-block">

0 commit comments

Comments
 (0)