Skip to content

Commit 164e615

Browse files
committed
deploy: 5718c16
1 parent e270210 commit 164e615

File tree

8 files changed

+580
-204
lines changed

8 files changed

+580
-204
lines changed

en/lc/722/index.html

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23333,9 +23333,9 @@
2333323333
<ul class="md-nav__list">
2333423334

2333523335
<li class="md-nav__item">
23336-
<a href="#solution-1" class="md-nav__link">
23336+
<a href="#solution-1-case-analysis" class="md-nav__link">
2333723337
<span class="md-ellipsis">
23338-
Solution 1
23338+
Solution 1: Case Analysis
2333923339
</span>
2334023340
</a>
2334123341

@@ -86403,19 +86403,19 @@ <h2 id="description">Description</h2>
8640386403
<strong>Explanation:</strong> The line by line code is visualized as below:
8640486404
/*Test program */
8640586405
int main()
86406-
{
86407-
// variable declaration
86406+
{
86407+
// variable declaration
8640886408
int a, b, c;
8640986409
/* This is a test
86410-
multiline
86411-
comment for
86410+
multiline
86411+
comment for
8641286412
testing */
8641386413
a = b + c;
8641486414
}
8641586415
The string /* denotes a block comment, including line 1 and lines 6-9. The string // denotes line 4 as comments.
8641686416
The line by line output code is visualized as below:
8641786417
int main()
86418-
{
86418+
{
8641986419

8642086420
int a, b, c;
8642186421
a = b + c;
@@ -86446,7 +86446,13 @@ <h2 id="description">Description</h2>
8644686446
<h2 id="solutions">Solutions</h2>
8644786447
<!-- solution:start -->
8644886448

86449-
<h3 id="solution-1">Solution 1</h3>
86449+
<h3 id="solution-1-case-analysis">Solution 1: Case Analysis</h3>
86450+
<p>We use a variable <span class="arithmatex">\(\textit{blockComment}\)</span> to indicate whether we are currently in a block comment. Initially, <span class="arithmatex">\(\textit{blockComment}\)</span> is <code>false</code>. We use a variable <span class="arithmatex">\(t\)</span> to store the valid characters of the current line.</p>
86451+
<p>Next, we traverse each line and discuss the following cases:</p>
86452+
<p>If we are currently in a block comment, and the current character and the next character are <code>'*/'</code>, it means the block comment ends. We set <span class="arithmatex">\(\textit{blockComment}\)</span> to <code>false</code> and skip these two characters. Otherwise, we continue in the block comment state without doing anything.</p>
86453+
<p>If we are not currently in a block comment, and the current character and the next character are <code>'/*'</code>, it means a block comment starts. We set <span class="arithmatex">\(\textit{blockComment}\)</span> to <code>true</code> and skip these two characters. If the current character and the next character are <code>'//'</code>, it means a line comment starts, and we exit the current line traversal. Otherwise, the current character is a valid character, and we add it to <span class="arithmatex">\(t\)</span>.</p>
86454+
<p>After traversing the current line, if <span class="arithmatex">\(\textit{blockComment}\)</span> is <code>false</code> and <span class="arithmatex">\(t\)</span> is not empty, it means the current line is valid. We add it to the answer array and clear <span class="arithmatex">\(t\)</span>. Continue to traverse the next line.</p>
86455+
<p>The time complexity is <span class="arithmatex">\(O(L)\)</span>, and the space complexity is <span class="arithmatex">\(O(L)\)</span>, where <span class="arithmatex">\(L\)</span> is the total length of the source code.</p>
8645086456
<div class="tabbed-set tabbed-alternate" data-tabs="1:6"><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" /><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></div>
8645186457
<div class="tabbed-content">
8645286458
<div class="tabbed-block">

en/lc/727/index.html

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23443,9 +23443,9 @@
2344323443
<ul class="md-nav__list">
2344423444

2344523445
<li class="md-nav__item">
23446-
<a href="#solution-1" class="md-nav__link">
23446+
<a href="#solution-1-dynamic-programming" class="md-nav__link">
2344723447
<span class="md-ellipsis">
23448-
Solution 1
23448+
Solution 1: Dynamic Programming
2344923449
</span>
2345023450
</a>
2345123451

@@ -86378,7 +86378,7 @@ <h2 id="description">Description</h2>
8637886378
<pre>
8637986379
<strong>Input:</strong> s1 = &quot;abcdebdde&quot;, s2 = &quot;bde&quot;
8638086380
<strong>Output:</strong> &quot;bcde&quot;
86381-
<strong>Explanation:</strong>
86381+
<strong>Explanation:</strong>
8638286382
&quot;bcde&quot; is the answer because it occurs before &quot;bdde&quot; which has the same length.
8638386383
&quot;deb&quot; is not a smaller window because the elements of s2 in the window must occur in order.
8638486384
</pre>
@@ -86404,7 +86404,18 @@ <h2 id="description">Description</h2>
8640486404
<h2 id="solutions">Solutions</h2>
8640586405
<!-- solution:start -->
8640686406

86407-
<h3 id="solution-1">Solution 1</h3>
86407+
<h3 id="solution-1-dynamic-programming">Solution 1: Dynamic Programming</h3>
86408+
<p>We define <span class="arithmatex">\(f[i][j]\)</span> to represent the starting position of the shortest substring of the first <span class="arithmatex">\(i\)</span> characters of string <span class="arithmatex">\(\textit{s1}\)</span> that contains the first <span class="arithmatex">\(j\)</span> characters of string <span class="arithmatex">\(\textit{s2}\)</span>. If it does not exist, it is <span class="arithmatex">\(0\)</span>.</p>
86409+
<p>We can derive the state transition equation:</p>
86410+
<div class="arithmatex">\[
86411+
f[i][j] = \begin{cases}
86412+
i, &amp; j = 1 \textit{ and } s1[i-1] = s2[j] \\
86413+
f[i - 1][j - 1], &amp; j &gt; 1 \textit{ and } s1[i-1] = s2[j-1] \\
86414+
f[i - 1][j], &amp; s1[i-1] \ne s2[j-1]
86415+
\end{cases}
86416+
\]</div>
86417+
<p>Next, we only need to traverse <span class="arithmatex">\(\textit{s1}\)</span>. If <span class="arithmatex">\(f[i][n] \gt 0\)</span>, update the starting position and length of the shortest substring. Finally, return the shortest substring.</p>
86418+
<p>The time complexity is <span class="arithmatex">\(O(m \times n)\)</span>, and the space complexity is <span class="arithmatex">\(O(m \times n)\)</span>. Here, <span class="arithmatex">\(m\)</span> and <span class="arithmatex">\(n\)</span> are the lengths of strings <span class="arithmatex">\(\textit{s1}\)</span> and <span class="arithmatex">\(\textit{s2}\)</span>, respectively.</p>
8640886419
<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>
8640986420
<div class="tabbed-content">
8641086421
<div class="tabbed-block">

0 commit comments

Comments
 (0)