Skip to content

Commit 0f1941e

Browse files
acbinidoocs
andauthored
feat: add weekly contest 373 (doocs#2017)
--------- Co-authored-by: Doocs Bot <doocs-bot@outlook.com>
1 parent ad5dea2 commit 0f1941e

File tree

15 files changed

+836
-0
lines changed

15 files changed

+836
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# [2946. 循环移位后的矩阵相似检查](https://leetcode.cn/problems/matrix-similarity-after-cyclic-shifts)
2+
3+
[English Version](/solution/2900-2999/2946.Matrix%20Similarity%20After%20Cyclic%20Shifts/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你一个大小为 <code>m x n</code> 的整数矩阵 <code>mat</code> 和一个整数 <code>k</code> 。请你将矩阵中的<strong> 奇数</strong> 行循环 <strong>右</strong> 移 <code>k</code> 次,<strong>偶数</strong> 行循环 <strong>左</strong> 移 <code>k</code> 次。</p>
10+
11+
<p>如果初始矩阵和最终矩阵完全相同,则返回 <code>true</code> ,否则返回 <code>false</code> 。</p>
12+
13+
<p>&nbsp;</p>
14+
15+
<p><strong class="example">示例 1:</strong></p>
16+
17+
<pre>
18+
<strong>输入:</strong>mat = [[1,2,1,2],[5,5,5,5],[6,3,6,3]], k = 2
19+
<strong>输出:</strong>true
20+
<strong>解释:</strong>
21+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2900-2999/2946.Matrix%20Similarity%20After%20Cyclic%20Shifts/images/similarmatrix.png" style="width: 500px; height: 117px;" />
22+
23+
初始矩阵如图一所示。
24+
图二表示对奇数行右移一次且对偶数行左移一次后的矩阵状态。
25+
图三是经过两次循环移位后的最终矩阵状态,与初始矩阵相同。
26+
因此,返回 true 。
27+
</pre>
28+
29+
<p><strong class="example">示例 2:</strong></p>
30+
31+
<pre>
32+
<strong>输入:</strong>mat = [[2,2],[2,2]], k = 3
33+
<strong>输出:</strong>true
34+
<strong>解释:</strong>由于矩阵中的所有值都相等,即使进行循环移位,矩阵仍然保持不变。因此,返回 true 。
35+
</pre>
36+
37+
<p><strong class="example">示例 3:</strong></p>
38+
39+
<pre>
40+
<strong>输入:</strong>mat = [[1,2]], k = 1
41+
<strong>输出:</strong>false
42+
<strong>解释:</strong>循环移位一次后,mat = [[2,1]],与初始矩阵不相等。因此,返回 false 。
43+
</pre>
44+
45+
<p>&nbsp;</p>
46+
47+
<p><strong>提示:</strong></p>
48+
49+
<ul>
50+
<li><code>1 &lt;= mat.length &lt;= 25</code></li>
51+
<li><code>1 &lt;= mat[i].length &lt;= 25</code></li>
52+
<li><code>1 &lt;= mat[i][j] &lt;= 25</code></li>
53+
<li><code>1 &lt;= k &lt;= 50</code></li>
54+
</ul>
55+
56+
## 解法
57+
58+
<!-- 这里可写通用的实现逻辑 -->
59+
60+
<!-- tabs:start -->
61+
62+
### **Python3**
63+
64+
<!-- 这里可写当前语言的特殊实现逻辑 -->
65+
66+
```python
67+
68+
```
69+
70+
### **Java**
71+
72+
<!-- 这里可写当前语言的特殊实现逻辑 -->
73+
74+
```java
75+
76+
```
77+
78+
### **C++**
79+
80+
```cpp
81+
82+
```
83+
84+
### **Go**
85+
86+
```go
87+
88+
```
89+
90+
### **...**
91+
92+
```
93+
94+
```
95+
96+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# [2946. Matrix Similarity After Cyclic Shifts](https://leetcode.com/problems/matrix-similarity-after-cyclic-shifts)
2+
3+
[中文文档](/solution/2900-2999/2946.Matrix%20Similarity%20After%20Cyclic%20Shifts/README.md)
4+
5+
## Description
6+
7+
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. You have to cyclically <strong>right</strong> shift <strong>odd</strong> indexed rows <code>k</code> times and cyclically <strong>left</strong> shift <strong>even</strong> indexed rows <code>k</code> times.</p>
8+
9+
<p>Return <code>true</code> <em>if the initial and final matrix are exactly the same and </em><code>false</code> <em>otherwise.</em></p>
10+
11+
<p>&nbsp;</p>
12+
<p><strong class="example">Example 1:</strong></p>
13+
14+
<pre>
15+
<strong>Input:</strong> mat = [[1,2,1,2],[5,5,5,5],[6,3,6,3]], k = 2
16+
<strong>Output:</strong> true
17+
<strong>Explanation:</strong>
18+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2900-2999/2946.Matrix%20Similarity%20After%20Cyclic%20Shifts/images/similarmatrix.png" style="width: 500px; height: 117px;" />
19+
20+
Initially, the matrix looks like the first figure.
21+
Second figure represents the state of the matrix after one right and left cyclic shifts to even and odd indexed rows.
22+
Third figure is the final state of the matrix after two cyclic shifts which is similar to the initial matrix.
23+
Therefore, return true.
24+
</pre>
25+
26+
<p><strong class="example">Example 2:</strong></p>
27+
28+
<pre>
29+
<strong>Input:</strong> mat = [[2,2],[2,2]], k = 3
30+
<strong>Output:</strong> true
31+
<strong>Explanation:</strong> As all the values are equal in the matrix, even after performing cyclic shifts the matrix will remain the same. Therefeore, we return true.
32+
</pre>
33+
34+
<p><strong class="example">Example 3:</strong></p>
35+
36+
<pre>
37+
<strong>Input:</strong> mat = [[1,2]], k = 1
38+
<strong>Output:</strong> false
39+
<strong>Explanation:</strong> After one cyclic shift, mat = [[2,1]] which is not equal to the initial matrix. Therefore we return false.
40+
</pre>
41+
42+
<p>&nbsp;</p>
43+
<p><strong>Constraints:</strong></p>
44+
45+
<ul>
46+
<li><code>1 &lt;= mat.length &lt;= 25</code></li>
47+
<li><code>1 &lt;= mat[i].length &lt;= 25</code></li>
48+
<li><code>1 &lt;= mat[i][j] &lt;= 25</code></li>
49+
<li><code>1 &lt;= k &lt;= 50</code></li>
50+
</ul>
51+
52+
## Solutions
53+
54+
<!-- tabs:start -->
55+
56+
### **Python3**
57+
58+
```python
59+
60+
```
61+
62+
### **Java**
63+
64+
```java
65+
66+
```
67+
68+
### **C++**
69+
70+
```cpp
71+
72+
```
73+
74+
### **Go**
75+
76+
```go
77+
78+
```
79+
80+
### **...**
81+
82+
```
83+
84+
```
85+
86+
<!-- tabs:end -->
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# [2947. 统计美丽子字符串 I](https://leetcode.cn/problems/count-beautiful-substrings-i)
2+
3+
[English Version](/solution/2900-2999/2947.Count%20Beautiful%20Substrings%20I/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你一个字符串 <code>s</code> 和一个正整数 <code>k</code> 。</p>
10+
11+
<p>用 <code>vowels</code> 和 <code>consonants</code> 分别表示字符串中元音字母和辅音字母的数量。</p>
12+
13+
<p>如果某个字符串满足以下条件,则称其为 <strong>美丽字符串</strong> :</p>
14+
15+
<ul>
16+
<li><code>vowels == consonants</code>,即元音字母和辅音字母的数量相等。</li>
17+
<li><code>(vowels * consonants) % k == 0</code>,即元音字母和辅音字母的数量的乘积能被 <code>k</code> 整除。</li>
18+
</ul>
19+
20+
<p>返回字符串 <code>s</code> 中 <strong>非空美丽子字符串</strong> 的数量。</p>
21+
22+
<p>子字符串是字符串中的一个连续字符序列。</p>
23+
24+
<p>英语中的<strong> 元音字母 </strong>为 <code>'a'</code>、<code>'e'</code>、<code>'i'</code>、<code>'o'</code> 和 <code>'u'</code> 。</p>
25+
26+
<p>英语中的<strong> 辅音字母 </strong>为除了元音字母之外的所有字母。</p>
27+
28+
<p>&nbsp;</p>
29+
30+
<p><strong class="example">示例 1:</strong></p>
31+
32+
<pre>
33+
<strong>输入:</strong>s = "baeyh", k = 2
34+
<strong>输出:</strong>2
35+
<strong>解释:</strong>字符串 s 中有 2 个美丽子字符串。
36+
- 子字符串 "b<em><strong>aeyh</strong></em>",vowels = 2(["a","e"]),consonants = 2(["y","h"])。
37+
可以看出字符串 "aeyh" 是美丽字符串,因为 vowels == consonants 且 vowels * consonants % k == 0 。
38+
- 子字符串 "<em><strong>baey</strong></em>h",vowels = 2(["a","e"]),consonants = 2(["b","y"])。
39+
可以看出字符串 "baey" 是美丽字符串,因为 vowels == consonants 且 vowels * consonants % k == 0 。
40+
可以证明字符串 s 中只有 2 个美丽子字符串。
41+
</pre>
42+
43+
<p><strong class="example">示例 2:</strong></p>
44+
45+
<pre>
46+
<strong>输入:</strong>s = "abba", k = 1
47+
<strong>输出:</strong>3
48+
<strong>解释:</strong>字符串 s 中有 3 个美丽子字符串。
49+
- 子字符串 "<strong><em>ab</em></strong>ba",vowels = 1(["a"]),consonants = 1(["b"])。
50+
- 子字符串 "ab<strong><em>ba</em></strong>",vowels = 1(["a"]),consonants = 1(["b"])。
51+
- 子字符串 "<em><strong>abba</strong></em>",vowels = 2(["a","a"]),consonants = 2(["b","b"])。
52+
可以证明字符串 s 中只有 3 个美丽子字符串。
53+
</pre>
54+
55+
<p><strong class="example">示例 3:</strong></p>
56+
57+
<pre>
58+
<strong>输入:</strong>s = "bcdf", k = 1
59+
<strong>输出:</strong>0
60+
<strong>解释:</strong>字符串 s 中没有美丽子字符串。
61+
</pre>
62+
63+
<p>&nbsp;</p>
64+
65+
<p><strong>提示:</strong></p>
66+
67+
<ul>
68+
<li><code>1 &lt;= s.length &lt;= 1000</code></li>
69+
<li><code>1 &lt;= k &lt;= 1000</code></li>
70+
<li><code>s</code> 仅由小写英文字母组成。</li>
71+
</ul>
72+
73+
## 解法
74+
75+
<!-- 这里可写通用的实现逻辑 -->
76+
77+
<!-- tabs:start -->
78+
79+
### **Python3**
80+
81+
<!-- 这里可写当前语言的特殊实现逻辑 -->
82+
83+
```python
84+
85+
```
86+
87+
### **Java**
88+
89+
<!-- 这里可写当前语言的特殊实现逻辑 -->
90+
91+
```java
92+
93+
```
94+
95+
### **C++**
96+
97+
```cpp
98+
99+
```
100+
101+
### **Go**
102+
103+
```go
104+
105+
```
106+
107+
### **...**
108+
109+
```
110+
111+
```
112+
113+
<!-- tabs:end -->

0 commit comments

Comments
 (0)