Skip to content

Commit 872e5fa

Browse files
committed
deploy: dc4d031
1 parent 5194833 commit 872e5fa

File tree

6 files changed

+28
-19
lines changed

6 files changed

+28
-19
lines changed

en/lc/2526/index.html

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60260,9 +60260,9 @@
6026060260
<ul class="md-nav__list">
6026160261

6026260262
<li class="md-nav__item">
60263-
<a href="#solution-1" class="md-nav__link">
60263+
<a href="#solution-1-counting" class="md-nav__link">
6026460264
<span class="md-ellipsis">
60265-
Solution 1
60265+
Solution 1: Counting
6026660266
</span>
6026760267
</a>
6026860268

@@ -80136,11 +80136,11 @@ <h2 id="description">Description</h2>
8013680136
[null, false, false, true, false]
8013780137

8013880138
<strong>Explanation</strong>
80139-
DataStream dataStream = new DataStream(4, 3); //value = 4, k = 3
80140-
dataStream.consec(4); // Only 1 integer is parsed, so returns False.
80139+
DataStream dataStream = new DataStream(4, 3); //value = 4, k = 3
80140+
dataStream.consec(4); // Only 1 integer is parsed, so returns False.
8014180141
dataStream.consec(4); // Only 2 integers are parsed.
80142-
// Since 2 is less than k, returns False.
80143-
dataStream.consec(4); // The 3 integers parsed are all equal to value, so returns True.
80142+
// Since 2 is less than k, returns False.
80143+
dataStream.consec(4); // The 3 integers parsed are all equal to value, so returns True.
8014480144
dataStream.consec(3); // The last k integers parsed in the stream are [4,4,3].
8014580145
// Since 3 is not equal to value, it returns False.
8014680146
</pre>
@@ -80159,7 +80159,10 @@ <h2 id="description">Description</h2>
8015980159
<h2 id="solutions">Solutions</h2>
8016080160
<!-- solution:start -->
8016180161

80162-
<h3 id="solution-1">Solution 1</h3>
80162+
<h3 id="solution-1-counting">Solution 1: Counting</h3>
80163+
<p>We can maintain a counter $\textit{cnt}$ to record the current number of consecutive integers equal to $\textit{value}$.</p>
80164+
<p>When calling the <code>consec</code> method, if $\textit{num}$ is equal to $\textit{value}$, we increment $\textit{cnt}$ by 1; otherwise, we reset $\textit{cnt}$ to 0. Then we check whether $\textit{cnt}$ is greater than or equal to $\textit{k}$.</p>
80165+
<p>The time complexity is $O(1)$, and the space complexity is $O(1)$.</p>
8016380166
<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>
8016480167
<div class="tabbed-content">
8016580168
<div class="tabbed-block">

en/lc/2528/index.html

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60302,9 +60302,9 @@
6030260302
<ul class="md-nav__list">
6030360303

6030460304
<li class="md-nav__item">
60305-
<a href="#solution-1" class="md-nav__link">
60305+
<a href="#solution-1-binary-search-difference-array-greedy" class="md-nav__link">
6030660306
<span class="md-ellipsis">
60307-
Solution 1
60307+
Solution 1: Binary Search + Difference Array + Greedy
6030860308
</span>
6030960309
</a>
6031060310

@@ -80144,8 +80144,8 @@ <h2 id="description">Description</h2>
8014480144
<pre>
8014580145
<strong>Input:</strong> stations = [1,2,4,5,0], r = 1, k = 2
8014680146
<strong>Output:</strong> 5
80147-
<strong>Explanation:</strong>
80148-
One of the optimal ways is to install both the power stations at city 1.
80147+
<strong>Explanation:</strong>
80148+
One of the optimal ways is to install both the power stations at city 1.
8014980149
So stations will become [1,4,4,5,0].
8015080150
- City 0 is provided by 1 + 4 = 5 power stations.
8015180151
- City 1 is provided by 1 + 4 + 4 = 9 power stations.
@@ -80161,7 +80161,7 @@ <h2 id="description">Description</h2>
8016180161
<pre>
8016280162
<strong>Input:</strong> stations = [4,4,4,4], r = 0, k = 3
8016380163
<strong>Output:</strong> 4
80164-
<strong>Explanation:</strong>
80164+
<strong>Explanation:</strong>
8016580165
It can be proved that we cannot make the minimum power of a city greater than 4.
8016680166
</pre>
8016780167

@@ -80181,7 +80181,13 @@ <h2 id="description">Description</h2>
8018180181
<h2 id="solutions">Solutions</h2>
8018280182
<!-- solution:start -->
8018380183

