Skip to content

Commit 8103ffc

Browse files
committed
deploy: be7a64e
1 parent caab71b commit 8103ffc

File tree

7 files changed

+93
-139
lines changed

7 files changed

+93
-139
lines changed

en/lc/1572/index.html

Lines changed: 25 additions & 56 deletions
Large diffs are not rendered by default.

en/lc/1573/index.html

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40297,9 +40297,9 @@
4029740297
<ul class="md-nav__list">
4029840298

4029940299
<li class="md-nav__item">
40300-
<a href="#solution-1" class="md-nav__link">
40300+
<a href="#solution-1-counting" class="md-nav__link">
4030140301
<span class="md-ellipsis">
40302-
Solution 1
40302+
Solution 1: Counting
4030340303
</span>
4030440304
</a>
4030540305

@@ -80721,7 +80721,16 @@ <h2 id="description">Description</h2>
8072180721
<h2 id="solutions">Solutions</h2>
8072280722
<!-- solution:start -->
8072380723

80724-
<h3 id="solution-1">Solution 1</h3>
80724+
<h3 id="solution-1-counting">Solution 1: Counting</h3>
80725+
<p>First, we traverse the string $s$ and count the number of characters $1$, denoted as $cnt$. If $cnt$ cannot be divided by $3$, then it is impossible to split the string, so we directly return $0$. If $cnt$ is $0$, it means there are no characters $1$ in the string. We can choose any two positions out of $n-1$ positions to split the string into three substrings, so the number of ways is $C_{n-1}^2$.</p>
80726+
<p>If $cnt \gt 0$, we update $cnt$ to $\frac{cnt}{3}$, which is the number of characters $1$ in each substring.</p>
80727+
<p>Next, we find the minimum index of the right boundary of the first substring, denoted as $i_1$, and the maximum index of the right boundary of the first substring (exclusive), denoted as $i_2$. Similarly, we find the minimum index of the right boundary of the second substring, denoted as $j_1$, and the maximum index of the right boundary of the second substring (exclusive), denoted as $j_2$. Then the number of ways is $(i_2 - i_1) \times (j_2 - j_1)$.</p>
80728+
<p>Note that the answer may be very large, so we need to take the modulo $10^9+7$.</p>
80729+
<p>The time complexity is $O(n)$, and the space complexity is $O(1)$. Here, $n$ is the length of the string $s$.</p>
80730+
<p>Similar problems:</p>
80731+
<ul>
80732+
<li><a href="https://github.com/doocs/leetcode/blob/main/solution/0900-0999/0927.Three%20Equal%20Parts/README_EN.md">927. Three Equal Parts</a></li>
80733+
</ul>
8072580734
<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>
8072680735
<div class="tabbed-content">
8072780736
<div class="tabbed-block">

en/lc/1574/index.html

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40318,18 +40318,18 @@
4031840318
<ul class="md-nav__list">
4031940319

4032040320
<li class="md-nav__item">
40321-
<a href="#solution-1" class="md-nav__link">
40321+
<a href="#solution-1-two-pointers-binary-search" class="md-nav__link">
4032240322
<span class="md-ellipsis">
40323-
Solution 1
40323+
Solution 1: Two Pointers + Binary Search
4032440324
</span>
4032540325
</a>
4032640326

4032740327
</li>
4032840328

4032940329
<li class="md-nav__item">
40330-
<a href="#solution-2" class="md-nav__link">
40330+
<a href="#solution-2-two-pointers" class="md-nav__link">
4033140331
<span class="md-ellipsis">
40332-
Solution 2
40332+
Solution 2: Two Pointers
4033340333
</span>
4033440334
</a>
4033540335

@@ -80745,7 +80745,12 @@ <h2 id="description">Description</h2>
8074580745
<h2 id="solutions">Solutions</h2>
8074680746
<!-- solution:start -->
8074780747

