Skip to content

Commit 6dfa077

Browse files
authored
feat: add weekly contest 419 and biweekly contest 141 (#3638)
1 parent 497b411 commit 6dfa077

File tree

26 files changed

+1899
-3
lines changed

26 files changed

+1899
-3
lines changed

solution/3100-3199/3162.Find the Number of Good Pairs I/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ tags:
2121

2222
<p>给你两个整数数组 <code>nums1</code> 和 <code>nums2</code>,长度分别为 <code>n</code> 和 <code>m</code>。同时给你一个<strong>正整数</strong> <code>k</code>。</p>
2323

24-
<p>如果 <code>nums1[i]</code> 可以被 <code>nums2[j] * k</code> 整除,则称数对 <code>(i, j)</code> 为 <strong>优质数对</strong>(<code>0 &lt;= i &lt;= n - 1</code>, <code>0 &lt;= j &lt;= m - 1</code>)。</p>
24+
<p>如果 <code>nums1[i]</code> 可以除尽&nbsp;<code>nums2[j] * k</code>,则称数对 <code>(i, j)</code> 为 <strong>优质数对</strong>(<code>0 &lt;= i &lt;= n - 1</code>, <code>0 &lt;= j &lt;= m - 1</code>)。</p>
2525

2626
<p>返回<strong> 优质数对 </strong>的总数。</p>
2727

solution/3300-3399/3311.Construct 2D Grid Matching Graph Layout/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ tags:
8080
<li><code>1 &lt;= edges.length &lt;= 10<sup>5</sup></code></li>
8181
<li><code>edges[i] = [u<sub>i</sub>, v<sub>i</sub>]</code></li>
8282
<li><code>0 &lt;= u<sub>i</sub> &lt; v<sub>i</sub> &lt; n</code></li>
83-
<li>树中的边互不相同。</li>
83+
<li>图中的边互不相同。</li>
8484
<li>输入保证&nbsp;<code>edges</code>&nbsp;可以形成一个符合上述条件的二维矩阵。</li>
8585
</ul>
8686

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
---
2+
comments: true
3+
difficulty: 简单
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3314.Construct%20the%20Minimum%20Bitwise%20Array%20I/README.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3314. 构造最小位运算数组 I](https://leetcode.cn/problems/construct-the-minimum-bitwise-array-i)
10+
11+
[English Version](/solution/3300-3399/3314.Construct%20the%20Minimum%20Bitwise%20Array%20I/README_EN.md)
12+
13+
## 题目描述
14+
15+
<!-- description:start -->
16+
17+
<p>给你一个长度为 <code>n</code>&nbsp;的<span data-keyword="prime">质数</span>数组&nbsp;<code>nums</code>&nbsp;。你的任务是返回一个长度为 <code>n</code>&nbsp;的数组 <code>ans</code>&nbsp;,对于每个下标 <code>i</code>&nbsp;,以下<strong>&nbsp;条件</strong>&nbsp;均成立:</p>
18+
19+
<ul>
20+
<li><code>ans[i] OR (ans[i] + 1) == nums[i]</code></li>
21+
</ul>
22+
23+
<p>除此以外,你需要 <strong>最小化</strong>&nbsp;结果数组里每一个&nbsp;<code>ans[i]</code>&nbsp;。</p>
24+
25+
<p>如果没法找到符合 <strong>条件</strong>&nbsp;&nbsp;<code>ans[i]</code>&nbsp;,那么&nbsp;<code>ans[i] = -1</code>&nbsp;。</p>
26+
27+
<p><strong>质数</strong>&nbsp;指的是一个大于 1 的自然数,且它只有 1 和自己两个因数。</p>
28+
29+
<p>&nbsp;</p>
30+
31+
<p><strong class="example">示例 1:</strong></p>
32+
33+
<div class="example-block">
34+
<p><span class="example-io"><b>输入:</b>nums = [2,3,5,7]</span></p>
35+
36+
<p><span class="example-io"><b>输出:</b>[-1,1,4,3]</span></p>
37+
38+
<p><b>解释:</b></p>
39+
40+
<ul>
41+
<li>对于&nbsp;<code>i = 0</code>&nbsp;,不存在&nbsp;<code>ans[0]</code>&nbsp;满足&nbsp;<code>ans[0] OR (ans[0] + 1) = 2</code>&nbsp;,所以&nbsp;<code>ans[0] = -1</code>&nbsp;。</li>
42+
<li>对于&nbsp;<code>i = 1</code>&nbsp;,满足 <code>ans[1] OR (ans[1] + 1) = 3</code>&nbsp;的最小&nbsp;<code>ans[1]</code>&nbsp;为&nbsp;<code>1</code>&nbsp;,因为&nbsp;<code>1 OR (1 + 1) = 3</code>&nbsp;。</li>
43+
<li>对于&nbsp;<code>i = 2</code>&nbsp;,满足 <code>ans[2] OR (ans[2] + 1) = 5</code>&nbsp;的最小 <code>ans[2]</code>&nbsp;为&nbsp;<code>4</code>&nbsp;,因为&nbsp;<code>4 OR (4 + 1) = 5</code>&nbsp;。</li>
44+
<li>对于&nbsp;<code>i = 3</code>&nbsp;,满足&nbsp;<code>ans[3] OR (ans[3] + 1) = 7</code>&nbsp;的最小&nbsp;<code>ans[3]</code>&nbsp;为&nbsp;<code>3</code>&nbsp;,因为&nbsp;<code>3 OR (3 + 1) = 7</code>&nbsp;。</li>
45+
</ul>
46+
</div>
47+
48+
<p><strong class="example">示例 2:</strong></p>
49+
50+
<div class="example-block">
51+
<p><span class="example-io"><b>输入:</b>nums = [11,13,31]</span></p>
52+
53+
<p><span class="example-io"><b>输出:</b>[9,12,15]</span></p>
54+
55+
<p><b>解释:</b></p>
56+
57+
<ul>
58+
<li>对于&nbsp;<code>i = 0</code>&nbsp;,满足&nbsp;<code>ans[0] OR (ans[0] + 1) = 11</code> 的最小&nbsp;<code>ans[0]</code>&nbsp;为&nbsp;<code>9</code>&nbsp;,因为&nbsp;<code>9 OR (9 + 1) = 11</code>&nbsp;。</li>
59+
<li>对于&nbsp;<code>i = 1</code>&nbsp;,满足&nbsp;<code>ans[1] OR (ans[1] + 1) = 13</code>&nbsp;的最小&nbsp;<code>ans[1]</code>&nbsp;为&nbsp;<code>12</code>&nbsp;,因为&nbsp;<code>12 OR (12 + 1) = 13</code>&nbsp;。</li>
60+
<li>对于&nbsp;<code>i = 2</code>&nbsp;,满足&nbsp;<code>ans[2] OR (ans[2] + 1) = 31</code>&nbsp;的最小&nbsp;<code>ans[2]</code>&nbsp;为&nbsp;<code>15</code>&nbsp;,因为&nbsp;<code>15 OR (15 + 1) = 31</code>&nbsp;。</li>
61+
</ul>
62+
</div>
63+
64+
<p>&nbsp;</p>
65+
66+
<p><strong>提示:</strong></p>
67+
68+
<ul>
69+
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
70+
<li><code>2 &lt;= nums[i] &lt;= 1000</code></li>
71+
<li><code>nums[i]</code>&nbsp;是一个质数。</li>
72+
</ul>
73+
74+
<!-- description:end -->
75+
76+
## 解法
77+
78+
<!-- solution:start -->
79+
80+
### 方法一
81+
82+
<!-- tabs:start -->
83+
84+
#### Python3
85+
86+
```python
87+
88+
```
89+
90+
#### Java
91+
92+
```java
93+
94+
```
95+
96+
#### C++
97+
98+
```cpp
99+
100+
```
101+
102+
#### Go
103+
104+
```go
105+
106+
```
107+
108+
<!-- tabs:end -->
109+
110+
<!-- solution:end -->
111+
112+
<!-- problem:end -->
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
comments: true
3+
difficulty: Easy
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3314.Construct%20the%20Minimum%20Bitwise%20Array%20I/README_EN.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3314. Construct the Minimum Bitwise Array I](https://leetcode.com/problems/construct-the-minimum-bitwise-array-i)
10+
11+
[中文文档](/solution/3300-3399/3314.Construct%20the%20Minimum%20Bitwise%20Array%20I/README.md)
12+
13+
## Description
14+
15+
<!-- description:start -->
16+
17+
<p>You are given an array <code>nums</code> consisting of <code>n</code> <span data-keyword="prime-number">prime</span> integers.</p>
18+
19+
<p>You need to construct an array <code>ans</code> of length <code>n</code>, such that, for each index <code>i</code>, the bitwise <code>OR</code> of <code>ans[i]</code> and <code>ans[i] + 1</code> is equal to <code>nums[i]</code>, i.e. <code>ans[i] OR (ans[i] + 1) == nums[i]</code>.</p>
20+
21+
<p>Additionally, you must <strong>minimize</strong> each value of <code>ans[i]</code> in the resulting array.</p>
22+
23+
<p>If it is <em>not possible</em> to find such a value for <code>ans[i]</code> that satisfies the <strong>condition</strong>, then set <code>ans[i] = -1</code>.</p>
24+
25+
<p>A <strong>prime number</strong> is a natural number greater than 1 with only two factors, 1 and itself.</p>
26+
27+
<p>&nbsp;</p>
28+
<p><strong class="example">Example 1:</strong></p>
29+
30+
<div class="example-block">
31+
<p><strong>Input:</strong> <span class="example-io">nums = [2,3,5,7]</span></p>
32+
33+
<p><strong>Output:</strong> <span class="example-io">[-1,1,4,3]</span></p>
34+
35+
<p><strong>Explanation:</strong></p>
36+
37+
<ul>
38+
<li>For <code>i = 0</code>, as there is no value for <code>ans[0]</code> that satisfies <code>ans[0] OR (ans[0] + 1) = 2</code>, so <code>ans[0] = -1</code>.</li>
39+
<li>For <code>i = 1</code>, the smallest <code>ans[1]</code> that satisfies <code>ans[1] OR (ans[1] + 1) = 3</code> is <code>1</code>, because <code>1 OR (1 + 1) = 3</code>.</li>
40+
<li>For <code>i = 2</code>, the smallest <code>ans[2]</code> that satisfies <code>ans[2] OR (ans[2] + 1) = 5</code> is <code>4</code>, because <code>4 OR (4 + 1) = 5</code>.</li>
41+
<li>For <code>i = 3</code>, the smallest <code>ans[3]</code> that satisfies <code>ans[3] OR (ans[3] + 1) = 7</code> is <code>3</code>, because <code>3 OR (3 + 1) = 7</code>.</li>
42+
</ul>
43+
</div>
44+
45+
<p><strong class="example">Example 2:</strong></p>
46+
47+
<div class="example-block">
48+
<p><strong>Input:</strong> <span class="example-io">nums = [11,13,31]</span></p>
49+
50+
<p><strong>Output:</strong> <span class="example-io">[9,12,15]</span></p>
51+
52+
<p><strong>Explanation:</strong></p>
53+
54+
<ul>
55+
<li>For <code>i = 0</code>, the smallest <code>ans[0]</code> that satisfies <code>ans[0] OR (ans[0] + 1) = 11</code> is <code>9</code>, because <code>9 OR (9 + 1) = 11</code>.</li>
56+
<li>For <code>i = 1</code>, the smallest <code>ans[1]</code> that satisfies <code>ans[1] OR (ans[1] + 1) = 13</code> is <code>12</code>, because <code>12 OR (12 + 1) = 13</code>.</li>
57+
<li>For <code>i = 2</code>, the smallest <code>ans[2]</code> that satisfies <code>ans[2] OR (ans[2] + 1) = 31</code> is <code>15</code>, because <code>15 OR (15 + 1) = 31</code>.</li>
58+
</ul>
59+
</div>
60+
61+
<p>&nbsp;</p>
62+
<p><strong>Constraints:</strong></p>
63+
64+
<ul>
65+
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
66+
<li><code>2 &lt;= nums[i] &lt;= 1000</code></li>
67+
<li><code>nums[i]</code> is a prime number.</li>
68+
</ul>
69+
70+
<!-- description:end -->
71+
72+
## Solutions
73+
74+
<!-- solution:start -->
75+
76+
### Solution 1
77+
78+
<!-- tabs:start -->
79+
80+
#### Python3
81+
82+
```python
83+
84+
```
85+
86+
#### Java
87+
88+
```java
89+
90+
```
91+
92+
#### C++
93+
94+
```cpp
95+
96+
```
97+
98+
#### Go
99+
100+
```go
101+
102+
```
103+
104+
<!-- tabs:end -->
105+
106+
<!-- solution:end -->
107+
108+
<!-- problem:end -->
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
---
2+
comments: true
3+
difficulty: 中等
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3315.Construct%20the%20Minimum%20Bitwise%20Array%20II/README.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3315. 构造最小位运算数组 II](https://leetcode.cn/problems/construct-the-minimum-bitwise-array-ii)
10+
11+
[English Version](/solution/3300-3399/3315.Construct%20the%20Minimum%20Bitwise%20Array%20II/README_EN.md)
12+
13+
## 题目描述
14+
15+
<!-- description:start -->
16+
17+
<p>给你一个长度为 <code>n</code>&nbsp;的<span data-keyword="prime">质数</span>数组&nbsp;<code>nums</code>&nbsp;。你的任务是返回一个长度为 <code>n</code>&nbsp;的数组 <code>ans</code>&nbsp;,对于每个下标 <code>i</code>&nbsp;,以下<strong>&nbsp;条件</strong>&nbsp;均成立:</p>
18+
19+
<ul>
20+
<li><code>ans[i] OR (ans[i] + 1) == nums[i]</code></li>
21+
</ul>
22+
23+
<p>除此以外,你需要 <strong>最小化</strong>&nbsp;结果数组里每一个&nbsp;<code>ans[i]</code>&nbsp;。</p>
24+
25+
<p>如果没法找到符合 <strong>条件</strong>&nbsp;&nbsp;<code>ans[i]</code>&nbsp;,那么&nbsp;<code>ans[i] = -1</code>&nbsp;。</p>
26+
27+
<p><strong>质数</strong>&nbsp;指的是一个大于 1 的自然数,且它只有 1 和自己两个因数。</p>
28+
29+
<p>&nbsp;</p>
30+
31+
<p><strong class="example">示例 1:</strong></p>
32+
33+
<div class="example-block">
34+
<p><span class="example-io"><b>输入:</b>nums = [2,3,5,7]</span></p>
35+
36+
<p><span class="example-io"><b>输出:</b>[-1,1,4,3]</span></p>
37+
38+
<p><b>解释:</b></p>
39+
40+
<ul>
41+
<li>对于&nbsp;<code>i = 0</code>&nbsp;,不存在&nbsp;<code>ans[0]</code>&nbsp;满足&nbsp;<code>ans[0] OR (ans[0] + 1) = 2</code>&nbsp;,所以&nbsp;<code>ans[0] = -1</code>&nbsp;。</li>
42+
<li>对于&nbsp;<code>i = 1</code>&nbsp;,满足 <code>ans[1] OR (ans[1] + 1) = 3</code>&nbsp;的最小&nbsp;<code>ans[1]</code>&nbsp;为&nbsp;<code>1</code>&nbsp;,因为&nbsp;<code>1 OR (1 + 1) = 3</code>&nbsp;。</li>
43+
<li>对于&nbsp;<code>i = 2</code>&nbsp;,满足 <code>ans[2] OR (ans[2] + 1) = 5</code>&nbsp;的最小 <code>ans[2]</code>&nbsp;为&nbsp;<code>4</code>&nbsp;,因为&nbsp;<code>4 OR (4 + 1) = 5</code>&nbsp;。</li>
44+
<li>对于&nbsp;<code>i = 3</code>&nbsp;,满足&nbsp;<code>ans[3] OR (ans[3] + 1) = 7</code>&nbsp;的最小&nbsp;<code>ans[3]</code>&nbsp;为&nbsp;<code>3</code>&nbsp;,因为&nbsp;<code>3 OR (3 + 1) = 7</code>&nbsp;。</li>
45+
</ul>
46+
</div>
47+
48+
<p><strong class="example">示例 2:</strong></p>
49+
50+
<div class="example-block">
51+
<p><span class="example-io"><b>输入:</b>nums = [11,13,31]</span></p>
52+
53+
<p><span class="example-io"><b>输出:</b>[9,12,15]</span></p>
54+
55+
<p><b>解释:</b></p>
56+
57+
<ul>
58+
<li>对于&nbsp;<code>i = 0</code>&nbsp;,满足&nbsp;<code>ans[0] OR (ans[0] + 1) = 11</code> 的最小&nbsp;<code>ans[0]</code>&nbsp;为&nbsp;<code>9</code>&nbsp;,因为&nbsp;<code>9 OR (9 + 1) = 11</code>&nbsp;。</li>
59+
<li>对于&nbsp;<code>i = 1</code>&nbsp;,满足&nbsp;<code>ans[1] OR (ans[1] + 1) = 13</code>&nbsp;的最小&nbsp;<code>ans[1]</code>&nbsp;为&nbsp;<code>12</code>&nbsp;,因为&nbsp;<code>12 OR (12 + 1) = 13</code>&nbsp;。</li>
60+
<li>对于&nbsp;<code>i = 2</code>&nbsp;,满足&nbsp;<code>ans[2] OR (ans[2] + 1) = 31</code>&nbsp;的最小&nbsp;<code>ans[2]</code>&nbsp;为&nbsp;<code>15</code>&nbsp;,因为&nbsp;<code>15 OR (15 + 1) = 31</code>&nbsp;。</li>
61+
</ul>
62+
</div>
63+
64+
<p>&nbsp;</p>
65+
66+
<p><strong>提示:</strong></p>
67+
68+
<ul>
69+
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
70+
<li><code>2 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
71+
<li><code>nums[i]</code>&nbsp;是一个质数。</li>
72+
</ul>
73+
74+
<!-- description:end -->
75+
76+
## 解法
77+
78+
<!-- solution:start -->
79+
80+
### 方法一
81+
82+
<!-- tabs:start -->
83+
84+
#### Python3
85+
86+
```python
87+
88+
```
89+
90+
#### Java
91+
92+
```java
93+
94+
```
95+
96+
#### C++
97+
98+
```cpp
99+
100+
```
101+
102+
#### Go
103+
104+
```go
105+
106+
```
107+
108+
<!-- tabs:end -->
109+
110+
<!-- solution:end -->
111+
112+
<!-- problem:end -->

0 commit comments

Comments
 (0)