80184-
<h3 id="solution-1">Solution 1</h3>
80184+
<h3 id="solution-1-binary-search-difference-array-greedy">Solution 1: Binary Search + Difference Array + Greedy</h3>
80185+
<p>According to the problem description, the minimum number of power stations increases as the value of $k$ increases. Therefore, we can use binary search to find the largest minimum number of power stations, ensuring that the additional power stations needed do not exceed $k$.</p>
80186+
<p>First, we use a difference array and prefix sum to calculate the initial number of power stations in each city, recording it in the array $s$, where $s[i]$ represents the number of power stations in the $i$-th city.</p>
80187+
<p>Next, we define the left boundary of the binary search as $0$ and the right boundary as $2^{40}$. Then, we implement a function $check(x, k)$ to determine whether the minimum number of power stations in the cities can be $x$, ensuring that the additional power stations needed do not exceed $k$.</p>
80188+
<p>The implementation logic of the function $check(x, k)$ is as follows:</p>
80189+
<p>Traverse each city. If the number of power stations in the current city $i$ is less than $x$, we can greedily build a power station at the rightmost possible position, $j = \min(i + r, n - 1)$, to cover as many cities as possible. During this process, we can use the difference array to add a certain value to a continuous segment. If the number of additional power stations needed exceeds $k$, then $x$ does not meet the condition, and we return <code>false</code>. Otherwise, after the traversal, return <code>true</code>.</p>
80190+
<p>The time complexity is $O(n \times \log M)$, and the space complexity is $O(n)$. Here, $n$ is the number of cities, and $M$ is fixed at $2^{40}$.</p>
8018580191
<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>
8018680192
<div class="tabbed-content">
8018780193
<div class="tabbed-block">

en/search/search_index.json

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

lc/2526/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84737,7 +84737,7 @@ <h2 id="_1">题目描述</h2>
8473784737
[null, false, false, true, false]
8473884738

8473984739
<strong>解释:</strong>
84740-
DataStream dataStream = new DataStream(4, 3); // value = 4, k = 3
84740+
DataStream dataStream = new DataStream(4, 3); // value = 4, k = 3
8474184741
dataStream.consec(4); // 数据流中只有 1 个整数,所以返回 False 。
8474284742
dataStream.consec(4); // 数据流中只有 2 个整数
8474384743
// 由于 2 小于 k ,返回 False 。
@@ -84762,8 +84762,8 @@ <h2 id="_2">解法</h2>
8476284762
<!-- solution:start -->
8476384763

8476484764
<h3 id="_3">方法一:计数</h3>
84765-
<p>维护一个计数器 $cnt$,记录当前连续整数为 <code>value</code> 的个数。</p>
84766-
<p> <code>num</code> 与 <code>value</code> 相等时,$cnt$ 自增 1,否则 $cnt$ 重置为 0。然后判断 $cnt$ 是否大于等于 <code>k</code> 即可。</p>
84765+
<p>我们可以维护一个计数器 $\textit{cnt}$,记录当前连续整数为 $\textit{value}$ 的个数。</p>
84766+
<p>调用 <code>consec</code> 方法时,如果 $\textit{num}$ 与 $\textit{value}$ 相等,我们将 $\textit{cnt}$ 自增 1,否则将 $\textit{cnt}$ 重置为 0。然后判断 $\textit{cnt}$ 是否大于等于 $\textit{k}$ 即可。</p>
8476784767
<p>时间复杂度 $O(1)$,空间复杂度 $O(1)$。</p>
8476884768
<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>
8476984769
<div class="tabbed-content">

lc/2528/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84788,7 +84788,7 @@ <h3 id="_3">方法一:二分查找 + 差分数组 + 贪心</h3>
8478884788
<p>我们先利用差分数组以及前缀和算出初始时每座城市的供电站数目,记录在数组 $s$ 中,其中 $s[i]$ 表示第 $i$ 座城市的供电站数目。</p>
8478984789
<p>接下来,我们定义二分查找的左边界为 $0$,右边界为 $2^{40}$。然后实现一个 $check(x, k)$ 函数,用于判断是否城市供电站数目的最小值是否可以为 $x$,使得额外建造的供电站不超过 $k$ 座。</p>
8479084790
<p>函数 $check(x, k)$ 的实现逻辑是:</p>
84791-
<p>遍历每座城市,如果当前城市 $i$ 的供电站数目小于 $x$,此时我们可以贪心地在尽可能右边的位置上建造供电站,位置 $j = min(i + r, n - 1)$,这样可以使得供电站覆盖尽可能多的城市。过程中我们可以借助差分数组,给一段连续的位置加上某个值。如果需要额外建造的供电站数量超过 $k$,那么 $x$ 不满足条件,返回 <code>false</code>。否则遍历结束后,返回 <code>true</code>。</p>
84791+
<p>遍历每座城市,如果当前城市 $i$ 的供电站数目小于 $x$,此时我们可以贪心地在尽可能右边的位置上建造供电站,位置 $j = \min(i + r, n - 1)$,这样可以使得供电站覆盖尽可能多的城市。过程中我们可以借助差分数组,给一段连续的位置加上某个值。如果需要额外建造的供电站数量超过 $k$,那么 $x$ 不满足条件,返回 <code>false</code>。否则遍历结束后,返回 <code>true</code>。</p>
8479284792
<p>时间复杂度 $O(n \times \log M)$,空间复杂度 $O(n)$。其中 $n$ 为城市数量,而 $M$ 我们固定取 $2^{40}$。</p>
8479384793
<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>
8479484794
<div class="tabbed-content">

search/search_index.json

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

0 commit comments

Comments
 (0)