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 37f4c1f

Browse files
authored
feat: add weekly contest 376 (doocs#2111)
1 parent 30a1628 commit 37f4c1f

File tree

14 files changed

+740
-0
lines changed

14 files changed

+740
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# [2965. 找出缺失和重复的数字](https://leetcode.cn/problems/find-missing-and-repeated-values)
2+
3+
[English Version](/solution/2900-2999/2965.Find%20Missing%20and%20Repeated%20Values/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你一个下标从<strong> 0 </strong>开始的二维整数矩阵 <code><font face="monospace">grid</font></code>,大小为 <code>n * n</code> ,其中的值在 <code>[1, n<sup>2</sup>]</code> 范围内。除了 <code>a</code> 出现 <strong>两次</strong>,<code>b</code> <strong>缺失</strong> 之外,每个整数都<strong> 恰好出现一次</strong> 。</p>
10+
11+
<p>任务是找出重复的数字<code>a</code> 和缺失的数字 <code>b</code> 。</p>
12+
13+
<p>返回一个下标从 0 开始、长度为 <code>2</code> 的整数数组 <code>ans</code> ,其中 <code>ans[0]</code> 等于 <code>a</code> ,<code>ans[1]</code> 等于 <code>b</code> 。</p>
14+
15+
<p>&nbsp;</p>
16+
17+
<p><strong class="example">示例 1:</strong></p>
18+
19+
<pre>
20+
<strong>输入:</strong>grid = [[1,3],[2,2]]
21+
<strong>输出:</strong>[2,4]
22+
<strong>解释:</strong>数字 2 重复,数字 4 缺失,所以答案是 [2,4] 。
23+
</pre>
24+
25+
<p><strong class="example">示例 2:</strong></p>
26+
27+
<pre>
28+
<strong>输入:</strong>grid = [[9,1,7],[8,9,2],[3,4,6]]
29+
<strong>输出:</strong>[9,5]
30+
<strong>解释:</strong>数字 9 重复,数字 5 缺失,所以答案是 [9,5] 。
31+
</pre>
32+
33+
<p>&nbsp;</p>
34+
35+
<p><strong>提示:</strong></p>
36+
37+
<ul>
38+
<li><code>2 &lt;= n == grid.length == grid[i].length &lt;= 50</code></li>
39+
<li><code>1 &lt;= grid[i][j] &lt;= n * n</code></li>
40+
<li>对于所有满足<code>1 &lt;= x &lt;= n * n</code> 的 <code>x</code> ,恰好存在一个 <code>x</code> 与矩阵中的任何成员都不相等。</li>
41+
<li>对于所有满足<code>1 &lt;= x &lt;= n * n</code> 的 <code>x</code> ,恰好存在一个 <code>x</code> 与矩阵中的两个成员相等。</li>
42+
<li>除上述的两个之外,对于所有满足<code>1 &lt;= x &lt;= n * n</code> 的 <code>x</code> ,都恰好存在一对 <code>i, j</code> 满足 <code>0 &lt;= i, j &lt;= n - 1</code> 且 <code>grid[i][j] == x</code> 。</li>
43+
</ul>
44+
45+
## 解法
46+
47+
<!-- 这里可写通用的实现逻辑 -->
48+
49+
<!-- tabs:start -->
50+
51+
### **Python3**
52+
53+
<!-- 这里可写当前语言的特殊实现逻辑 -->
54+
55+
```python
56+
57+
```
58+
59+
### **Java**
60+
61+
<!-- 这里可写当前语言的特殊实现逻辑 -->
62+
63+
```java
64+
65+
```
66+
67+
### **C++**
68+
69+
```cpp
70+
71+
```
72+
73+
### **Go**
74+
75+
```go
76+
77+
```
78+
79+
### **...**
80+
81+
```
82+
83+
```
84+
85+
<!-- tabs:end -->
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# [2965. Find Missing and Repeated Values](https://leetcode.com/problems/find-missing-and-repeated-values)
2+
3+
[中文文档](/solution/2900-2999/2965.Find%20Missing%20and%20Repeated%20Values/README.md)
4+
5+
## Description
6+
7+
<p>You are given a <strong>0-indexed</strong> 2D integer matrix <code><font face="monospace">grid</font></code> of size <code>n * n</code> with values in the range <code>[1, n<sup>2</sup>]</code>. Each integer appears <strong>exactly once</strong> except <code>a</code> which appears <strong>twice</strong> and <code>b</code> which is <strong>missing</strong>. The task is to find the repeating and missing numbers <code>a</code> and <code>b</code>.</p>
8+
9+
<p>Return <em>a <strong>0-indexed </strong>integer array </em><code>ans</code><em> of size </em><code>2</code><em> where </em><code>ans[0]</code><em> equals to </em><code>a</code><em> and </em><code>ans[1]</code><em> equals to </em><code>b</code><em>.</em></p>
10+
11+
<p>&nbsp;</p>
12+
<p><strong class="example">Example 1:</strong></p>
13+
14+
<pre>
15+
<strong>Input:</strong> grid = [[1,3],[2,2]]
16+
<strong>Output:</strong> [2,4]
17+
<strong>Explanation:</strong> Number 2 is repeated and number 4 is missing so the answer is [2,4].
18+
</pre>
19+
20+
<p><strong class="example">Example 2:</strong></p>
21+
22+
<pre>
23+
<strong>Input:</strong> grid = [[9,1,7],[8,9,2],[3,4,6]]
24+
<strong>Output:</strong> [9,5]
25+
<strong>Explanation:</strong> Number 9 is repeated and number 5 is missing so the answer is [9,5].
26+
</pre>
27+
28+
<p>&nbsp;</p>
29+
<p><strong>Constraints:</strong></p>
30+
31+
<ul>
32+
<li><code>2 &lt;= n == grid.length == grid[i].length &lt;= 50</code></li>
33+
<li><code>1 &lt;= grid[i][j] &lt;= n * n</code></li>
34+
<li>For all <code>x</code> that <code>1 &lt;= x &lt;= n * n</code> there is exactly one <code>x</code> that is not equal to any of the grid members.</li>
35+
<li>For all <code>x</code> that <code>1 &lt;= x &lt;= n * n</code> there is exactly one <code>x</code> that is equal to exactly two of the grid members.</li>
36+
<li>For all <code>x</code> that <code>1 &lt;= x &lt;= n * n</code> except two of them there is exatly one pair of <code>i, j</code> that <code>0 &lt;= i, j &lt;= n - 1</code> and <code>grid[i][j] == x</code>.</li>
37+
</ul>
38+
39+
## Solutions
40+
41+
<!-- tabs:start -->
42+
43+
### **Python3**
44+
45+
```python
46+
47+
```
48+
49+
### **Java**
50+
51+
```java
52+
53+
```
54+
55+
### **C++**
56+
57+
```cpp
58+
59+
```
60+
61+
### **Go**
62+
63+
```go
64+
65+
```
66+
67+
### **...**
68+
69+
```
70+
71+
```
72+
73+
<!-- tabs:end -->
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# [2966. 划分数组并满足最大差限制](https://leetcode.cn/problems/divide-array-into-arrays-with-max-difference)
2+
3+
[English Version](/solution/2900-2999/2966.Divide%20Array%20Into%20Arrays%20With%20Max%20Difference/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你一个长度为 <code>n</code> 的整数数组 <code>nums</code>,以及一个正整数 <code>k</code> 。</p>
10+
11+
<p>将这个数组划分为一个或多个长度为 <code>3</code> 的子数组,并满足以下条件:</p>
12+
13+
<ul>
14+
<li><code>nums</code> 中的 <strong>每个 </strong>元素都必须 <strong>恰好 </strong>存在于某个子数组中。</li>
15+
<li>子数组中<strong> 任意 </strong>两个元素的差必须小于或等于 <code>k</code> 。</li>
16+
</ul>
17+
18+
<p>返回一个<em> </em><strong>二维数组 </strong>,包含所有的子数组。如果不可能满足条件,就返回一个空数组。如果有多个答案,返回 <strong>任意一个</strong> 即可。</p>
19+
20+
<p>&nbsp;</p>
21+
22+
<p><strong class="example">示例 1:</strong></p>
23+
24+
<pre>
25+
<strong>输入:</strong>nums = [1,3,4,8,7,9,3,5,1], k = 2
26+
<strong>输出:</strong>[[1,1,3],[3,4,5],[7,8,9]]
27+
<strong>解释:</strong>可以将数组划分为以下子数组:[1,1,3],[3,4,5] 和 [7,8,9] 。
28+
每个子数组中任意两个元素的差都小于或等于 2 。
29+
注意,元素的顺序并不重要。
30+
</pre>
31+
32+
<p><strong class="example">示例 2:</strong></p>
33+
34+
<pre>
35+
<strong>输入:</strong>nums = [1,3,3,2,7,3], k = 3
36+
<strong>输出:</strong>[]
37+
<strong>解释:</strong>无法划分数组满足所有条件。
38+
</pre>
39+
40+
<p>&nbsp;</p>
41+
42+
<p><strong>提示:</strong></p>
43+
44+
<ul>
45+
<li><code>n == nums.length</code></li>
46+
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
47+
<li><code>n</code> 是 <code>3</code> 的倍数</li>
48+
<li><code>1 &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
49+
<li><code>1 &lt;= k &lt;= 10<sup>5</sup></code></li>
50+
</ul>
51+
52+
## 解法
53+
54+
<!-- 这里可写通用的实现逻辑 -->
55+
56+
<!-- tabs:start -->
57+
58+
### **Python3**
59+
60+
<!-- 这里可写当前语言的特殊实现逻辑 -->
61+
62+
```python
63+
64+
```
65+
66+
### **Java**
67+
68+
<!-- 这里可写当前语言的特殊实现逻辑 -->
69+
70+
```java
71+
72+
```
73+
74+
### **C++**
75+
76+
```cpp
77+
78+
```
79+
80+
### **Go**
81+
82+
```go
83+
84+
```
85+
86+
### **...**
87+
88+
```
89+
90+
```
91+
92+
<!-- tabs:end -->
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# [2966. Divide Array Into Arrays With Max Difference](https://leetcode.com/problems/divide-array-into-arrays-with-max-difference)
2+
3+
[中文文档](/solution/2900-2999/2966.Divide%20Array%20Into%20Arrays%20With%20Max%20Difference/README.md)
4+
5+
## Description
6+
7+
<p>You are given an integer array <code>nums</code> of size <code>n</code> and a positive integer <code>k</code>.</p>
8+
9+
<p>Divide the array into one or more arrays of size <code>3</code> satisfying the following conditions:</p>
10+
11+
<ul>
12+
<li><strong>Each</strong> element of <code>nums</code> should be in <strong>exactly</strong> one array.</li>
13+
<li>The difference between <strong>any</strong> two elements in one array is less than or equal to <code>k</code>.</li>
14+
</ul>
15+
16+
<p>Return <em>a </em><strong>2D</strong><em> array containing all the arrays. If it is impossible to satisfy the conditions, return an empty array. And if there are multiple answers, return <strong>any</strong> of them.</em></p>
17+
18+
<p>&nbsp;</p>
19+
<p><strong class="example">Example 1:</strong></p>
20+
21+
<pre>
22+
<strong>Input:</strong> nums = [1,3,4,8,7,9,3,5,1], k = 2
23+
<strong>Output:</strong> [[1,1,3],[3,4,5],[7,8,9]]
24+
<strong>Explanation:</strong> We can divide the array into the following arrays: [1,1,3], [3,4,5] and [7,8,9].
25+
The difference between any two elements in each array is less than or equal to 2.
26+
Note that the order of elements is not important.
27+
</pre>
28+
29+
<p><strong class="example">Example 2:</strong></p>
30+
31+
<pre>
32+
<strong>Input:</strong> nums = [1,3,3,2,7,3], k = 3
33+
<strong>Output:</strong> []
34+
<strong>Explanation:</strong> It is not possible to divide the array satisfying all the conditions.
35+
</pre>
36+
37+
<p>&nbsp;</p>
38+
<p><strong>Constraints:</strong></p>
39+
40+
<ul>
41+
<li><code>n == nums.length</code></li>
42+
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
43+
<li><code>n</code> is a multiple of <code>3</code>.</li>
44+
<li><code>1 &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
45+
<li><code>1 &lt;= k &lt;= 10<sup>5</sup></code></li>
46+
</ul>
47+
48+
## Solutions
49+
50+
<!-- tabs:start -->
51+
52+
### **Python3**
53+
54+
```python
55+
56+
```
57+
58+
### **Java**
59+
60+
```java
61+
62+
```
63+
64+
### **C++**
65+
66+
```cpp
67+
68+
```
69+
70+
### **Go**
71+
72+
```go
73+
74+
```
75+
76+
### **...**
77+
78+
```
79+
80+
```
81+
82+
<!-- tabs:end -->

0 commit comments

Comments
(0)

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