-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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 375 and biweekly contest 119 (#2076)
--------- Co-authored-by: Doocs Bot <[email protected]>
- Loading branch information
Showing
24 changed files
with
1,542 additions
and
0 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
solution/2900-2999/2956.Find Common Elements Between Two Arrays/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,91 @@ | ||
# [2956. 找到两个数组中的公共元素](https://leetcode.cn/problems/find-common-elements-between-two-arrays) | ||
|
||
[English Version](/solution/2900-2999/2956.Find%20Common%20Elements%20Between%20Two%20Arrays/README_EN.md) | ||
|
||
## 题目描述 | ||
|
||
<!-- 这里写题目描述 --> | ||
|
||
<p>给你两个下标从 <strong>0</strong> 开始的整数数组 <code>nums1</code> 和 <code>nums2</code> ,它们分别含有 <code>n</code> 和 <code>m</code> 个元素。</p> | ||
|
||
<p>请你计算以下两个数值:</p> | ||
|
||
<ul> | ||
<li>统计 <code>0 <= i < n</code> 中的下标 <code>i</code> ,满足 <code>nums1[i]</code> 在 <code>nums2</code> 中 <strong>至少</strong> 出现了一次。</li> | ||
<li>统计 <code>0 <= i < m</code> 中的下标 <code>i</code> ,满足 <code>nums2[i]</code> 在 <code>nums1</code> 中 <strong>至少</strong> 出现了一次。</li> | ||
</ul> | ||
|
||
<p>请你返回一个长度为 <code>2</code> 的整数数组<em> </em><code>answer</code> ,<strong>按顺序</strong> 分别为以上两个数值。</p> | ||
|
||
<p> </p> | ||
|
||
<p><strong class="example">示例 1:</strong></p> | ||
|
||
<pre> | ||
<strong>输入:</strong>nums1 = [4,3,2,3,1], nums2 = [2,2,5,2,3,6] | ||
<b>输出:</b>[3,4] | ||
<b>解释:</b>分别计算两个数值: | ||
- nums1 中下标为 1 ,2 和 3 的元素在 nums2 中至少出现了一次,所以第一个值为 3 。 | ||
- nums2 中下标为 0 ,1 ,3 和 4 的元素在 nums1 中至少出现了一次,所以第二个值为 4 。 | ||
</pre> | ||
|
||
<p><strong class="example">示例 2:</strong></p> | ||
|
||
<pre> | ||
<b>输入:</b>nums1 = [3,4,2,3], nums2 = [1,5] | ||
<b>输出:</b>[0,0] | ||
<b>解释:</b>两个数组中没有公共元素,所以两个值都为 0 。 | ||
</pre> | ||
|
||
<p> </p> | ||
|
||
<p><strong>提示:</strong></p> | ||
|
||
<ul> | ||
<li><code>n == nums1.length</code></li> | ||
<li><code>m == nums2.length</code></li> | ||
<li><code>1 <= n, m <= 100</code></li> | ||
<li><code>1 <= nums1[i], nums2[i] <= 100</code></li> | ||
</ul> | ||
|
||
## 解法 | ||
|
||
<!-- 这里可写通用的实现逻辑 --> | ||
|
||
<!-- tabs:start --> | ||
|
||
### **Python3** | ||
|
||
<!-- 这里可写当前语言的特殊实现逻辑 --> | ||
|
||
```python | ||
|
||
``` | ||
|
||
### **Java** | ||
|
||
<!-- 这里可写当前语言的特殊实现逻辑 --> | ||
|
||
```java | ||
|
||
``` | ||
|
||
### **C++** | ||
|
||
```cpp | ||
|
||
``` | ||
|
||
### **Go** | ||
|
||
```go | ||
|
||
``` | ||
|
||
### **...** | ||
|
||
``` | ||
``` | ||
|
||
<!-- tabs:end --> |
81 changes: 81 additions & 0 deletions
81
solution/2900-2999/2956.Find Common Elements Between Two Arrays/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,81 @@ | ||
# [2956. Find Common Elements Between Two Arrays](https://leetcode.com/problems/find-common-elements-between-two-arrays) | ||
|
||
[中文文档](/solution/2900-2999/2956.Find%20Common%20Elements%20Between%20Two%20Arrays/README.md) | ||
|
||
## Description | ||
|
||
<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of sizes <code>n</code> and <code>m</code>, respectively.</p> | ||
|
||
<p>Consider calculating the following values:</p> | ||
|
||
<ul> | ||
<li>The number of indices <code>i</code> such that <code>0 <= i < n</code> and <code>nums1[i]</code> occurs <strong>at least</strong> once in <code>nums2</code>.</li> | ||
<li>The number of indices <code>i</code> such that <code>0 <= i < m</code> and <code>nums2[i]</code> occurs <strong>at least</strong> once in <code>nums1</code>.</li> | ||
</ul> | ||
|
||
<p>Return <em>an integer array </em><code>answer</code><em> of size </em><code>2</code><em> containing the two values <strong>in the above order</strong></em>.</p> | ||
|
||
<p> </p> | ||
<p><strong class="example">Example 1:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> nums1 = [4,3,2,3,1], nums2 = [2,2,5,2,3,6] | ||
<strong>Output:</strong> [3,4] | ||
<strong>Explanation:</strong> We calculate the values as follows: | ||
- The elements at indices 1, 2, and 3 in nums1 occur at least once in nums2. So the first value is 3. | ||
- The elements at indices 0, 1, 3, and 4 in nums2 occur at least once in nums1. So the second value is 4. | ||
</pre> | ||
|
||
<p><strong class="example">Example 2:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> nums1 = [3,4,2,3], nums2 = [1,5] | ||
<strong>Output:</strong> [0,0] | ||
<strong>Explanation:</strong> There are no common elements between the two arrays, so the two values will be 0. | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>n == nums1.length</code></li> | ||
<li><code>m == nums2.length</code></li> | ||
<li><code>1 <= n, m <= 100</code></li> | ||
<li><code>1 <= nums1[i], nums2[i] <= 100</code></li> | ||
</ul> | ||
|
||
## Solutions | ||
|
||
<!-- tabs:start --> | ||
|
||
### **Python3** | ||
|
||
```python | ||
|
||
``` | ||
|
||
### **Java** | ||
|
||
```java | ||
|
||
``` | ||
|
||
### **C++** | ||
|
||
```cpp | ||
|
||
``` | ||
|
||
### **Go** | ||
|
||
```go | ||
|
||
``` | ||
|
||
### **...** | ||
|
||
``` | ||
``` | ||
|
||
<!-- tabs:end --> |
94 changes: 94 additions & 0 deletions
94
solution/2900-2999/2957.Remove Adjacent Almost-Equal Characters/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,94 @@ | ||
# [2957. 消除相邻近似相等字符](https://leetcode.cn/problems/remove-adjacent-almost-equal-characters) | ||
|
||
[English Version](/solution/2900-2999/2957.Remove%20Adjacent%20Almost-Equal%20Characters/README_EN.md) | ||
|
||
## 题目描述 | ||
|
||
<!-- 这里写题目描述 --> | ||
|
||
<p>给你一个下标从 <strong>0</strong> 开始的字符串 <code>word</code> 。</p> | ||
|
||
<p>一次操作中,你可以选择 <code>word</code> 中任意一个下标 <code>i</code> ,将 <code>word[i]</code> 修改成任意一个小写英文字母。</p> | ||
|
||
<p>请你返回消除 <code>word</code> 中所有相邻 <strong>近似相等</strong> 字符的 <strong>最少</strong> 操作次数。</p> | ||
|
||
<p>两个字符 <code>a</code> 和 <code>b</code> 如果满足 <code>a == b</code> 或者 <code>a</code> 和 <code>b</code> 在字母表中是相邻的,那么我们称它们是 <strong>近似相等</strong> 字符。</p> | ||
|
||
<p> </p> | ||
|
||
<p><strong class="example">示例 1:</strong></p> | ||
|
||
<pre> | ||
<b>输入:</b>word = "aaaaa" | ||
<b>输出:</b>2 | ||
<b>解释:</b>我们将 word 变为 "a<em><strong>c</strong></em>a<em><strong>c</strong></em>a" ,该字符串没有相邻近似相等字符。 | ||
消除 word 中所有相邻近似相等字符最少需要 2 次操作。 | ||
</pre> | ||
|
||
<p><strong class="example">示例 2:</strong></p> | ||
|
||
<pre> | ||
<b>输入:</b>word = "abddez" | ||
<b>输出:</b>2 | ||
<b>解释:</b>我们将 word 变为 "<em><strong>y</strong></em>bd<em><strong>o</strong></em>ez" ,该字符串没有相邻近似相等字符。 | ||
消除 word 中所有相邻近似相等字符最少需要 2 次操作。</pre> | ||
|
||
<p><strong class="example">示例 3:</strong></p> | ||
|
||
<pre> | ||
<b>输入:</b>word = "zyxyxyz" | ||
<b>输出:</b>3 | ||
<b>解释:</b>我们将 word 变为 "z<em><strong>a</strong></em>x<em><strong>a</strong></em>x<em><strong>a</strong></em>z" ,该字符串没有相邻近似相等字符。 | ||
消除 word 中所有相邻近似相等字符最少需要 3 次操作 | ||
</pre> | ||
|
||
<p> </p> | ||
|
||
<p><strong>提示:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= word.length <= 100</code></li> | ||
<li><code>word</code> 只包含小写英文字母。</li> | ||
</ul> | ||
|
||
## 解法 | ||
|
||
<!-- 这里可写通用的实现逻辑 --> | ||
|
||
<!-- tabs:start --> | ||
|
||
### **Python3** | ||
|
||
<!-- 这里可写当前语言的特殊实现逻辑 --> | ||
|
||
```python | ||
|
||
``` | ||
|
||
### **Java** | ||
|
||
<!-- 这里可写当前语言的特殊实现逻辑 --> | ||
|
||
```java | ||
|
||
``` | ||
|
||
### **C++** | ||
|
||
```cpp | ||
|
||
``` | ||
|
||
### **Go** | ||
|
||
```go | ||
|
||
``` | ||
|
||
### **...** | ||
|
||
``` | ||
``` | ||
|
||
<!-- tabs:end --> |
84 changes: 84 additions & 0 deletions
84
solution/2900-2999/2957.Remove Adjacent Almost-Equal Characters/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,84 @@ | ||
# [2957. Remove Adjacent Almost-Equal Characters](https://leetcode.com/problems/remove-adjacent-almost-equal-characters) | ||
|
||
[中文文档](/solution/2900-2999/2957.Remove%20Adjacent%20Almost-Equal%20Characters/README.md) | ||
|
||
## Description | ||
|
||
<p>You are given a <strong>0-indexed</strong> string <code>word</code>.</p> | ||
|
||
<p>In one operation, you can pick any index <code>i</code> of <code>word</code> and change <code>word[i]</code> to any lowercase English letter.</p> | ||
|
||
<p>Return <em>the <strong>minimum</strong> number of operations needed to remove all adjacent <strong>almost-equal</strong> characters from</em> <code>word</code>.</p> | ||
|
||
<p>Two characters <code>a</code> and <code>b</code> are <strong>almost-equal</strong> if <code>a == b</code> or <code>a</code> and <code>b</code> are adjacent in the alphabet.</p> | ||
|
||
<p> </p> | ||
<p><strong class="example">Example 1:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> word = "aaaaa" | ||
<strong>Output:</strong> 2 | ||
<strong>Explanation:</strong> We can change word into "a<strong><u>c</u></strong>a<u><strong>c</strong></u>a" which does not have any adjacent almost-equal characters. | ||
It can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 2. | ||
</pre> | ||
|
||
<p><strong class="example">Example 2:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> word = "abddez" | ||
<strong>Output:</strong> 2 | ||
<strong>Explanation:</strong> We can change word into "<strong><u>y</u></strong>bd<u><strong>o</strong></u>ez" which does not have any adjacent almost-equal characters. | ||
It can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 2.</pre> | ||
|
||
<p><strong class="example">Example 3:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> word = "zyxyxyz" | ||
<strong>Output:</strong> 3 | ||
<strong>Explanation:</strong> We can change word into "z<u><strong>a</strong></u>x<u><strong>a</strong></u>x<strong><u>a</u></strong>z" which does not have any adjacent almost-equal characters. | ||
It can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 3. | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= word.length <= 100</code></li> | ||
<li><code>word</code> consists only of lowercase English letters.</li> | ||
</ul> | ||
|
||
## Solutions | ||
|
||
<!-- tabs:start --> | ||
|
||
### **Python3** | ||
|
||
```python | ||
|
||
``` | ||
|
||
### **Java** | ||
|
||
```java | ||
|
||
``` | ||
|
||
### **C++** | ||
|
||
```cpp | ||
|
||
``` | ||
|
||
### **Go** | ||
|
||
```go | ||
|
||
``` | ||
|
||
### **...** | ||
|
||
``` | ||
``` | ||
|
||
<!-- tabs:end --> |
Oops, something went wrong.