Skip to content

Commit b51a566

Browse files
authored
feat: add weekly contest 371 (doocs#1958)
1 parent b84f6c5 commit b51a566

File tree

14 files changed

+818
-0
lines changed

14 files changed

+818
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# [2932. 找出强数对的最大异或值 I](https://leetcode.cn/problems/maximum-strong-pair-xor-i)
2+
3+
[English Version](/solution/2900-2999/2932.Maximum%20Strong%20Pair%20XOR%20I/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你一个下标从 <strong>0</strong> 开始的整数数组 <code>nums</code> 。如果一对整数 <code>x</code> 和 <code>y</code> 满足以下条件,则称其为 <strong>强数对</strong> :</p>
10+
11+
<ul>
12+
<li><code>|x - y| &lt;= min(x, y)</code></li>
13+
</ul>
14+
15+
<p>你需要从 <code>nums</code> 中选出两个整数,且满足:这两个整数可以形成一个强数对,并且它们的按位异或(<code>XOR</code>)值是在该数组所有强数对中的<strong> 最大值 </strong>。</p>
16+
17+
<p>返回数组 <code>nums</code> 所有可能的强数对中的<strong> 最大 </strong>异或值。</p>
18+
19+
<p><strong>注意</strong>,你可以选择同一个整数两次来形成一个强数对。</p>
20+
21+
<p>&nbsp;</p>
22+
23+
<p><strong class="example">示例 1:</strong></p>
24+
25+
<pre>
26+
<strong>输入:</strong>nums = [1,2,3,4,5]
27+
<strong>输出:</strong>7
28+
<strong>解释:</strong>数组<code> nums </code>中有 11 个强数对:(1, 1), (1, 2), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (3, 5), (4, 4), (4, 5) 和 (5, 5) 。
29+
这些强数对中的最大异或值是 3 XOR 4 = 7 。
30+
</pre>
31+
32+
<p><strong class="example">示例 2:</strong></p>
33+
34+
<pre>
35+
<strong>输入:</strong>nums = [10,100]
36+
<strong>输出:</strong>0
37+
<strong>解释:</strong>数组<code> nums </code>中有 2 个强数对:(10, 10) 和 (100, 100) 。
38+
这些强数对中的最大异或值是 10 XOR 10 = 0 ,数对 (100, 100) 的异或值也是 100 XOR 100 = 0 。
39+
</pre>
40+
41+
<p><strong class="example">示例 3:</strong></p>
42+
43+
<pre>
44+
<strong>输入:</strong>nums = [5,6,25,30]
45+
<strong>输出:</strong>7
46+
<strong>解释:</strong>数组<code> nums </code>中有 6 个强数对:(5, 5), (5, 6), (6, 6), (25, 25), (25, 30) 和 (30, 30) 。
47+
这些强数对中的最大异或值是 25 XOR 30 = 7 ;另一个异或值非零的数对是 (5, 6) ,其异或值是 5 XOR 6 = 3 。
48+
</pre>
49+
50+
<p>&nbsp;</p>
51+
52+
<p><strong>提示:</strong></p>
53+
54+
<ul>
55+
<li><code>1 &lt;= nums.length &lt;= 50</code></li>
56+
<li><code>1 &lt;= nums[i] &lt;= 100</code></li>
57+
</ul>
58+
59+
## 解法
60+
61+
<!-- 这里可写通用的实现逻辑 -->
62+
63+
<!-- tabs:start -->
64+
65+
### **Python3**
66+
67+
<!-- 这里可写当前语言的特殊实现逻辑 -->
68+
69+
```python
70+
71+
```
72+
73+
### **Java**
74+
75+
<!-- 这里可写当前语言的特殊实现逻辑 -->
76+
77+
```java
78+
79+
```
80+
81+
### **C++**
82+
83+
```cpp
84+
85+
```
86+
87+
### **Go**
88+
89+
```go
90+
91+
```
92+
93+
### **...**
94+
95+
```
96+
97+
```
98+
99+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# [2932. Maximum Strong Pair XOR I](https://leetcode.com/problems/maximum-strong-pair-xor-i)
2+
3+
[中文文档](/solution/2900-2999/2932.Maximum%20Strong%20Pair%20XOR%20I/README.md)
4+
5+
## Description
6+
7+
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. A pair of integers <code>x</code> and <code>y</code> is called a <strong>strong</strong> pair if it satisfies the condition:</p>
8+
9+
<ul>
10+
<li><code>|x - y| &lt;= min(x, y)</code></li>
11+
</ul>
12+
13+
<p>You need to select two integers from <code>nums</code> such that they form a strong pair and their bitwise <code>XOR</code> is the <strong>maximum</strong> among all strong pairs in the array.</p>
14+
15+
<p>Return <em>the <strong>maximum</strong> </em><code>XOR</code><em> value out of all possible strong pairs in the array</em> <code>nums</code>.</p>
16+
17+
<p><strong>Note</strong> that you can pick the same integer twice to form a pair.</p>
18+
19+
<p>&nbsp;</p>
20+
<p><strong class="example">Example 1:</strong></p>
21+
22+
<pre>
23+
<strong>Input:</strong> nums = [1,2,3,4,5]
24+
<strong>Output:</strong> 7
25+
<strong>Explanation:</strong> There are 11 strong pairs in the array <code>nums</code>: (1, 1), (1, 2), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (3, 5), (4, 4), (4, 5) and (5, 5).
26+
The maximum XOR possible from these pairs is 3 XOR 4 = 7.
27+
</pre>
28+
29+
<p><strong class="example">Example 2:</strong></p>
30+
31+
<pre>
32+
<strong>Input:</strong> nums = [10,100]
33+
<strong>Output:</strong> 0
34+
<strong>Explanation:</strong> There are 2 strong pairs in the array <code>nums</code>: (10, 10) and (100, 100).
35+
The maximum XOR possible from these pairs is 10 XOR 10 = 0 since the pair (100, 100) also gives 100 XOR 100 = 0.
36+
</pre>
37+
38+
<p><strong class="example">Example 3:</strong></p>
39+
40+
<pre>
41+
<strong>Input:</strong> nums = [5,6,25,30]
42+
<strong>Output:</strong> 7
43+
<strong>Explanation:</strong> There are 6 strong pairs in the array <code>nums</code>: (5, 5), (5, 6), (6, 6), (25, 25), (25, 30) and (30, 30).
44+
The maximum XOR possible from these pairs is 25 XOR 30 = 7 since the only other non-zero XOR value is 5 XOR 6 = 3.
45+
</pre>
46+
47+
<p>&nbsp;</p>
48+
<p><strong>Constraints:</strong></p>
49+
50+
<ul>
51+
<li><code>1 &lt;= nums.length &lt;= 50</code></li>
52+
<li><code>1 &lt;= nums[i] &lt;= 100</code></li>
53+
</ul>
54+
55+
## Solutions
56+
57+
<!-- tabs:start -->
58+
59+
### **Python3**
60+
61+
```python
62+
63+
```
64+
65+
### **Java**
66+
67+
```java
68+
69+
```
70+
71+
### **C++**
72+
73+
```cpp
74+
75+
```
76+
77+
### **Go**
78+
79+
```go
80+
81+
```
82+
83+
### **...**
84+
85+
```
86+
87+
```
88+
89+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# [2933. 高访问员工](https://leetcode.cn/problems/high-access-employees)
2+
3+
[English Version](/solution/2900-2999/2933.High-Access%20Employees/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你一个长度为 <code>n</code> 、下标从 <strong>0</strong> 开始的二维字符串数组 <code>access_times</code> 。对于每个 <code>i</code>(<code>0 &lt;= i &lt;= n - 1</code> ),<code>access_times[i][0]</code> 表示某位员工的姓名,<code>access_times[i][1]</code> 表示该员工的访问时间。<code>access_times</code> 中的所有条目都发生在同一天内。</p>
10+
11+
<p>访问时间用 <strong>四位</strong> 数字表示, 符合 <strong>24 小时制</strong> ,例如 <code>"0800"</code> 或 <code>"2250"</code> 。</p>
12+
13+
<p>如果员工在 <strong>同一小时内</strong> 访问系统 <strong>三次或更多</strong> ,则称其为 <strong>高访问</strong> 员工。</p>
14+
15+
<p>时间间隔正好相差一小时的时间 <strong>不</strong> 被视为同一小时内。例如,<code>"0815"</code> 和 <code>"0915"</code> 不属于同一小时内。</p>
16+
17+
<p>一天开始和结束时的访问时间不被计算为同一小时内。例如,<code>"0005"</code> 和 <code>"2350"</code> 不属于同一小时内。</p>
18+
19+
<p>以列表形式,按任意顺序,返回所有 <strong>高访问</strong> 员工的姓名。</p>
20+
21+
<p>&nbsp;</p>
22+
23+
<p><strong class="example">示例 1:</strong></p>
24+
25+
<pre>
26+
<strong>输入:</strong>access_times = [["a","0549"],["b","0457"],["a","0532"],["a","0621"],["b","0540"]]
27+
<strong>输出:</strong>["a"]
28+
<strong>解释:</strong>"a" 在时间段 [05:32, 06:31] 内有三条访问记录,时间分别为 05:32 、05:49 和 06:21 。
29+
但是 "b" 的访问记录只有两条。
30+
因此,答案是 ["a"] 。</pre>
31+
32+
<p><strong class="example">示例 2:</strong></p>
33+
34+
<pre>
35+
<strong>输入:</strong>access_times = [["d","0002"],["c","0808"],["c","0829"],["e","0215"],["d","1508"],["d","1444"],["d","1410"],["c","0809"]]
36+
<strong>输出:</strong>["c","d"]
37+
<strong>解释:</strong>"c" 在时间段 [08:08, 09:07] 内有三条访问记录,时间分别为 08:08 、08:09 和 08:29 。
38+
"d" 在时间段 [14:10, 15:09] 内有三条访问记录,时间分别为 14:10 、14:44 和 15:08 。
39+
然而,"e" 只有一条访问记录,因此不能包含在答案中,最终答案是 ["c","d"] 。</pre>
40+
41+
<p><strong class="example">示例 3:</strong></p>
42+
43+
<pre>
44+
<strong>输入:</strong>access_times = [["cd","1025"],["ab","1025"],["cd","1046"],["cd","1055"],["ab","1124"],["ab","1120"]]
45+
<strong>输出:</strong>["ab","cd"]
46+
<strong>解释:</strong>"ab"在时间段 [10:25, 11:24] 内有三条访问记录,时间分别为 10:25 、11:20 和 11:24 。
47+
"cd" 在时间段 [10:25, 11:24] 内有三条访问记录,时间分别为 10:25 、10:46 和 10:55 。
48+
因此,答案是 ["ab","cd"] 。</pre>
49+
50+
<p>&nbsp;</p>
51+
52+
<p><strong>提示:</strong></p>
53+
54+
<ul>
55+
<li><code>1 &lt;= access_times.length &lt;= 100</code></li>
56+
<li><code>access_times[i].length == 2</code></li>
57+
<li><code>1 &lt;= access_times[i][0].length &lt;= 10</code></li>
58+
<li><code>access_times[i][0]</code> 仅由小写英文字母组成。</li>
59+
<li><code>access_times[i][1].length == 4</code></li>
60+
<li><code>access_times[i][1]</code> 采用24小时制表示时间。</li>
61+
<li><code>access_times[i][1]</code> 仅由数字 <code>'0'</code> 到 <code>'9'</code> 组成。</li>
62+
</ul>
63+
64+
## 解法
65+
66+
<!-- 这里可写通用的实现逻辑 -->
67+
68+
<!-- tabs:start -->
69+
70+
### **Python3**
71+
72+
<!-- 这里可写当前语言的特殊实现逻辑 -->
73+
74+
```python
75+
76+
```
77+
78+
### **Java**
79+
80+
<!-- 这里可写当前语言的特殊实现逻辑 -->
81+
82+
```java
83+
84+
```
85+
86+
### **C++**
87+
88+
```cpp
89+
90+
```
91+
92+
### **Go**
93+
94+
```go
95+
96+
```
97+
98+
### **...**
99+
100+
```
101+
102+
```
103+
104+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# [2933. High-Access Employees](https://leetcode.com/problems/high-access-employees)
2+
3+
[中文文档](/solution/2900-2999/2933.High-Access%20Employees/README.md)
4+
5+
## Description
6+
7+
<p>You are given a 2D <strong>0-indexed</strong> array of strings, <code>access_times</code>, with size <code>n</code>. For each <code>i</code> where <code>0 &lt;= i &lt;= n - 1</code>, <code>access_times[i][0]</code> represents the name of an employee, and <code>access_times[i][1]</code> represents the access time of that employee. All entries in <code>access_times</code> are within the same day.</p>
8+
9+
<p>The access time is represented as <strong>four digits</strong> using a <strong>24-hour</strong> time format, for example, <code>&quot;0800&quot;</code> or <code>&quot;2250&quot;</code>.</p>
10+
11+
<p>An employee is said to be <strong>high-access</strong> if he has accessed the system <strong>three or more</strong> times within a <strong>one-hour period</strong>.</p>
12+
13+
<p>Times with exactly one hour of difference are <strong>not</strong> considered part of the same one-hour period. For example, <code>&quot;0815&quot;</code> and <code>&quot;0915&quot;</code> are not part of the same one-hour period.</p>
14+
15+
<p>Access times at the start and end of the day are <strong>not</strong> counted within the same one-hour period. For example, <code>&quot;0005&quot;</code> and <code>&quot;2350&quot;</code> are not part of the same one-hour period.</p>
16+
17+
<p>Return <em>a list that contains the names of <strong>high-access</strong> employees with any order you want.</em></p>
18+
19+
<p>&nbsp;</p>
20+
<p><strong class="example">Example 1:</strong></p>
21+
22+
<pre>
23+
<strong>Input:</strong> access_times = [[&quot;a&quot;,&quot;0549&quot;],[&quot;b&quot;,&quot;0457&quot;],[&quot;a&quot;,&quot;0532&quot;],[&quot;a&quot;,&quot;0621&quot;],[&quot;b&quot;,&quot;0540&quot;]]
24+
<strong>Output:</strong> [&quot;a&quot;]
25+
<strong>Explanation:</strong> &quot;a&quot; has three access times in the one-hour period of [05:32, 06:31] which are 05:32, 05:49, and 06:21.
26+
But &quot;b&quot; does not have more than two access times at all.
27+
So the answer is [&quot;a&quot;].</pre>
28+
29+
<p><strong class="example">Example 2:</strong></p>
30+
31+
<pre>
32+
<strong>Input:</strong> access_times = [[&quot;d&quot;,&quot;0002&quot;],[&quot;c&quot;,&quot;0808&quot;],[&quot;c&quot;,&quot;0829&quot;],[&quot;e&quot;,&quot;0215&quot;],[&quot;d&quot;,&quot;1508&quot;],[&quot;d&quot;,&quot;1444&quot;],[&quot;d&quot;,&quot;1410&quot;],[&quot;c&quot;,&quot;0809&quot;]]
33+
<strong>Output:</strong> [&quot;c&quot;,&quot;d&quot;]
34+
<strong>Explanation:</strong> &quot;c&quot; has three access times in the one-hour period of [08:08, 09:07] which are 08:08, 08:09, and 08:29.
35+
&quot;d&quot; has also three access times in the one-hour period of [14:10, 15:09] which are 14:10, 14:44, and 15:08.
36+
However, &quot;e&quot; has just one access time, so it can not be in the answer and the final answer is [&quot;c&quot;,&quot;d&quot;].</pre>
37+
38+
<p><strong class="example">Example 3:</strong></p>
39+
40+
<pre>
41+
<strong>Input:</strong> access_times = [[&quot;cd&quot;,&quot;1025&quot;],[&quot;ab&quot;,&quot;1025&quot;],[&quot;cd&quot;,&quot;1046&quot;],[&quot;cd&quot;,&quot;1055&quot;],[&quot;ab&quot;,&quot;1124&quot;],[&quot;ab&quot;,&quot;1120&quot;]]
42+
<strong>Output:</strong> [&quot;ab&quot;,&quot;cd&quot;]
43+
<strong>Explanation:</strong> &quot;ab&quot; has three access times in the one-hour period of [10:25, 11:24] which are 10:25, 11:20, and 11:24.
44+
&quot;cd&quot; has also three access times in the one-hour period of [10:25, 11:24] which are 10:25, 10:46, and 10:55.
45+
So the answer is [&quot;ab&quot;,&quot;cd&quot;].</pre>
46+
47+
<p>&nbsp;</p>
48+
<p><strong>Constraints:</strong></p>
49+
50+
<ul>
51+
<li><code>1 &lt;= access_times.length &lt;= 100</code></li>
52+
<li><code>access_times[i].length == 2</code></li>
53+
<li><code>1 &lt;= access_times[i][0].length &lt;= 10</code></li>
54+
<li><code>access_times[i][0]</code> consists only of English small letters.</li>
55+
<li><code>access_times[i][1].length == 4</code></li>
56+
<li><code>access_times[i][1]</code> is in 24-hour time format.</li>
57+
<li><code>access_times[i][1]</code> consists only of <code>&#39;0&#39;</code> to <code>&#39;9&#39;</code>.</li>
58+
</ul>
59+
60+
## Solutions
61+
62+
<!-- tabs:start -->
63+
64+
### **Python3**
65+
66+
```python
67+
68+
```
69+
70+
### **Java**
71+
72+
```java
73+
74+
```
75+
76+
### **C++**
77+
78+
```cpp
79+
80+
```
81+
82+
### **Go**
83+
84+
```go
85+
86+
```
87+
88+
### **...**
89+
90+
```
91+
92+
```
93+
94+
<!-- tabs:end -->

0 commit comments

Comments
 (0)