Skip to content

Commit fc2da90

Browse files
acbinidoocs
andauthored
feat: add weekly contest 375 and biweekly contest 119 (doocs#2076)
--------- Co-authored-by: Doocs Bot <doocs-bot@outlook.com>
1 parent bd766a4 commit fc2da90

File tree

24 files changed

+1542
-0
lines changed

24 files changed

+1542
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# [2956. 找到两个数组中的公共元素](https://leetcode.cn/problems/find-common-elements-between-two-arrays)
2+
3+
[English Version](/solution/2900-2999/2956.Find%20Common%20Elements%20Between%20Two%20Arrays/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你两个下标从 <strong>0</strong>&nbsp;开始的整数数组&nbsp;<code>nums1</code>&nbsp;&nbsp;<code>nums2</code>&nbsp;,它们分别含有 <code>n</code>&nbsp;和 <code>m</code>&nbsp;个元素。</p>
10+
11+
<p>请你计算以下两个数值:</p>
12+
13+
<ul>
14+
<li>统计&nbsp;<code>0 &lt;= i &lt; n</code>&nbsp;中的下标&nbsp;<code>i</code>&nbsp;,满足&nbsp;<code>nums1[i]</code>&nbsp;在 <code>nums2</code>&nbsp;中 <strong>至少</strong>&nbsp;出现了一次。</li>
15+
<li>统计&nbsp;<code>0 &lt;= i &lt; m</code>&nbsp;中的下标&nbsp;<code>i</code>&nbsp;,满足&nbsp;<code>nums2[i]</code>&nbsp;在 <code>nums1</code>&nbsp;中 <strong>至少</strong>&nbsp;出现了一次。</li>
16+
</ul>
17+
18+
<p>请你返回一个长度为 <code>2</code>&nbsp;的整数数组<em>&nbsp;</em><code>answer</code>&nbsp;,<strong>按顺序</strong>&nbsp;分别为以上两个数值。</p>
19+
20+
<p>&nbsp;</p>
21+
22+
<p><strong class="example">示例 1:</strong></p>
23+
24+
<pre>
25+
<strong>输入:</strong>nums1 = [4,3,2,3,1], nums2 = [2,2,5,2,3,6]
26+
<b>输出:</b>[3,4]
27+
<b>解释:</b>分别计算两个数值:
28+
- nums1 中下标为 1 ,2 和 3 的元素在 nums2 中至少出现了一次,所以第一个值为 3 。
29+
- nums2 中下标为 0 ,1 ,3 和 4 的元素在 nums1 中至少出现了一次,所以第二个值为 4 。
30+
</pre>
31+
32+
<p><strong class="example">示例 2:</strong></p>
33+
34+
<pre>
35+
<b>输入:</b>nums1 = [3,4,2,3], nums2 = [1,5]
36+
<b>输出:</b>[0,0]
37+
<b>解释:</b>两个数组中没有公共元素,所以两个值都为 0 。
38+
</pre>
39+
40+
<p>&nbsp;</p>
41+
42+
<p><strong>提示:</strong></p>
43+
44+
<ul>
45+
<li><code>n == nums1.length</code></li>
46+
<li><code>m == nums2.length</code></li>
47+
<li><code>1 &lt;= n, m &lt;= 100</code></li>
48+
<li><code>1 &lt;= nums1[i], nums2[i] &lt;= 100</code></li>
49+
</ul>
50+
51+
## 解法
52+
53+
<!-- 这里可写通用的实现逻辑 -->
54+
55+
<!-- tabs:start -->
56+
57+
### **Python3**
58+
59+
<!-- 这里可写当前语言的特殊实现逻辑 -->
60+
61+
```python
62+
63+
```
64+
65+
### **Java**
66+
67+
<!-- 这里可写当前语言的特殊实现逻辑 -->
68+
69+
```java
70+
71+
```
72+
73+
### **C++**
74+
75+
```cpp
76+
77+
```
78+
79+
### **Go**
80+
81+
```go
82+
83+
```
84+
85+
### **...**
86+
87+
```
88+
89+
```
90+
91+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# [2956. Find Common Elements Between Two Arrays](https://leetcode.com/problems/find-common-elements-between-two-arrays)
2+
3+
[中文文档](/solution/2900-2999/2956.Find%20Common%20Elements%20Between%20Two%20Arrays/README.md)
4+
5+
## Description
6+
7+
<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>
8+
9+
<p>Consider calculating the following values:</p>
10+
11+
<ul>
12+
<li>The number of indices <code>i</code> such that <code>0 &lt;= i &lt; n</code> and <code>nums1[i]</code> occurs <strong>at least</strong> once in <code>nums2</code>.</li>
13+
<li>The number of indices <code>i</code> such that <code>0 &lt;= i &lt; m</code> and <code>nums2[i]</code> occurs <strong>at least</strong> once in <code>nums1</code>.</li>
14+
</ul>
15+
16+
<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>
17+
18+
<p>&nbsp;</p>
19+
<p><strong class="example">Example 1:</strong></p>
20+
21+
<pre>
22+
<strong>Input:</strong> nums1 = [4,3,2,3,1], nums2 = [2,2,5,2,3,6]
23+
<strong>Output:</strong> [3,4]
24+
<strong>Explanation:</strong> We calculate the values as follows:
25+
- The elements at indices 1, 2, and 3 in nums1 occur at least once in nums2. So the first value is 3.
26+
- The elements at indices 0, 1, 3, and 4 in nums2 occur at least once in nums1. So the second value is 4.
27+
</pre>
28+
29+
<p><strong class="example">Example 2:</strong></p>
30+
31+
<pre>
32+
<strong>Input:</strong> nums1 = [3,4,2,3], nums2 = [1,5]
33+
<strong>Output:</strong> [0,0]
34+
<strong>Explanation:</strong> There are no common elements between the two arrays, so the two values will be 0.
35+
</pre>
36+
37+
<p>&nbsp;</p>
38+
<p><strong>Constraints:</strong></p>
39+
40+
<ul>
41+
<li><code>n == nums1.length</code></li>
42+
<li><code>m == nums2.length</code></li>
43+
<li><code>1 &lt;= n, m &lt;= 100</code></li>
44+
<li><code>1 &lt;= nums1[i], nums2[i] &lt;= 100</code></li>
45+
</ul>
46+
47+
## Solutions
48+
49+
<!-- tabs:start -->
50+
51+
### **Python3**
52+
53+
```python
54+
55+
```
56+
57+
### **Java**
58+
59+
```java
60+
61+
```
62+
63+
### **C++**
64+
65+
```cpp
66+
67+
```
68+
69+
### **Go**
70+
71+
```go
72+
73+
```
74+
75+
### **...**
76+
77+
```
78+
79+
```
80+
81+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# [2957. 消除相邻近似相等字符](https://leetcode.cn/problems/remove-adjacent-almost-equal-characters)
2+
3+
[English Version](/solution/2900-2999/2957.Remove%20Adjacent%20Almost-Equal%20Characters/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你一个下标从 <strong>0</strong>&nbsp;开始的字符串&nbsp;<code>word</code>&nbsp;。</p>
10+
11+
<p>一次操作中,你可以选择&nbsp;<code>word</code>&nbsp;中任意一个下标 <code>i</code>&nbsp;,将&nbsp;<code>word[i]</code> 修改成任意一个小写英文字母。</p>
12+
13+
<p>请你返回消除 <code>word</code>&nbsp;中所有相邻 <strong>近似相等</strong>&nbsp;字符的 <strong>最少</strong>&nbsp;操作次数。</p>
14+
15+
<p>两个字符&nbsp;<code>a</code> 和&nbsp;<code>b</code>&nbsp;如果满足&nbsp;<code>a == b</code>&nbsp;或者&nbsp;<code>a</code> 和&nbsp;<code>b</code>&nbsp;在字母表中是相邻的,那么我们称它们是 <strong>近似相等</strong>&nbsp;字符。</p>
16+
17+
<p>&nbsp;</p>
18+
19+
<p><strong class="example">示例 1:</strong></p>
20+
21+
<pre>
22+
<b>输入:</b>word = "aaaaa"
23+
<b>输出:</b>2
24+
<b>解释:</b>我们将 word 变为 "a<em><strong>c</strong></em>a<em><strong>c</strong></em>a" ,该字符串没有相邻近似相等字符。
25+
消除 word 中所有相邻近似相等字符最少需要 2 次操作。
26+
</pre>
27+
28+
<p><strong class="example">示例 2:</strong></p>
29+
30+
<pre>
31+
<b>输入:</b>word = "abddez"
32+
<b>输出:</b>2
33+
<b>解释:</b>我们将 word 变为 "<em><strong>y</strong></em>bd<em><strong>o</strong></em>ez" ,该字符串没有相邻近似相等字符。
34+
消除 word 中所有相邻近似相等字符最少需要 2 次操作。</pre>
35+
36+
<p><strong class="example">示例 3:</strong></p>
37+
38+
<pre>
39+
<b>输入:</b>word = "zyxyxyz"
40+
<b>输出:</b>3
41+
<b>解释:</b>我们将 word 变为 "z<em><strong>a</strong></em>x<em><strong>a</strong></em>x<em><strong>a</strong></em>z" ,该字符串没有相邻近似相等字符。
42+
消除 word 中所有相邻近似相等字符最少需要 3 次操作
43+
</pre>
44+
45+
<p>&nbsp;</p>
46+
47+
<p><strong>提示:</strong></p>
48+
49+
<ul>
50+
<li><code>1 &lt;= word.length &lt;= 100</code></li>
51+
<li><code>word</code>&nbsp;只包含小写英文字母。</li>
52+
</ul>
53+
54+
## 解法
55+
56+
<!-- 这里可写通用的实现逻辑 -->
57+
58+
<!-- tabs:start -->
59+
60+
### **Python3**
61+
62+
<!-- 这里可写当前语言的特殊实现逻辑 -->
63+
64+
```python
65+
66+
```
67+
68+
### **Java**
69+
70+
<!-- 这里可写当前语言的特殊实现逻辑 -->
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 -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# [2957. Remove Adjacent Almost-Equal Characters](https://leetcode.com/problems/remove-adjacent-almost-equal-characters)
2+
3+
[中文文档](/solution/2900-2999/2957.Remove%20Adjacent%20Almost-Equal%20Characters/README.md)
4+
5+
## Description
6+
7+
<p>You are given a <strong>0-indexed</strong> string <code>word</code>.</p>
8+
9+
<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>
10+
11+
<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>
12+
13+
<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>
14+
15+
<p>&nbsp;</p>
16+
<p><strong class="example">Example 1:</strong></p>
17+
18+
<pre>
19+
<strong>Input:</strong> word = &quot;aaaaa&quot;
20+
<strong>Output:</strong> 2
21+
<strong>Explanation:</strong> We can change word into &quot;a<strong><u>c</u></strong>a<u><strong>c</strong></u>a&quot; which does not have any adjacent almost-equal characters.
22+
It can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 2.
23+
</pre>
24+
25+
<p><strong class="example">Example 2:</strong></p>
26+
27+
<pre>
28+
<strong>Input:</strong> word = &quot;abddez&quot;
29+
<strong>Output:</strong> 2
30+
<strong>Explanation:</strong> We can change word into &quot;<strong><u>y</u></strong>bd<u><strong>o</strong></u>ez&quot; which does not have any adjacent almost-equal characters.
31+
It can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 2.</pre>
32+
33+
<p><strong class="example">Example 3:</strong></p>
34+
35+
<pre>
36+
<strong>Input:</strong> word = &quot;zyxyxyz&quot;
37+
<strong>Output:</strong> 3
38+
<strong>Explanation:</strong> We can change word into &quot;z<u><strong>a</strong></u>x<u><strong>a</strong></u>x<strong><u>a</u></strong>z&quot; which does not have any adjacent almost-equal characters.
39+
It can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 3.
40+
</pre>
41+
42+
<p>&nbsp;</p>
43+
<p><strong>Constraints:</strong></p>
44+
45+
<ul>
46+
<li><code>1 &lt;= word.length &lt;= 100</code></li>
47+
<li><code>word</code> consists only of lowercase English letters.</li>
48+
</ul>
49+
50+
## Solutions
51+
52+
<!-- tabs:start -->
53+
54+
### **Python3**
55+
56+
```python
57+
58+
```
59+
60+
### **Java**
61+
62+
```java
63+
64+
```
65+
66+
### **C++**
67+
68+
```cpp
69+
70+
```
71+
72+
### **Go**
73+
74+
```go
75+
76+
```
77+
78+
### **...**
79+
80+
```
81+
82+
```
83+
84+
<!-- tabs:end -->

0 commit comments

Comments
 (0)