Skip to content

Commit dc59e8c

Browse files
committed
deploy: 468d402
1 parent 6ae3712 commit dc59e8c

File tree

11 files changed

+34
-29
lines changed

11 files changed

+34
-29
lines changed

en/lc/400/index.html

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

1524215242
<li class="md-nav__item">
15243-
<a href="#solution-1" class="md-nav__link">
15243+
<a href="#solution-1-mathematics" class="md-nav__link">
1524415244
<span class="md-ellipsis">
15245-
Solution 1
15245+
Solution 1: Mathematics
1524615246
</span>
1524715247
</a>
1524815248

@@ -75827,7 +75827,12 @@ <h2 id="description">Description</h2>
7582775827
<h2 id="solutions">Solutions</h2>
7582875828
<!-- solution:start -->
7582975829

75830-
<h3 id="solution-1">Solution 1</h3>
75830+
<h3 id="solution-1-mathematics">Solution 1: Mathematics</h3>
75831+
<p>The smallest and largest integers with $k$ digits are $10^{k-1}$ and $10^k-1$ respectively, so the total number of digits for $k$-digit numbers is $k \times 9 \times 10^{k-1}$.</p>
75832+
<p>We use $k$ to represent the number of digits of the current number, and $cnt$ to represent the total number of numbers with the current number of digits. Initially, $k=1$, $cnt=9$.</p>
75833+
<p>Each time we subtract $cnt \times k$ from $n$, when $n$ is less than or equal to $cnt \times k$, it means that the number corresponding to $n$ is within the range of numbers with the current number of digits. At this time, we can calculate the corresponding number.</p>
75834+
<p>The specific method is to first calculate which number of the current number of digits corresponds to $n$, and then calculate which digit of this number it is, so as to get the number on this digit.</p>
75835+
<p>The time complexity is $O(\log_{10} n)$.</p>
7583175836
<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">JavaScript</label><label for="__tabbed_1_6">C#</label></div>
7583275837
<div class="tabbed-content">
7583375838
<div class="tabbed-block">

en/search/search_index.json

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

lcof/41/index.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74227,7 +74227,7 @@
7422774227
<li class="md-nav__item">
7422874228
<a href="#_4" class="md-nav__link">
7422974229
<span class="md-ellipsis">
74230-
方法二
74230+
方法二:有序列表
7423174231
</span>
7423274232
</a>
7423374233

@@ -81067,7 +81067,9 @@ <h3 id="_3">方法一:优先队列(大小根堆)</h3>
8106781067

8106881068
<!-- solution:start-->
8106981069

81070-
<h3 id="_4">方法二</h3>
81070+
<h3 id="_4">方法二:有序列表</h3>
81071+
<p>我们也可以使用一个有序列表来维护数据流中的元素,这样我们就可以直接通过索引来获取中位数。</p>
81072+
<p>时间复杂度方面,添加元素的时间复杂度为 $O(\log n)$,查找中位数的时间复杂度为 $O(1)$。空间复杂度为 $O(n)$。其中 $n$ 为数据流中元素的个数。</p>
8107181073
<div class="tabbed-set tabbed-alternate" data-tabs="2:1"><input checked="checked" id="__tabbed_2_1" name="__tabbed_2" type="radio" /><div class="tabbed-labels"><label for="__tabbed_2_1">Python3</label></div>
8107281074
<div class="tabbed-content">
8107381075
<div class="tabbed-block">

lcof/42/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80424,7 +80424,7 @@ <h3 id="_3">方法一:动态规划</h3>
8042480424
f[i] = \max(f[i-1], 0) + nums[i]
8042580425
$$</p>
8042680426
<p>我们可以不用开一个数组来存储所有的计算结果,而是只用两个变量 $f$ 和 $ans$ 来维护对于每一个位置 $i$ 我们的最大值,这样我们可以省去空间复杂度的开销。</p>
80427-
<p>时间复杂度 $O(n)$,空间复杂度 $O(1)$。其中 $n$ 为数组长度。</p>
80427+
<p>时间复杂度 $O(n)$,其中 $n$ 为数组长度。空间复杂度 $O(1)$。</p>
8042880428
<div class="tabbed-set tabbed-alternate" data-tabs="1:8"><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" /><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></div>
8042980429
<div class="tabbed-content">
8043080430
<div class="tabbed-block">

lcof/45/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80415,7 +80415,7 @@ <h2 id="_2">解法</h2>
8041580415
<!-- solution:start -->
8041680416

8041780417
<h3 id="_3">方法一:自定义排序</h3>
80418-
<p>将数组中的数字转换为字符串,然后按照字符串拼接的大小进行排序。具体地,比较两个字符串 $a$ 和 $b$,如果 $a + b \lt b + a$,则 $a$ 小于 $b$,否则 $a$ 大于 $b$。</p>
80418+
<p>我们将数组中的数字转换为字符串,然后按照字符串拼接的大小进行排序。具体地,比较两个字符串 $a$ 和 $b$,如果 $a + b \lt b + a$,则 $a$ 小于 $b$,否则 $a$ 大于 $b$。</p>
8041980419
<p>时间复杂度 $O(n \times \log n + n \times m)$,空间复杂度 $O(n \times m)$。其中 $n $ 和 $m$ 分别为数组的长度和字符串的平均长度。</p>
8042080420
<div class="tabbed-set tabbed-alternate" data-tabs="1:8"><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" /><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></div>
8042180421
<div class="tabbed-content">

