Skip to content

Commit

Permalink
feat: add biweekly contest 137 (#3430)
Browse files Browse the repository at this point in the history
  • Loading branch information
yanglbme authored Aug 18, 2024
1 parent 584cf2d commit 4fdaa4c
Show file tree
Hide file tree
Showing 34 changed files with 1,477 additions and 43 deletions.
38 changes: 25 additions & 13 deletions solution/0600-0699/0624.Maximum Distance in Arrays/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,48 @@ tags:

<!-- problem:start -->

# [624. 数组列表中的最大距离 🔒](https://leetcode.cn/problems/maximum-distance-in-arrays)
# [624. 数组列表中的最大距离](https://leetcode.cn/problems/maximum-distance-in-arrays)

[English Version](/solution/0600-0699/0624.Maximum%20Distance%20in%20Arrays/README_EN.md)

## 题目描述

<!-- description:start -->

<p>给定&nbsp;<code>m</code>&nbsp;个数组,每个数组都已经按照升序排好序了。现在你需要从两个不同的数组中选择两个整数(每个数组选一个)并且计算它们的距离。两个整数&nbsp;<code>a</code>&nbsp;&nbsp;<code>b</code>&nbsp;之间的距离定义为它们差的绝对值&nbsp;<code>|a-b|</code>&nbsp;。你的任务就是去找到最大距离</p>
<p>给定&nbsp;<code>m</code>&nbsp;个数组,每个数组都已经按照升序排好序了。</p>

<p>现在你需要从两个不同的数组中选择两个整数(每个数组选一个)并且计算它们的距离。两个整数&nbsp;<code>a</code>&nbsp;&nbsp;<code>b</code>&nbsp;之间的距离定义为它们差的绝对值&nbsp;<code>|a-b|</code>&nbsp;。</p>

<p>返回最大距离。</p>

<p><strong>示例 1:</strong></p>

<pre><strong>输入:</strong>
[[1,2,3],
[4,5],
[1,2,3]]
<strong>输出:</strong> 4
<pre>
<strong>输入:</strong>[[1,2,3],[4,5],[1,2,3]]
<strong>输出:</strong>4
<strong>解释:</strong>
一种得到答案 4 的方法是从第一个数组或者第三个数组中选择 1,同时从第二个数组中选择 5 。
</pre>

<p><strong class="example">示例 2:</strong></p>

<pre>
<strong>输入:</strong>arrays = [[1],[1]]
<b>输出:</b>0
</pre>

<p>&nbsp;</p>

<p><strong>注意:</strong></p>
<p><strong>提示:</strong></p>

<ol>
<li>每个给定数组至少会有 1 个数字。列表中至少有两个非空数组。</li>
<li><strong>所有</strong>&nbsp;<code>m</code>&nbsp;个数组中的数字总数目在范围 [2, 10000] 内。</li>
<li><code>m</code>&nbsp;个数组中所有整数的范围在 [-10000, 10000] 内。</li>
</ol>
<ul>
<li><code>m == arrays.length</code></li>
<li><code>2 &lt;= m &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= arrays[i].length &lt;= 500</code></li>
<li><code>-10<sup>4</sup> &lt;= arrays[i][j] &lt;= 10<sup>4</sup></code></li>
<li><code>arrays[i]</code>&nbsp;以&nbsp;<strong>升序</strong>&nbsp;排序。</li>
<li>所有数组中最多有&nbsp;<code>10<sup>5</sup></code> 个整数。</li>
</ul>

<p>&nbsp;</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ tags:

<!-- problem:start -->

# [624. Maximum Distance in Arrays 🔒](https://leetcode.com/problems/maximum-distance-in-arrays)
# [624. Maximum Distance in Arrays](https://leetcode.com/problems/maximum-distance-in-arrays)

[中文文档](/solution/0600-0699/0624.Maximum%20Distance%20in%20Arrays/README.md)

Expand Down
4 changes: 2 additions & 2 deletions solution/0800-0899/0860.Lemonade Change/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ tags:
<pre>
<strong>Input:</strong> bills = [5,5,5,10,20]
<strong>Output:</strong> true
<strong>Explanation:</strong>
<strong>Explanation:</strong>
From the first 3 customers, we collect three $5 bills in order.
From the fourth customer, we collect a $10 bill and give back a $5.
From the fifth customer, we give a $10 bill and a $5 bill.
Expand All @@ -41,7 +41,7 @@ Since all customers got correct change, we output true.
<pre>
<strong>Input:</strong> bills = [5,5,10,10,20]
<strong>Output:</strong> false
<strong>Explanation:</strong>
<strong>Explanation:</strong>
From the first two customers in order, we collect two $5 bills.
For the next two customers in order, we collect a $10 bill and give back a $5 bill.
For the last customer, we can not give the change of $15 back because we only have two $10 bills.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ tags:
<p><strong>示例 1:</strong></p>

<pre><strong>输入:</strong>orders = [[&quot;David&quot;,&quot;3&quot;,&quot;Ceviche&quot;],[&quot;Corina&quot;,&quot;10&quot;,&quot;Beef Burrito&quot;],[&quot;David&quot;,&quot;3&quot;,&quot;Fried Chicken&quot;],[&quot;Carla&quot;,&quot;5&quot;,&quot;Water&quot;],[&quot;Carla&quot;,&quot;5&quot;,&quot;Ceviche&quot;],[&quot;Rous&quot;,&quot;3&quot;,&quot;Ceviche&quot;]]
<strong>输出:</strong>[[&quot;Table&quot;,&quot;Beef Burrito&quot;,&quot;Ceviche&quot;,&quot;Fried Chicken&quot;,&quot;Water&quot;],[&quot;3&quot;,&quot;0&quot;,&quot;2&quot;,&quot;1&quot;,&quot;0&quot;],[&quot;5&quot;,&quot;0&quot;,&quot;1&quot;,&quot;0&quot;,&quot;1&quot;],[&quot;10&quot;,&quot;1&quot;,&quot;0&quot;,&quot;0&quot;,&quot;0&quot;]]
<strong>输出:</strong>[[&quot;Table&quot;,&quot;Beef Burrito&quot;,&quot;Ceviche&quot;,&quot;Fried Chicken&quot;,&quot;Water&quot;],[&quot;3&quot;,&quot;0&quot;,&quot;2&quot;,&quot;1&quot;,&quot;0&quot;],[&quot;5&quot;,&quot;0&quot;,&quot;1&quot;,&quot;0&quot;,&quot;1&quot;],[&quot;10&quot;,&quot;1&quot;,&quot;0&quot;,&quot;0&quot;,&quot;0&quot;]]
<strong>解释:
</strong>点菜展示表如下所示:
<strong>Table,Beef Burrito,Ceviche,Fried Chicken,Water</strong>
Expand All @@ -42,13 +42,13 @@ tags:
10 ,1 ,0 ,0 ,0
对于餐桌 3:David 点了 &quot;Ceviche&quot;&quot;Fried Chicken&quot;,而 Rous 点了 &quot;Ceviche&quot;
而餐桌 5:Carla 点了 &quot;Water&quot;&quot;Ceviche&quot;
餐桌 10:Corina 点了 &quot;Beef Burrito&quot;
餐桌 10:Corina 点了 &quot;Beef Burrito&quot;
</pre>

<p><strong>示例 2:</strong></p>

<pre><strong>输入:</strong>orders = [[&quot;James&quot;,&quot;12&quot;,&quot;Fried Chicken&quot;],[&quot;Ratesh&quot;,&quot;12&quot;,&quot;Fried Chicken&quot;],[&quot;Amadeus&quot;,&quot;12&quot;,&quot;Fried Chicken&quot;],[&quot;Adam&quot;,&quot;1&quot;,&quot;Canadian Waffles&quot;],[&quot;Brianna&quot;,&quot;1&quot;,&quot;Canadian Waffles&quot;]]
<strong>输出:</strong>[[&quot;Table&quot;,&quot;Canadian Waffles&quot;,&quot;Fried Chicken&quot;],[&quot;1&quot;,&quot;2&quot;,&quot;0&quot;],[&quot;12&quot;,&quot;0&quot;,&quot;3&quot;]]
<strong>输出:</strong>[[&quot;Table&quot;,&quot;Canadian Waffles&quot;,&quot;Fried Chicken&quot;],[&quot;1&quot;,&quot;2&quot;,&quot;0&quot;],[&quot;12&quot;,&quot;0&quot;,&quot;3&quot;]]
<strong>解释:</strong>
对于餐桌 1:Adam 和 Brianna 都点了 &quot;Canadian Waffles&quot;
而餐桌 12:James, Ratesh 和 Amadeus 都点了 &quot;Fried Chicken&quot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ tags:

<strong>Input:</strong> orders = [[&quot;David&quot;,&quot;3&quot;,&quot;Ceviche&quot;],[&quot;Corina&quot;,&quot;10&quot;,&quot;Beef Burrito&quot;],[&quot;David&quot;,&quot;3&quot;,&quot;Fried Chicken&quot;],[&quot;Carla&quot;,&quot;5&quot;,&quot;Water&quot;],[&quot;Carla&quot;,&quot;5&quot;,&quot;Ceviche&quot;],[&quot;Rous&quot;,&quot;3&quot;,&quot;Ceviche&quot;]]

<strong>Output:</strong> [[&quot;Table&quot;,&quot;Beef Burrito&quot;,&quot;Ceviche&quot;,&quot;Fried Chicken&quot;,&quot;Water&quot;],[&quot;3&quot;,&quot;0&quot;,&quot;2&quot;,&quot;1&quot;,&quot;0&quot;],[&quot;5&quot;,&quot;0&quot;,&quot;1&quot;,&quot;0&quot;,&quot;1&quot;],[&quot;10&quot;,&quot;1&quot;,&quot;0&quot;,&quot;0&quot;,&quot;0&quot;]]
<strong>Output:</strong> [[&quot;Table&quot;,&quot;Beef Burrito&quot;,&quot;Ceviche&quot;,&quot;Fried Chicken&quot;,&quot;Water&quot;],[&quot;3&quot;,&quot;0&quot;,&quot;2&quot;,&quot;1&quot;,&quot;0&quot;],[&quot;5&quot;,&quot;0&quot;,&quot;1&quot;,&quot;0&quot;,&quot;1&quot;],[&quot;10&quot;,&quot;1&quot;,&quot;0&quot;,&quot;0&quot;,&quot;0&quot;]]

<strong>Explanation:

Expand All @@ -52,7 +52,7 @@ For the table 3: David orders &quot;Ceviche&quot; and &quot;Fried Chicken&quot;,

For the table 5: Carla orders &quot;Water&quot; and &quot;Ceviche&quot;.

For the table 10: Corina orders &quot;Beef Burrito&quot;.
For the table 10: Corina orders &quot;Beef Burrito&quot;.

</pre>

Expand All @@ -62,9 +62,9 @@ For the table 10: Corina orders &quot;Beef Burrito&quot;.

<strong>Input:</strong> orders = [[&quot;James&quot;,&quot;12&quot;,&quot;Fried Chicken&quot;],[&quot;Ratesh&quot;,&quot;12&quot;,&quot;Fried Chicken&quot;],[&quot;Amadeus&quot;,&quot;12&quot;,&quot;Fried Chicken&quot;],[&quot;Adam&quot;,&quot;1&quot;,&quot;Canadian Waffles&quot;],[&quot;Brianna&quot;,&quot;1&quot;,&quot;Canadian Waffles&quot;]]

<strong>Output:</strong> [[&quot;Table&quot;,&quot;Canadian Waffles&quot;,&quot;Fried Chicken&quot;],[&quot;1&quot;,&quot;2&quot;,&quot;0&quot;],[&quot;12&quot;,&quot;0&quot;,&quot;3&quot;]]
<strong>Output:</strong> [[&quot;Table&quot;,&quot;Canadian Waffles&quot;,&quot;Fried Chicken&quot;],[&quot;1&quot;,&quot;2&quot;,&quot;0&quot;],[&quot;12&quot;,&quot;0&quot;,&quot;3&quot;]]

<strong>Explanation:</strong>
<strong>Explanation:</strong>

For the table 1: Adam and Brianna order &quot;Canadian Waffles&quot;.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ tags:
<p><strong>示例 1:</strong></p>

<pre><strong>输入:</strong>s = &quot;011101&quot;
<strong>输出:</strong>5
<strong>输出:</strong>5
<strong>解释:</strong>
将字符串 s 划分为两个非空子字符串的可行方案有:
左子字符串 = &quot;0&quot; 且 右子字符串 = &quot;11101&quot;,得分 = 1 + 4 = 5
左子字符串 = &quot;01&quot; 且 右子字符串 = &quot;1101&quot;,得分 = 1 + 3 = 4
左子字符串 = &quot;011&quot; 且 右子字符串 = &quot;101&quot;,得分 = 1 + 2 = 3
左子字符串 = &quot;0111&quot; 且 右子字符串 = &quot;01&quot;,得分 = 1 + 1 = 2
左子字符串 = &quot;0&quot; 且 右子字符串 = &quot;11101&quot;,得分 = 1 + 4 = 5
左子字符串 = &quot;01&quot; 且 右子字符串 = &quot;1101&quot;,得分 = 1 + 3 = 4
左子字符串 = &quot;011&quot; 且 右子字符串 = &quot;101&quot;,得分 = 1 + 2 = 3
左子字符串 = &quot;0111&quot; 且 右子字符串 = &quot;01&quot;,得分 = 1 + 1 = 2
左子字符串 = &quot;01110&quot; 且 右子字符串 = &quot;1&quot;,得分 = 2 + 1 = 3
</pre>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ tags:

<pre>
<strong>Input:</strong> s = &quot;011101&quot;
<strong>Output:</strong> 5
<strong>Explanation:</strong>
<strong>Output:</strong> 5
<strong>Explanation:</strong>
All possible ways of splitting s into two non-empty substrings are:
left = &quot;0&quot; and right = &quot;11101&quot;, score = 1 + 4 = 5
left = &quot;01&quot; and right = &quot;1101&quot;, score = 1 + 3 = 4
left = &quot;011&quot; and right = &quot;101&quot;, score = 1 + 2 = 3
left = &quot;0111&quot; and right = &quot;01&quot;, score = 1 + 1 = 2
left = &quot;0&quot; and right = &quot;11101&quot;, score = 1 + 4 = 5
left = &quot;01&quot; and right = &quot;1101&quot;, score = 1 + 3 = 4
left = &quot;011&quot; and right = &quot;101&quot;, score = 1 + 2 = 3
left = &quot;0111&quot; and right = &quot;01&quot;, score = 1 + 1 = 2
left = &quot;01110&quot; and right = &quot;1&quot;, score = 2 + 1 = 3
</pre>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ function getDirections(root: TreeNode | null, startValue: number, destValue: num
const left = lca(node.left, p, q);
const right = lca(node.right, p, q);

return left && right ? node : (left ?? right);
return left && right ? node : left ?? right;
};

const dfs = (node: TreeNode | null, x: number, path: string[]): boolean => {
Expand Down Expand Up @@ -370,7 +370,7 @@ var getDirections = function (root, startValue, destValue) {
const left = lca(node.left, p, q);
const right = lca(node.right, p, q);

return left && right ? node : (left ?? right);
return left && right ? node : left ?? right;
};

const dfs = (node, x, path) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ function getDirections(root: TreeNode | null, startValue: number, destValue: num
const left = lca(node.left, p, q);
const right = lca(node.right, p, q);

return left && right ? node : (left ?? right);
return left && right ? node : left ?? right;
};

const dfs = (node: TreeNode | null, x: number, path: string[]): boolean => {
Expand Down Expand Up @@ -366,7 +366,7 @@ var getDirections = function (root, startValue, destValue) {
const left = lca(node.left, p, q);
const right = lca(node.right, p, q);

return left && right ? node : (left ?? right);
return left && right ? node : left ?? right;
};

const dfs = (node, x, path) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var getDirections = function (root, startValue, destValue) {
const left = lca(node.left, p, q);
const right = lca(node.right, p, q);

return left && right ? node : (left ?? right);
return left && right ? node : left ?? right;
};

const dfs = (node, x, path) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function getDirections(root: TreeNode | null, startValue: number, destValue: num
const left = lca(node.left, p, q);
const right = lca(node.right, p, q);

return left && right ? node : (left ?? right);
return left && right ? node : left ?? right;
};

const dfs = (node: TreeNode | null, x: number, path: string[]): boolean => {
Expand Down
Loading

0 comments on commit 4fdaa4c

Please sign in to comment.