80748-
<h3 id="solution-1">Solution 1</h3>
80748+
<h3 id="solution-1-two-pointers-binary-search">Solution 1: Two Pointers + Binary Search</h3>
80749+
<p>First, we find the longest non-decreasing prefix and the longest non-decreasing suffix of the array, denoted as $\textit{nums}[0..i]$ and $\textit{nums}[j..n-1]$, respectively.</p>
80750+
<p>If $i \geq j$, it means the array is already non-decreasing, so we return $0$.</p>
80751+
<p>Otherwise, we can choose to delete the right suffix or the left prefix. Therefore, initially, the answer is $\min(n - i - 1, j)$.</p>
80752+
<p>Next, we enumerate the right endpoint $l$ of the left prefix. For each $l$, we can use binary search to find the first position greater than or equal to $\textit{nums}[l]$ in $\textit{nums}[j..n-1]$, denoted as $r$. At this point, we can delete $\textit{nums}[l+1..r-1]$ and update the answer $\textit{ans} = \min(\textit{ans}, r - l - 1)$. Continue enumerating $l$ to get the final answer.</p>
80753+
<p>The time complexity is $O(n \times \log n)$, where $n$ is the length of the array. The space complexity is $O(1)$.</p>
8074980754
<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>
8075080755
<div class="tabbed-content">
8075180756
<div class="tabbed-block">
@@ -80942,7 +80947,12 @@ <h3 id="solution-1">Solution 1</h3>
8094280947

8094380948
<!-- solution:start -->
8094480949

80945-
<h3 id="solution-2">Solution 2</h3>
80950+
<h3 id="solution-2-two-pointers">Solution 2: Two Pointers</h3>
80951+
<p>Similar to Solution 1, we first find the longest non-decreasing prefix and the longest non-decreasing suffix of the array, denoted as $\textit{nums}[0..i]$ and $\textit{nums}[j..n-1]$, respectively.</p>
80952+
<p>If $i \geq j$, it means the array is already non-decreasing, so we return $0$.</p>
80953+
<p>Otherwise, we can choose to delete the right suffix or the left prefix. Therefore, initially, the answer is $\min(n - i - 1, j)$.</p>
80954+
<p>Next, we enumerate the right endpoint $l$ of the left prefix. For each $l$, we directly use two pointers to find the first position greater than or equal to $\textit{nums}[l]$ in $\textit{nums}[j..n-1]$, denoted as $r$. At this point, we can delete $\textit{nums}[l+1..r-1]$ and update the answer $\textit{ans} = \min(\textit{ans}, r - l - 1)$. Continue enumerating $l$ to get the final answer.</p>
80955+
<p>The time complexity is $O(n)$, where $n$ is the length of the array. The space complexity is $O(1)$.</p>
8094680956
<div class="tabbed-set tabbed-alternate" data-tabs="2:6"><input checked="checked" id="__tabbed_2_1" name="__tabbed_2" type="radio" /><input id="__tabbed_2_2" name="__tabbed_2" type="radio" /><input id="__tabbed_2_3" name="__tabbed_2" type="radio" /><input id="__tabbed_2_4" name="__tabbed_2" type="radio" /><input id="__tabbed_2_5" name="__tabbed_2" type="radio" /><input id="__tabbed_2_6" name="__tabbed_2" type="radio" /><div class="tabbed-labels"><label for="__tabbed_2_1">Python3</label><label for="__tabbed_2_2">Java</label><label for="__tabbed_2_3">C++</label><label for="__tabbed_2_4">Go</label><label for="__tabbed_2_5">TypeScript</label><label for="__tabbed_2_6">JavaScript</label></div>
8094780957
<div class="tabbed-content">
8094880958
<div class="tabbed-block">
@@ -81222,14 +81232,14 @@ <h3 id="solution-2">Solution 2</h3>
8122281232

8122381233
<nav>
8122481234

81225-
<a href="https://github.com/rain84" class="md-author" title="@rain84">
81235+
<a href="https://github.com/yanglbme" class="md-author" title="@yanglbme">
8122681236

81227-
<img src="https://avatars.githubusercontent.com/u/1732547?v=4&size=72" alt="rain84">
81237+
<img src="https://avatars.githubusercontent.com/u/21008209?v=4&size=72" alt="yanglbme">
8122881238
</a>
8122981239

81230-
<a href="https://github.com/yanglbme" class="md-author" title="@yanglbme">
81240+
<a href="https://github.com/rain84" class="md-author" title="@rain84">
8123181241

81232-
<img src="https://avatars.githubusercontent.com/u/21008209?v=4&size=72" alt="yanglbme">
81242+
<img src="https://avatars.githubusercontent.com/u/1732547?v=4&size=72" alt="rain84">
8123381243
</a>
8123481244

8123581245
<a href="https://github.com/LjyYano" class="md-author" title="@LjyYano">

en/search/search_index.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)