Skip to content

Commit 9137ea1

Browse files
committed
deploy: da48265
1 parent b7d08e4 commit 9137ea1

File tree

8 files changed

+527
-543
lines changed

8 files changed

+527
-543
lines changed

en/lc/624/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86403,7 +86403,7 @@ <h2 id="solutions">Solutions</h2>
8640386403

8640486404
<h3 id="solution-1-maintain-maximum-and-minimum-values">Solution 1: Maintain Maximum and Minimum Values</h3>
8640586405
<p>We notice that the maximum distance must be the distance between the maximum value in one array and the minimum value in another array. Therefore, we can maintain two variables <span class="arithmatex">\(\textit{mi}\)</span> and <span class="arithmatex">\(\textit{mx}\)</span>, representing the minimum and maximum values of the arrays we have traversed. Initially, <span class="arithmatex">\(\textit{mi}\)</span> and <span class="arithmatex">\(\textit{mx}\)</span> are the first and last elements of the first array, respectively.</p>
86406-
<p>Next, we traverse from the second array. For each array, we first calculate the distance between the first element of the current array and <span class="arithmatex">\(\textit{mx}\)</span>, and the distance between the last element of the current array and <span class="arithmatex">\(\textit{mi}\)</span>. Then, we update the maximum distance. At the same time, we update <span class="arithmatex">\(\textit{mi}\)</span> and <span class="arithmatex">\(\textit{mx}\)</span> to be the first and last elements of the current array.</p>
86406+
<p>Next, we traverse from the second array. For each array, we first calculate the distance between the first element of the current array and <span class="arithmatex">\(\textit{mx}\)</span>, and the distance between the last element of the current array and <span class="arithmatex">\(\textit{mi}\)</span>. Then, we update the maximum distance. At the same time, we update <span class="arithmatex">\(\textit{mi} = \min(\textit{mi}, \textit{arr}[0])\)</span> and <span class="arithmatex">\(\textit{mx} = \max(\textit{mx}, \textit{arr}[\textit{size} - 1])\)</span>.</p>
8640786407
<p>After traversing all arrays, we get the maximum distance.</p>
8640886408
<p>The time complexity is <span class="arithmatex">\(O(m)\)</span>, where <span class="arithmatex">\(m\)</span> is the number of arrays. The space complexity is <span class="arithmatex">\(O(1)\)</span>.</p>
8640986409
<div class="tabbed-set tabbed-alternate" data-tabs="1:7"><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" /><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></div>

en/lc/657/index.html

Lines changed: 151 additions & 41 deletions
Large diffs are not rendered by default.

en/lc/863/index.html

Lines changed: 112 additions & 229 deletions
Large diffs are not rendered by default.

en/search/search_index.json

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

lc/624/index.html

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

9120391203
<h3 id="_3">方法一:维护最大值和最小值</h3>
9120491204
<p>我们注意到,最大距离一定是两个数组中的一个最大值和另一个最小值之间的距离。因此,我们可以维护两个变量 <span class="arithmatex">\(\textit{mi}\)</span> 和 <span class="arithmatex">\(\textit{mx}\)</span>,分别表示已经遍历过的数组中的最小值和最大值。初始时 <span class="arithmatex">\(\textit{mi}\)</span> 和 <span class="arithmatex">\(\textit{mx}\)</span> 分别为第一个数组的第一个元素和最后一个元素。</p>
91205-
<p>接下来,我们从第二个数组开始遍历,对于每个数组,我们首先计算当前数组的第一个元素和 <span class="arithmatex">\(\textit{mx}\)</span> 之间的距离,以及当前数组的最后一个元素和 <span class="arithmatex">\(\textit{mi}\)</span> 之间的距离,然后更新最大距离。同时,我们更新 <span class="arithmatex">\(\textit{mi}\)</span> 和 <span class="arithmatex">\(\textit{mx}\)</span> 为当前数组的第一个元素和最后一个元素。</p>
91205+
<p>接下来,我们从第二个数组开始遍历,对于每个数组,我们首先计算当前数组的第一个元素和 <span class="arithmatex">\(\textit{mx}\)</span> 之间的距离,以及当前数组的最后一个元素和 <span class="arithmatex">\(\textit{mi}\)</span> 之间的距离,然后更新最大距离。同时,我们更新 <span class="arithmatex">\(\textit{mi} = \min(\textit{mi}, \textit{arr}[0])\)</span> 和 <span class="arithmatex">\(\textit{mx} = \max(\textit{mx}, \textit{arr}[\textit{size} - 1])\)</span>。</p>
9120691206
<p>遍历结束后,即可得到最大距离。</p>
9120791207
<p>时间复杂度 <span class="arithmatex">\(O(m)\)</span>,其中 <span class="arithmatex">\(m\)</span> 为数组的个数。空间复杂度 <span class="arithmatex">\(O(1)\)</span>。</p>
9120891208
<div class="tabbed-set tabbed-alternate" data-tabs="1:7"><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" /><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></div>

0 commit comments

Comments
 (0)