Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8d7a71a

Browse files
yanglbmeidoocs
andauthored
feat: add weekly contest 386 (doocs#2374)
Co-authored-by: Doocs Bot <doocs-bot@outlook.com>
1 parent 59d6ac2 commit 8d7a71a

File tree

15 files changed

+754
-0
lines changed

15 files changed

+754
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# [3046. 分割数组](https://leetcode.cn/problems/split-the-array)
2+
3+
[English Version](/solution/3000-3099/3046.Split%20the%20Array/README_EN.md)
4+
5+
<!-- tags: -->
6+
7+
## 题目描述
8+
9+
<!-- 这里写题目描述 -->
10+
11+
<p>给你一个长度为 <strong>偶数 </strong>的整数数组 <code>nums</code> 。你需要将这个数组分割成 <code>nums1</code> 和 <code>nums2</code> 两部分,要求:</p>
12+
13+
<ul>
14+
<li><code>nums1.length == nums2.length == nums.length / 2</code> 。</li>
15+
<li><code>nums1</code> 应包含 <strong>互不相同</strong><strong> </strong>的元素。</li>
16+
<li><code>nums2</code>也应包含<strong> 互不相同</strong> 的元素。</li>
17+
</ul>
18+
19+
<p>如果能够分割数组就返回 <code>true</code> ,否则返回 <code>false</code> 。</p>
20+
21+
<p>&nbsp;</p>
22+
23+
<p><strong class="example">示例 1:</strong></p>
24+
25+
<pre>
26+
<strong>输入:</strong>nums = [1,1,2,2,3,4]
27+
<strong>输出:</strong>true
28+
<strong>解释:</strong>分割 nums 的可行方案之一是 nums1 = [1,2,3] 和 nums2 = [1,2,4] 。
29+
</pre>
30+
31+
<p><strong class="example">示例 2:</strong></p>
32+
33+
<pre>
34+
<strong>输入:</strong>nums = [1,1,1,1]
35+
<strong>输出:</strong>false
36+
<strong>解释:</strong>分割 nums 的唯一可行方案是 nums1 = [1,1] 和 nums2 = [1,1] 。但 nums1 和 nums2 都不是由互不相同的元素构成。因此,返回 false 。
37+
</pre>
38+
39+
<p>&nbsp;</p>
40+
41+
<p><strong>提示:</strong></p>
42+
43+
<ul>
44+
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
45+
<li><code>nums.length % 2 == 0</code></li>
46+
<li><code>1 &lt;= nums[i] &lt;= 100</code></li>
47+
</ul>
48+
49+
## 解法
50+
51+
### 方法一
52+
53+
<!-- tabs:start -->
54+
55+
```python
56+
57+
```
58+
59+
```java
60+
61+
```
62+
63+
```cpp
64+
65+
```
66+
67+
```go
68+
69+
```
70+
71+
<!-- tabs:end -->
72+
73+
<!-- end -->
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# [3046. Split the Array](https://leetcode.com/problems/split-the-array)
2+
3+
[中文文档](/solution/3000-3099/3046.Split%20the%20Array/README.md)
4+
5+
<!-- tags: -->
6+
7+
## Description
8+
9+
<p>You are given an integer array <code>nums</code> of <strong>even</strong> length. You have to split the array into two parts <code>nums1</code> and <code>nums2</code> such that:</p>
10+
11+
<ul>
12+
<li><code>nums1.length == nums2.length == nums.length / 2</code>.</li>
13+
<li><code>nums1</code> should contain <strong>distinct </strong>elements.</li>
14+
<li><code>nums2</code> should also contain <strong>distinct</strong> elements.</li>
15+
</ul>
16+
17+
<p>Return <code>true</code><em> if it is possible to split the array, and </em><code>false</code> <em>otherwise</em><em>.</em></p>
18+
19+
<p>&nbsp;</p>
20+
<p><strong class="example">Example 1:</strong></p>
21+
22+
<pre>
23+
<strong>Input:</strong> nums = [1,1,2,2,3,4]
24+
<strong>Output:</strong> true
25+
<strong>Explanation:</strong> One of the possible ways to split nums is nums1 = [1,2,3] and nums2 = [1,2,4].
26+
</pre>
27+
28+
<p><strong class="example">Example 2:</strong></p>
29+
30+
<pre>
31+
<strong>Input:</strong> nums = [1,1,1,1]
32+
<strong>Output:</strong> false
33+
<strong>Explanation:</strong> The only possible way to split nums is nums1 = [1,1] and nums2 = [1,1]. Both nums1 and nums2 do not contain distinct elements. Therefore, we return false.
34+
</pre>
35+
36+
<p>&nbsp;</p>
37+
<p><strong>Constraints:</strong></p>
38+
39+
<ul>
40+
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
41+
<li><code>nums.length % 2 == 0 </code></li>
42+
<li><code>1 &lt;= nums[i] &lt;= 100</code></li>
43+
</ul>
44+
45+
## Solutions
46+
47+
### Solution 1
48+
49+
<!-- tabs:start -->
50+
51+
```python
52+
53+
```
54+
55+
```java
56+
57+
```
58+
59+
```cpp
60+
61+
```
62+
63+
```go
64+
65+
```
66+
67+
<!-- tabs:end -->
68+
69+
<!-- end -->
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# [3047. 求交集区域内的最大正方形面积](https://leetcode.cn/problems/find-the-largest-area-of-square-inside-two-rectangles)
2+
3+
[English Version](/solution/3000-3099/3047.Find%20the%20Largest%20Area%20of%20Square%20Inside%20Two%20Rectangles/README_EN.md)
4+
5+
<!-- tags: -->
6+
7+
## 题目描述
8+
9+
<!-- 这里写题目描述 -->
10+
11+
<p>在二维平面上存在 <code>n</code> 个矩形。给你两个下标从 <strong>0</strong> 开始的二维整数数组 <code>bottomLeft</code> 和 <code>topRight</code>,两个数组的大小都是 <code>n x 2</code> ,其中 <code>bottomLeft[i]</code> 和 <code>topRight[i]</code> 分别代表第 <code>i</code> 个矩形的<strong> 左下角 </strong>和 <strong>右上角 </strong>坐标。</p>
12+
13+
<p>我们定义 <strong>向右 </strong>的方向为 x 轴正半轴(<strong>x 坐标增加</strong>),<strong>向左 </strong>的方向为 x 轴负半轴(<strong>x 坐标减少</strong>)。同样地,定义 <strong>向上 </strong>的方向为 y 轴正半轴(<strong>y 坐标增加</strong>)<strong>,向下 </strong>的方向为 y 轴负半轴(<strong>y 坐标减少</strong>)。</p>
14+
15+
<p>你可以选择一个区域,该区域由两个矩形的 <strong>交集</strong>&nbsp;形成。你需要找出能够放入该区域 <strong>内 </strong>的<strong> 最大 </strong>正方形面积,并选择最优解。</p>
16+
17+
<p>返回能够放入交集区域的正方形的 <strong>最大 </strong>可能面积,如果矩形之间不存在任何交集区域,则返回 <code>0</code>。</p>
18+
19+
<p>&nbsp;</p>
20+
21+
<p><strong class="example">示例 1:</strong></p>
22+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3000-3099/3047.Find%20the%20Largest%20Area%20of%20Square%20Inside%20Two%20Rectangles/images/example12.png" style="width: 443px; height: 364px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem;" />
23+
<pre>
24+
<strong>输入:</strong>bottomLeft = [[1,1],[2,2],[3,1]], topRight = [[3,3],[4,4],[6,6]]
25+
<strong>输出:</strong>1
26+
<strong>解释:</strong>边长为 1 的正方形可以放入矩形 0 和矩形 1 的交集区域,或矩形 1 和矩形 2 的交集区域。因此最大面积是边长 * 边长,即 1 * 1 = 1。
27+
可以证明,边长更大的正方形无法放入任何交集区域。
28+
</pre>
29+
30+
<p><strong class="example">示例 2:</strong></p>
31+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3000-3099/3047.Find%20the%20Largest%20Area%20of%20Square%20Inside%20Two%20Rectangles/images/rectanglesexample2.png" style="padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; width: 445px; height: 365px;" />
32+
<pre>
33+
<strong>输入:</strong>bottomLeft = [[1,1],[2,2],[1,2]], topRight = [[3,3],[4,4],[3,4]]
34+
<strong>输出:</strong>1
35+
<strong>解释:</strong>边长为 1 的正方形可以放入矩形 0 和矩形 1,矩形 1 和矩形 2,或所有三个矩形的交集区域。因此最大面积是边长 * 边长,即 1 * 1 = 1。
36+
可以证明,边长更大的正方形无法放入任何交集区域。
37+
请注意,区域可以由多于两个矩形的交集构成。
38+
</pre>
39+
40+
<p><strong class="example">示例 3:</strong></p>
41+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3000-3099/3047.Find%20the%20Largest%20Area%20of%20Square%20Inside%20Two%20Rectangles/images/rectanglesexample3.png" style="padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; width: 444px; height: 364px;" />
42+
<pre>
43+
<strong>输入:</strong>bottomLeft = [[1,1],[3,3],[3,1]], topRight = [[2,2],[4,4],[4,2]]
44+
<strong>输出:</strong>0
45+
<strong>解释:</strong>不存在相交的矩形,因此,返回 0 。
46+
</pre>
47+
48+
<p>&nbsp;</p>
49+
50+
<p><strong>提示:</strong></p>
51+
52+
<ul>
53+
<li><code>n == bottomLeft.length == topRight.length</code></li>
54+
<li><code>2 &lt;= n &lt;= 10<sup>3</sup></code></li>
55+
<li><code>bottomLeft[i].length == topRight[i].length == 2</code></li>
56+
<li><code>1 &lt;= bottomLeft[i][0], bottomLeft[i][1] &lt;= 10<sup>7</sup></code></li>
57+
<li><code>1 &lt;= topRight[i][0], topRight[i][1] &lt;= 10<sup>7</sup></code></li>
58+
<li><code>bottomLeft[i][0] &lt; topRight[i][0]</code></li>
59+
<li><code>bottomLeft[i][1] &lt; topRight[i][1]</code></li>
60+
</ul>
61+
62+
## 解法
63+
64+
### 方法一
65+
66+
<!-- tabs:start -->
67+
68+
```python
69+
70+
```
71+
72+
```java
73+
74+
```
75+
76+
```cpp
77+
78+
```
79+
80+
```go
81+
82+
```
83+
84+
<!-- tabs:end -->
85+
86+
<!-- end -->
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# [3047. Find the Largest Area of Square Inside Two Rectangles](https://leetcode.com/problems/find-the-largest-area-of-square-inside-two-rectangles)
2+
3+
[中文文档](/solution/3000-3099/3047.Find%20the%20Largest%20Area%20of%20Square%20Inside%20Two%20Rectangles/README.md)
4+
5+
<!-- tags: -->
6+
7+
## Description
8+
9+
<p>There exist <code>n</code> rectangles in a 2D plane. You are given two <strong>0-indexed</strong> 2D integer arrays <code>bottomLeft</code> and <code>topRight</code>, both of size <code>n x 2</code>, where <code>bottomLeft[i]</code> and <code>topRight[i]</code> represent the <strong>bottom-left</strong> and <strong>top-right</strong> coordinates of the <code>i<sup>th</sup></code> rectangle respectively.</p>
10+
11+
<p>You can select a region formed from the <strong>intersection</strong> of&nbsp;two of the given rectangles. You need to find the <strong>largest </strong>area of a <strong>square</strong> that can fit <strong>inside</strong> this region if you select the region optimally.</p>
12+
13+
<p>Return <em>the <strong>largest </strong>possible area of a square, or </em><code>0</code><em> if there <strong>do not</strong> exist any intersecting regions between the rectangles</em>.</p>
14+
15+
<p>&nbsp;</p>
16+
<p><strong class="example">Example 1:</strong></p>
17+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3000-3099/3047.Find%20the%20Largest%20Area%20of%20Square%20Inside%20Two%20Rectangles/images/example12.png" style="width: 443px; height: 364px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem;" />
18+
<pre>
19+
<strong>Input:</strong> bottomLeft = [[1,1],[2,2],[3,1]], topRight = [[3,3],[4,4],[6,6]]
20+
<strong>Output:</strong> 1
21+
<strong>Explanation:</strong> A square with side length 1 can fit inside either the intersecting region of rectangle 0 and rectangle 1, or the intersecting region of rectangle 1 and rectangle 2. Hence the largest area is side * side which is 1 * 1 == 1.
22+
It can be shown that a square with a greater side length can not fit inside any intersecting region.
23+
</pre>
24+
25+
<p><strong class="example">Example 2:</strong></p>
26+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3000-3099/3047.Find%20the%20Largest%20Area%20of%20Square%20Inside%20Two%20Rectangles/images/rectanglesexample2.png" style="padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; width: 445px; height: 365px;" />
27+
<pre>
28+
<strong>Input:</strong> bottomLeft = [[1,1],[2,2],[1,2]], topRight = [[3,3],[4,4],[3,4]]
29+
<strong>Output:</strong> 1
30+
<strong>Explanation:</strong> A square with side length 1 can fit inside either the intersecting region of rectangle 0 and rectangle 1, the intersecting region of rectangle 1 and rectangle 2, or the intersection region of all 3 rectangles. Hence the largest area is side * side which is 1 * 1 == 1.
31+
It can be shown that a square with a greater side length can not fit inside any intersecting region.
32+
Note that the region can be formed by the intersection of more than 2 rectangles.
33+
</pre>
34+
35+
<p><strong class="example">Example 3:</strong></p>
36+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3000-3099/3047.Find%20the%20Largest%20Area%20of%20Square%20Inside%20Two%20Rectangles/images/rectanglesexample3.png" style="padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; width: 444px; height: 364px;" />
37+
<pre>
38+
<strong>Input:</strong> bottomLeft = [[1,1],[3,3],[3,1]], topRight = [[2,2],[4,4],[4,2]]
39+
<strong>Output:</strong> 0
40+
<strong>Explanation:</strong> No pair of rectangles intersect, hence, we return 0.
41+
</pre>
42+
43+
<p>&nbsp;</p>
44+
<p><strong>Constraints:</strong></p>
45+
46+
<ul>
47+
<li><code>n == bottomLeft.length == topRight.length</code></li>
48+
<li><code>2 &lt;= n &lt;= 10<sup>3</sup></code></li>
49+
<li><code>bottomLeft[i].length == topRight[i].length == 2</code></li>
50+
<li><code>1 &lt;= bottomLeft[i][0], bottomLeft[i][1] &lt;= 10<sup>7</sup></code></li>
51+
<li><code>1 &lt;= topRight[i][0], topRight[i][1] &lt;= 10<sup>7</sup></code></li>
52+
<li><code>bottomLeft[i][0] &lt; topRight[i][0]</code></li>
53+
<li><code>bottomLeft[i][1] &lt; topRight[i][1]</code></li>
54+
</ul>
55+
56+
## Solutions
57+
58+
### Solution 1
59+
60+
<!-- tabs:start -->
61+
62+
```python
63+
64+
```
65+
66+
```java
67+
68+
```
69+
70+
```cpp
71+
72+
```
73+
74+
```go
75+
76+
```
77+
78+
<!-- tabs:end -->
79+
80+
<!-- end -->
4.65 KB
Loading[フレーム]
4.49 KB
Loading[フレーム]
4.16 KB
Loading[フレーム]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /