Skip to content

Commit a81893f

Browse files
authored
feat: add weekly contest 442 (#4288)
1 parent ace4809 commit a81893f

File tree

21 files changed

+1025
-5
lines changed

21 files changed

+1025
-5
lines changed

solution/0300-0399/0325.Maximum Size Subarray Sum Equals k/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ tags:
2626

2727
<pre>
2828
<strong>输入: </strong><em>nums</em> = <code>[1,-1,5,-2,3]</code>, <em>k</em> = <code>3</code>
29-
<strong>输出: </strong>4
29+
<strong>输出: </strong>4
3030
<strong>解释: </strong>子数组 <code>[1, -1, 5, -2]</code> 和等于 3,且长度最长。
3131
</pre>
3232

solution/1400-1499/1478.Allocate Mailboxes/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ tags:
3434
<strong>Input:</strong> houses = [1,4,8,10,20], k = 3
3535
<strong>Output:</strong> 5
3636
<strong>Explanation:</strong> Allocate mailboxes in position 3, 9 and 20.
37-
Minimum total distance from each houses to nearest mailboxes is |3-1| + |4-3| + |9-8| + |10-9| + |20-20| = 5
37+
Minimum total distance from each houses to nearest mailboxes is |3-1| + |4-3| + |9-8| + |10-9| + |20-20| = 5
3838
</pre>
3939

4040
<p><strong class="example">Example 2:</strong></p>

solution/2600-2699/2643.Row With Maximum Ones/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ tags:
3232
<pre>
3333
<strong>输入:</strong>mat = [[0,1],[1,0]]
3434
<strong>输出:</strong>[0,1]
35-
<strong>解释:</strong>两行中 1 的数量相同。所以返回下标最小的行,下标为 0 。该行 1 的数量为 1 。所以,答案为 [0,1] 。
35+
<strong>解释:</strong>两行中 1 的数量相同。所以返回下标最小的行,下标为 0 。该行 1 的数量为 1 。所以,答案为 [0,1] 。
3636
</pre>
3737

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

solution/2600-2699/2643.Row With Maximum Ones/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ tags:
3131
<pre>
3232
<strong>Input:</strong> mat = [[0,1],[1,0]]
3333
<strong>Output:</strong> [0,1]
34-
<strong>Explanation:</strong> Both rows have the same number of 1&#39;s. So we return the index of the smaller row, 0, and the maximum count of ones (1<code>)</code>. So, the answer is [0,1].
34+
<strong>Explanation:</strong> Both rows have the same number of 1&#39;s. So we return the index of the smaller row, 0, and the maximum count of ones (1<code>)</code>. So, the answer is [0,1].
3535
</pre>
3636

3737
<p><strong class="example">Example 2:</strong></p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
comments: true
3+
difficulty: 简单
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3492.Maximum%20Containers%20on%20a%20Ship/README.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3492. 船上可以装载的最大集装箱数量](https://leetcode.cn/problems/maximum-containers-on-a-ship)
10+
11+
[English Version](/solution/3400-3499/3492.Maximum%20Containers%20on%20a%20Ship/README_EN.md)
12+
13+
## 题目描述
14+
15+
<!-- description:start -->
16+
17+
<p>给你一个正整数 <code>n</code>,表示船上的一个 <code>n x n</code> 的货物甲板。甲板上的每个单元格可以装载一个重量<strong> 恰好 </strong>为 <code>w</code> 的集装箱。</p>
18+
19+
<p>然而,如果将所有集装箱装载到甲板上,其总重量不能超过船的最大承载重量 <code>maxWeight</code>。</p>
20+
21+
<p>请返回可以装载到船上的 <strong>最大 </strong>集装箱数量。</p>
22+
23+
<p>&nbsp;</p>
24+
25+
<p><strong class="example">示例 1:</strong></p>
26+
27+
<div class="example-block">
28+
<p><strong>输入:</strong> <span class="example-io">n = 2, w = 3, maxWeight = 15</span></p>
29+
30+
<p><strong>输出:</strong> 4</p>
31+
32+
<p><strong>解释:</strong></p>
33+
34+
<p>甲板有 4 个单元格,每个集装箱的重量为 3。将所有集装箱装载后,总重量为 12,未超过 <code>maxWeight</code>。</p>
35+
</div>
36+
37+
<p><strong class="example">示例 2:</strong></p>
38+
39+
<div class="example-block">
40+
<p><strong>输入:</strong> <span class="example-io">n = 3, w = 5, maxWeight = 20</span></p>
41+
42+
<p><strong>输出:</strong> <span class="example-io">4</span></p>
43+
44+
<p><strong>解释:</strong></p>
45+
46+
<p>甲板有 9 个单元格,每个集装箱的重量为 5。可以装载的最大集装箱数量为 4,此时总重量不超过 <code>maxWeight</code>。</p>
47+
</div>
48+
49+
<p>&nbsp;</p>
50+
51+
<p><strong>提示:</strong></p>
52+
53+
<ul>
54+
<li><code>1 &lt;= n &lt;= 1000</code></li>
55+
<li><code>1 &lt;= w &lt;= 1000</code></li>
56+
<li><code>1 &lt;= maxWeight &lt;= 10<sup>9</sup></code></li>
57+
</ul>
58+
59+
<!-- description:end -->
60+
61+
## 解法
62+
63+
<!-- solution:start -->
64+
65+
### 方法一
66+
67+
<!-- tabs:start -->
68+
69+
#### Python3
70+
71+
```python
72+
73+
```
74+
75+
#### Java
76+
77+
```java
78+
79+
```
80+
81+
#### C++
82+
83+
```cpp
84+
85+
```
86+
87+
#### Go
88+
89+
```go
90+
91+
```
92+
93+
<!-- tabs:end -->
94+
95+
<!-- solution:end -->
96+
97+
<!-- problem:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
comments: true
3+
difficulty: Easy
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3492.Maximum%20Containers%20on%20a%20Ship/README_EN.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3492. Maximum Containers on a Ship](https://leetcode.com/problems/maximum-containers-on-a-ship)
10+
11+
[中文文档](/solution/3400-3499/3492.Maximum%20Containers%20on%20a%20Ship/README.md)
12+
13+
## Description
14+
15+
<!-- description:start -->
16+
17+
<p>You are given a positive integer <code>n</code> representing an <code>n x n</code> cargo deck on a ship. Each cell on the deck can hold one container with a weight of <strong>exactly</strong> <code>w</code>.</p>
18+
19+
<p>However, the total weight of all containers, if loaded onto the deck, must not exceed the ship&#39;s maximum weight capacity, <code>maxWeight</code>.</p>
20+
21+
<p>Return the <strong>maximum</strong> number of containers that can be loaded onto the ship.</p>
22+
23+
<p>&nbsp;</p>
24+
<p><strong class="example">Example 1:</strong></p>
25+
26+
<div class="example-block">
27+
<p><strong>Input:</strong> <span class="example-io">n = 2, w = 3, maxWeight = 15</span></p>
28+
29+
<p><strong>Output:</strong> 4</p>
30+
31+
<p><strong>Explanation: </strong></p>
32+
33+
<p>The deck has 4 cells, and each container weighs 3. The total weight of loading all containers is 12, which does not exceed <code>maxWeight</code>.</p>
34+
</div>
35+
36+
<p><strong class="example">Example 2:</strong></p>
37+
38+
<div class="example-block">
39+
<p><strong>Input:</strong> <span class="example-io">n = 3, w = 5, maxWeight = 20</span></p>
40+
41+
<p><strong>Output:</strong> <span class="example-io">4</span></p>
42+
43+
<p><strong>Explanation: </strong></p>
44+
45+
<p>The deck has 9 cells, and each container weighs 5. The maximum number of containers that can be loaded without exceeding <code>maxWeight</code> is 4.</p>
46+
</div>
47+
48+
<p>&nbsp;</p>
49+
<p><strong>Constraints:</strong></p>
50+
51+
<ul>
52+
<li><code>1 &lt;= n &lt;= 1000</code></li>
53+
<li><code>1 &lt;= w &lt;= 1000</code></li>
54+
<li><code>1 &lt;= maxWeight &lt;= 10<sup>9</sup></code></li>
55+
</ul>
56+
57+
<!-- description:end -->
58+
59+
## Solutions
60+
61+
<!-- solution:start -->
62+
63+
### Solution 1
64+
65+
<!-- tabs:start -->
66+
67+
#### Python3
68+
69+
```python
70+
71+
```
72+
73+
#### Java
74+
75+
```java
76+
77+
```
78+
79+
#### C++
80+
81+
```cpp
82+
83+
```
84+
85+
#### Go
86+
87+
```go
88+
89+
```
90+
91+
<!-- tabs:end -->
92+
93+
<!-- solution:end -->
94+
95+
<!-- problem:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
---
2+
comments: true
3+
difficulty: 中等
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3493.Properties%20Graph/README.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3493. 属性图](https://leetcode.cn/problems/properties-graph)
10+
11+
[English Version](/solution/3400-3499/3493.Properties%20Graph/README_EN.md)
12+
13+
## 题目描述
14+
15+
<!-- description:start -->
16+
17+
<p>给你一个二维整数数组 <code>properties</code>,其维度为 <code>n x m</code>,以及一个整数 <code>k</code>。</p>
18+
19+
<p>定义一个函数 <code>intersect(a, b)</code>,它返回数组 <code>a</code> 和 <code>b</code> 中<strong> 共有的不同整数的数量 </strong>。</p>
20+
21+
<p>构造一个 <strong>无向图</strong>,其中每个索引 <code>i</code> 对应 <code>properties[i]</code>。如果且仅当 <code>intersect(properties[i], properties[j]) &gt;= k</code>(其中 <code>i</code> 和 <code>j</code> 的范围为 <code>[0, n - 1]</code> 且 <code>i != j</code>),节点 <code>i</code> 和节点 <code>j</code> 之间有一条边。</p>
22+
23+
<p>返回结果图中<strong> 连通分量 </strong>的数量。</p>
24+
25+
<p>&nbsp;</p>
26+
27+
<p><strong class="example">示例 1:</strong></p>
28+
29+
<div class="example-block">
30+
<p><strong>输入:</strong> <span class="example-io">properties = [[1,2],[1,1],[3,4],[4,5],[5,6],[7,7]], k = 1</span></p>
31+
32+
<p><strong>输出:</strong> <span class="example-io">3</span></p>
33+
34+
<p><strong>解释:</strong></p>
35+
36+
<p>生成的图有 3 个连通分量:</p>
37+
38+
<p><img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3400-3499/3493.Properties%20Graph/images/1742665594-CDVPWz-image.png" style="width: 279px; height: 171px;" /></p>
39+
</div>
40+
41+
<p><strong class="example">示例 2:</strong></p>
42+
43+
<div class="example-block">
44+
<p><strong>输入:</strong> <span class="example-io">properties = [[1,2,3],[2,3,4],[4,3,5]], k = 2</span></p>
45+
46+
<p><strong>输出:</strong> <span class="example-io">1</span></p>
47+
48+
<p><strong>解释:</strong></p>
49+
50+
<p>生成的图有 1 个连通分量:</p>
51+
52+
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3400-3499/3493.Properties%20Graph/images/1742665565-NzYlYH-screenshot-from-2025-02-27-23-58-34.png" style="width: 219px; height: 171px;" /></p>
53+
</div>
54+
55+
<p><strong class="example">示例 3:</strong></p>
56+
57+
<div class="example-block">
58+
<p><strong>输入:</strong> <span class="example-io">properties = [[1,1],[1,1]], k = 2</span></p>
59+
60+
<p><strong>输出:</strong> <span class="example-io">2</span></p>
61+
62+
<p><strong>解释:</strong></p>
63+
64+
<p><code>intersect(properties[0], properties[1]) = 1</code>,小于 <code>k</code>。因此在图中 <code>properties[0]</code> 和 <code>properties[1]</code> 之间没有边。</p>
65+
</div>
66+
67+
<p>&nbsp;</p>
68+
69+
<p><strong>提示:</strong></p>
70+
71+
<ul>
72+
<li><code>1 &lt;= n == properties.length &lt;= 100</code></li>
73+
<li><code>1 &lt;= m == properties[i].length &lt;= 100</code></li>
74+
<li><code>1 &lt;= properties[i][j] &lt;= 100</code></li>
75+
<li><code>1 &lt;= k &lt;= m</code></li>
76+
</ul>
77+
78+
<!-- description:end -->
79+
80+
## 解法
81+
82+
<!-- solution:start -->
83+
84+
### 方法一
85+
86+
<!-- tabs:start -->
87+
88+
#### Python3
89+
90+
```python
91+
92+
```
93+
94+
#### Java
95+
96+
```java
97+
98+
```
99+
100+
#### C++
101+
102+
```cpp
103+
104+
```
105+
106+
#### Go
107+
108+
```go
109+
110+
```
111+
112+
<!-- tabs:end -->
113+
114+
<!-- solution:end -->
115+
116+
<!-- problem:end -->

0 commit comments

Comments
 (0)