-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add weekly contest 371 (#1958)
- Loading branch information
Showing
14 changed files
with
818 additions
and
0 deletions.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
solution/2900-2999/2932.Maximum Strong Pair XOR I/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# [2932. 找出强数对的最大异或值 I](https://leetcode.cn/problems/maximum-strong-pair-xor-i) | ||
|
||
[English Version](/solution/2900-2999/2932.Maximum%20Strong%20Pair%20XOR%20I/README_EN.md) | ||
|
||
## 题目描述 | ||
|
||
<!-- 这里写题目描述 --> | ||
|
||
<p>给你一个下标从 <strong>0</strong> 开始的整数数组 <code>nums</code> 。如果一对整数 <code>x</code> 和 <code>y</code> 满足以下条件,则称其为 <strong>强数对</strong> :</p> | ||
|
||
<ul> | ||
<li><code>|x - y| <= min(x, y)</code></li> | ||
</ul> | ||
|
||
<p>你需要从 <code>nums</code> 中选出两个整数,且满足:这两个整数可以形成一个强数对,并且它们的按位异或(<code>XOR</code>)值是在该数组所有强数对中的<strong> 最大值 </strong>。</p> | ||
|
||
<p>返回数组 <code>nums</code> 所有可能的强数对中的<strong> 最大 </strong>异或值。</p> | ||
|
||
<p><strong>注意</strong>,你可以选择同一个整数两次来形成一个强数对。</p> | ||
|
||
<p> </p> | ||
|
||
<p><strong class="example">示例 1:</strong></p> | ||
|
||
<pre> | ||
<strong>输入:</strong>nums = [1,2,3,4,5] | ||
<strong>输出:</strong>7 | ||
<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) 。 | ||
这些强数对中的最大异或值是 3 XOR 4 = 7 。 | ||
</pre> | ||
|
||
<p><strong class="example">示例 2:</strong></p> | ||
|
||
<pre> | ||
<strong>输入:</strong>nums = [10,100] | ||
<strong>输出:</strong>0 | ||
<strong>解释:</strong>数组<code> nums </code>中有 2 个强数对:(10, 10) 和 (100, 100) 。 | ||
这些强数对中的最大异或值是 10 XOR 10 = 0 ,数对 (100, 100) 的异或值也是 100 XOR 100 = 0 。 | ||
</pre> | ||
|
||
<p><strong class="example">示例 3:</strong></p> | ||
|
||
<pre> | ||
<strong>输入:</strong>nums = [5,6,25,30] | ||
<strong>输出:</strong>7 | ||
<strong>解释:</strong>数组<code> nums </code>中有 6 个强数对:(5, 5), (5, 6), (6, 6), (25, 25), (25, 30) 和 (30, 30) 。 | ||
这些强数对中的最大异或值是 25 XOR 30 = 7 ;另一个异或值非零的数对是 (5, 6) ,其异或值是 5 XOR 6 = 3 。 | ||
</pre> | ||
|
||
<p> </p> | ||
|
||
<p><strong>提示:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= nums.length <= 50</code></li> | ||
<li><code>1 <= nums[i] <= 100</code></li> | ||
</ul> | ||
|
||
## 解法 | ||
|
||
<!-- 这里可写通用的实现逻辑 --> | ||
|
||
<!-- tabs:start --> | ||
|
||
### **Python3** | ||
|
||
<!-- 这里可写当前语言的特殊实现逻辑 --> | ||
|
||
```python | ||
|
||
``` | ||
|
||
### **Java** | ||
|
||
<!-- 这里可写当前语言的特殊实现逻辑 --> | ||
|
||
```java | ||
|
||
``` | ||
|
||
### **C++** | ||
|
||
```cpp | ||
|
||
``` | ||
|
||
### **Go** | ||
|
||
```go | ||
|
||
``` | ||
|
||
### **...** | ||
|
||
``` | ||
``` | ||
|
||
<!-- tabs:end --> |
89 changes: 89 additions & 0 deletions
89
solution/2900-2999/2932.Maximum Strong Pair XOR I/README_EN.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# [2932. Maximum Strong Pair XOR I](https://leetcode.com/problems/maximum-strong-pair-xor-i) | ||
|
||
[中文文档](/solution/2900-2999/2932.Maximum%20Strong%20Pair%20XOR%20I/README.md) | ||
|
||
## Description | ||
|
||
<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> | ||
|
||
<ul> | ||
<li><code>|x - y| <= min(x, y)</code></li> | ||
</ul> | ||
|
||
<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> | ||
|
||
<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> | ||
|
||
<p><strong>Note</strong> that you can pick the same integer twice to form a pair.</p> | ||
|
||
<p> </p> | ||
<p><strong class="example">Example 1:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> nums = [1,2,3,4,5] | ||
<strong>Output:</strong> 7 | ||
<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). | ||
The maximum XOR possible from these pairs is 3 XOR 4 = 7. | ||
</pre> | ||
|
||
<p><strong class="example">Example 2:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> nums = [10,100] | ||
<strong>Output:</strong> 0 | ||
<strong>Explanation:</strong> There are 2 strong pairs in the array <code>nums</code>: (10, 10) and (100, 100). | ||
The maximum XOR possible from these pairs is 10 XOR 10 = 0 since the pair (100, 100) also gives 100 XOR 100 = 0. | ||
</pre> | ||
|
||
<p><strong class="example">Example 3:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> nums = [5,6,25,30] | ||
<strong>Output:</strong> 7 | ||
<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). | ||
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. | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= nums.length <= 50</code></li> | ||
<li><code>1 <= nums[i] <= 100</code></li> | ||
</ul> | ||
|
||
## Solutions | ||
|
||
<!-- tabs:start --> | ||
|
||
### **Python3** | ||
|
||
```python | ||
|
||
``` | ||
|
||
### **Java** | ||
|
||
```java | ||
|
||
``` | ||
|
||
### **C++** | ||
|
||
```cpp | ||
|
||
``` | ||
|
||
### **Go** | ||
|
||
```go | ||
|
||
``` | ||
|
||
### **...** | ||
|
||
``` | ||
``` | ||
|
||
<!-- tabs:end --> |
104 changes: 104 additions & 0 deletions
104
solution/2900-2999/2933.High-Access Employees/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# [2933. 高访问员工](https://leetcode.cn/problems/high-access-employees) | ||
|
||
[English Version](/solution/2900-2999/2933.High-Access%20Employees/README_EN.md) | ||
|
||
## 题目描述 | ||
|
||
<!-- 这里写题目描述 --> | ||
|
||
<p>给你一个长度为 <code>n</code> 、下标从 <strong>0</strong> 开始的二维字符串数组 <code>access_times</code> 。对于每个 <code>i</code>(<code>0 <= i <= n - 1</code> ),<code>access_times[i][0]</code> 表示某位员工的姓名,<code>access_times[i][1]</code> 表示该员工的访问时间。<code>access_times</code> 中的所有条目都发生在同一天内。</p> | ||
|
||
<p>访问时间用 <strong>四位</strong> 数字表示, 符合 <strong>24 小时制</strong> ,例如 <code>"0800"</code> 或 <code>"2250"</code> 。</p> | ||
|
||
<p>如果员工在 <strong>同一小时内</strong> 访问系统 <strong>三次或更多</strong> ,则称其为 <strong>高访问</strong> 员工。</p> | ||
|
||
<p>时间间隔正好相差一小时的时间 <strong>不</strong> 被视为同一小时内。例如,<code>"0815"</code> 和 <code>"0915"</code> 不属于同一小时内。</p> | ||
|
||
<p>一天开始和结束时的访问时间不被计算为同一小时内。例如,<code>"0005"</code> 和 <code>"2350"</code> 不属于同一小时内。</p> | ||
|
||
<p>以列表形式,按任意顺序,返回所有 <strong>高访问</strong> 员工的姓名。</p> | ||
|
||
<p> </p> | ||
|
||
<p><strong class="example">示例 1:</strong></p> | ||
|
||
<pre> | ||
<strong>输入:</strong>access_times = [["a","0549"],["b","0457"],["a","0532"],["a","0621"],["b","0540"]] | ||
<strong>输出:</strong>["a"] | ||
<strong>解释:</strong>"a" 在时间段 [05:32, 06:31] 内有三条访问记录,时间分别为 05:32 、05:49 和 06:21 。 | ||
但是 "b" 的访问记录只有两条。 | ||
因此,答案是 ["a"] 。</pre> | ||
|
||
<p><strong class="example">示例 2:</strong></p> | ||
|
||
<pre> | ||
<strong>输入:</strong>access_times = [["d","0002"],["c","0808"],["c","0829"],["e","0215"],["d","1508"],["d","1444"],["d","1410"],["c","0809"]] | ||
<strong>输出:</strong>["c","d"] | ||
<strong>解释:</strong>"c" 在时间段 [08:08, 09:07] 内有三条访问记录,时间分别为 08:08 、08:09 和 08:29 。 | ||
"d" 在时间段 [14:10, 15:09] 内有三条访问记录,时间分别为 14:10 、14:44 和 15:08 。 | ||
然而,"e" 只有一条访问记录,因此不能包含在答案中,最终答案是 ["c","d"] 。</pre> | ||
|
||
<p><strong class="example">示例 3:</strong></p> | ||
|
||
<pre> | ||
<strong>输入:</strong>access_times = [["cd","1025"],["ab","1025"],["cd","1046"],["cd","1055"],["ab","1124"],["ab","1120"]] | ||
<strong>输出:</strong>["ab","cd"] | ||
<strong>解释:</strong>"ab"在时间段 [10:25, 11:24] 内有三条访问记录,时间分别为 10:25 、11:20 和 11:24 。 | ||
"cd" 在时间段 [10:25, 11:24] 内有三条访问记录,时间分别为 10:25 、10:46 和 10:55 。 | ||
因此,答案是 ["ab","cd"] 。</pre> | ||
|
||
<p> </p> | ||
|
||
<p><strong>提示:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= access_times.length <= 100</code></li> | ||
<li><code>access_times[i].length == 2</code></li> | ||
<li><code>1 <= access_times[i][0].length <= 10</code></li> | ||
<li><code>access_times[i][0]</code> 仅由小写英文字母组成。</li> | ||
<li><code>access_times[i][1].length == 4</code></li> | ||
<li><code>access_times[i][1]</code> 采用24小时制表示时间。</li> | ||
<li><code>access_times[i][1]</code> 仅由数字 <code>'0'</code> 到 <code>'9'</code> 组成。</li> | ||
</ul> | ||
|
||
## 解法 | ||
|
||
<!-- 这里可写通用的实现逻辑 --> | ||
|
||
<!-- tabs:start --> | ||
|
||
### **Python3** | ||
|
||
<!-- 这里可写当前语言的特殊实现逻辑 --> | ||
|
||
```python | ||
|
||
``` | ||
|
||
### **Java** | ||
|
||
<!-- 这里可写当前语言的特殊实现逻辑 --> | ||
|
||
```java | ||
|
||
``` | ||
|
||
### **C++** | ||
|
||
```cpp | ||
|
||
``` | ||
|
||
### **Go** | ||
|
||
```go | ||
|
||
``` | ||
|
||
### **...** | ||
|
||
``` | ||
``` | ||
|
||
<!-- tabs:end --> |
94 changes: 94 additions & 0 deletions
94
solution/2900-2999/2933.High-Access Employees/README_EN.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# [2933. High-Access Employees](https://leetcode.com/problems/high-access-employees) | ||
|
||
[中文文档](/solution/2900-2999/2933.High-Access%20Employees/README.md) | ||
|
||
## Description | ||
|
||
<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 <= i <= 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> | ||
|
||
<p>The access time is represented as <strong>four digits</strong> using a <strong>24-hour</strong> time format, for example, <code>"0800"</code> or <code>"2250"</code>.</p> | ||
|
||
<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> | ||
|
||
<p>Times with exactly one hour of difference are <strong>not</strong> considered part of the same one-hour period. For example, <code>"0815"</code> and <code>"0915"</code> are not part of the same one-hour period.</p> | ||
|
||
<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>"0005"</code> and <code>"2350"</code> are not part of the same one-hour period.</p> | ||
|
||
<p>Return <em>a list that contains the names of <strong>high-access</strong> employees with any order you want.</em></p> | ||
|
||
<p> </p> | ||
<p><strong class="example">Example 1:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> access_times = [["a","0549"],["b","0457"],["a","0532"],["a","0621"],["b","0540"]] | ||
<strong>Output:</strong> ["a"] | ||
<strong>Explanation:</strong> "a" has three access times in the one-hour period of [05:32, 06:31] which are 05:32, 05:49, and 06:21. | ||
But "b" does not have more than two access times at all. | ||
So the answer is ["a"].</pre> | ||
|
||
<p><strong class="example">Example 2:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> access_times = [["d","0002"],["c","0808"],["c","0829"],["e","0215"],["d","1508"],["d","1444"],["d","1410"],["c","0809"]] | ||
<strong>Output:</strong> ["c","d"] | ||
<strong>Explanation:</strong> "c" has three access times in the one-hour period of [08:08, 09:07] which are 08:08, 08:09, and 08:29. | ||
"d" has also three access times in the one-hour period of [14:10, 15:09] which are 14:10, 14:44, and 15:08. | ||
However, "e" has just one access time, so it can not be in the answer and the final answer is ["c","d"].</pre> | ||
|
||
<p><strong class="example">Example 3:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> access_times = [["cd","1025"],["ab","1025"],["cd","1046"],["cd","1055"],["ab","1124"],["ab","1120"]] | ||
<strong>Output:</strong> ["ab","cd"] | ||
<strong>Explanation:</strong> "ab" has three access times in the one-hour period of [10:25, 11:24] which are 10:25, 11:20, and 11:24. | ||
"cd" has also three access times in the one-hour period of [10:25, 11:24] which are 10:25, 10:46, and 10:55. | ||
So the answer is ["ab","cd"].</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= access_times.length <= 100</code></li> | ||
<li><code>access_times[i].length == 2</code></li> | ||
<li><code>1 <= access_times[i][0].length <= 10</code></li> | ||
<li><code>access_times[i][0]</code> consists only of English small letters.</li> | ||
<li><code>access_times[i][1].length == 4</code></li> | ||
<li><code>access_times[i][1]</code> is in 24-hour time format.</li> | ||
<li><code>access_times[i][1]</code> consists only of <code>'0'</code> to <code>'9'</code>.</li> | ||
</ul> | ||
|
||
## Solutions | ||
|
||
<!-- tabs:start --> | ||
|
||
### **Python3** | ||
|
||
```python | ||
|
||
``` | ||
|
||
### **Java** | ||
|
||
```java | ||
|
||
``` | ||
|
||
### **C++** | ||
|
||
```cpp | ||
|
||
``` | ||
|
||
### **Go** | ||
|
||
```go | ||
|
||
``` | ||
|
||
### **...** | ||
|
||
``` | ||
``` | ||
|
||
<!-- tabs:end --> |
Oops, something went wrong.