lcof/47/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74353,7 +74353,7 @@
7435374353
<li class="md-nav__item">
7435474354
<a href="#_4" class="md-nav__link">
7435574355
<span class="md-ellipsis">
74356-
方法二
74356+
方法二:动态规划(空间优化)
7435774357
</span>
7435874358
</a>
7435974359

@@ -80425,7 +80425,6 @@ <h3 id="_3">方法一:动态规划</h3>
8042580425
$$</p>
8042680426
<p>答案为 $f[m][n]$。</p>
8042780427
<p>时间复杂度 $O(m \times n)$,空间复杂度 $O(m \times n)$。其中 $m$ 和 $n$ 分别为棋盘的行数和列数。</p>
80428-
<p>我们注意到 $f[i][j]$ 只与 $f[i-1][j]$ 和 $f[i][j-1]$ 有关,因此我们可以仅用两行数组 $f[2][n+1]$ 来存储状态,从而将空间复杂度优化到 $O(n)$。</p>
8042980428
<div class="tabbed-set tabbed-alternate" data-tabs="1:8"><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" /><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></div>
8043080429
<div class="tabbed-content">
8043180430
<div class="tabbed-block">
@@ -80654,7 +80653,8 @@ <h3 id="_3">方法一:动态规划</h3>
8065480653

8065580654
<!-- solution:start-->
8065680655

80657-
<h3 id="_4">方法二</h3>
80656+
<h3 id="_4">方法二:动态规划(空间优化)</h3>
80657+
<p>我们注意到 $f[i][j]$ 只与 $f[i-1][j]$ 和 $f[i][j-1]$ 有关,因此我们可以仅用两行数组 $f[2][n+1]$ 来存储状态,从而将空间复杂度优化到 $O(n)$。</p>
8065880658
<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>
8065980659
<div class="tabbed-content">
8066080660
<div class="tabbed-block">

lcof/48/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80432,7 +80432,7 @@ <h2 id="_2">解法</h2>
8043280432

8043380433
<h3 id="_3">方法一:双指针 + 哈希表</h3>
8043480434
<p>我们用双指针 $j$ 和 $i$ 分别表示子串的左右边界,其中 $j$ 是滑动窗口的左边界,$i$ 是滑动窗口的右边界,用哈希表 $vis$ 记录每个字符是否出现过。</p>
80435-
<p>遍历字符串 $s$,如果此时 $s[i]$ 在哈希表 $vis$ 中存在,说明 $s[i]$ 重复了,我们需要将左边界 $j$ 右移,直到 $s[i]$ 不在哈希表 $vis$ 中为止,然后将 $s[i]$ 加入哈希表 $vis$ 中。此时,我们更新无重复字符子串的最大长度,即 $ans = max(ans, i - j + 1)$。</p>
80435+
<p>遍历字符串 $s$,如果此时 $s[i]$ 在哈希表 $vis$ 中存在,说明 $s[i]$ 重复了,我们需要将左边界 $j$ 右移,直到 $s[i]$ 不在哈希表 $vis$ 中为止,然后将 $s[i]$ 加入哈希表 $vis$ 中。此时,我们更新无重复字符子串的最大长度,即 $ans = \max(ans, i - j + 1)$。</p>
8043680436
<p>遍历结束后,我们返回 $ans$ 即可。</p>
8043780437
<p>时间复杂度 $O(n)$,空间复杂度 $O(C)$。其中 $n$ 是字符串 $s$ 的长度;而 $C$ 是字符集的大小。</p>
8043880438
<div class="tabbed-set tabbed-alternate" data-tabs="1:8"><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" /><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></div>

lcof/49/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80753,7 +80753,7 @@ <h3 id="_3">方法一:优先队列(最小堆)</h3>
8075380753
<!-- solution:start-->
8075480754

8075580755
<h3 id="_4">方法二:动态规划</h3>
80756-
<p>定义数组 $dp$,其中 $dp[i-1]$ 表示第 $i$ 个丑数,那么第 $n$ 个丑数就是 $dp[n - 1]$。最小的丑数是 $1$,所以 $dp[0]=1$。</p>
80756+
<p>我们定义数组 $dp$,其中 $dp[i-1]$ 表示第 $i$ 个丑数,那么第 $n$ 个丑数就是 $dp[n - 1]$。最小的丑数是 $1$,所以 $dp[0]=1$。</p>
8075780757
<p>定义 $3$ 个指针 $p_2$, $p_3$ 和 $p_5$,表示下一个丑数是当前指针指向的丑数乘以对应的质因数。初始时,三个指针的值都指向 $0$。</p>
8075880758
<p>当 $i$ 在 $[1,2..n-1]$ 范围内,我们更新 $dp[i]=\min(dp[p_2] \times 2, dp[p_3] \times 3, dp[p_5] \times 5)$,然后分别比较 $dp[i]$ 与 $dp[p_2] \times 2$, $dp[p_3] \times 3$, $dp[p_5] \times 5$ 是否相等,若是,则对应的指针加 $1$。</p>
8075980759
<p>最后返回 $dp[n - 1]$ 即可。</p>

0 commit comments

Comments
 (0)