Skip to content

Commit 6cb7d57

Browse files
committed
feat: add solutions to lc problems: No.2072~2076
* No.2072.The Winner University * No.2073.Time Needed to Buy Tickets * No.2074.Reverse Nodes in Even Length Groups * No.2075.Decode the Slanted Ciphertext * No.2076.Process Restricted Friend Requests
1 parent 76e188d commit 6cb7d57

File tree

48 files changed

+2993
-74
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2993
-74
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# [2067. Number of Equal Count Substrings](https://leetcode-cn.com/problems/number-of-equal-count-substrings)
2+
3+
[English Version](/solution/2000-2099/2067.Number%20of%20Equal%20Count%20Substrings/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>You are given a <strong>0-indexed</strong> string <code>s</code> consisting of only lowercase English letters, and an integer <code>count</code>. A <strong>substring</strong> of <code>s</code> is said to be an <strong>equal count substring</strong> if, for each <strong>unique</strong> letter in the substring, it appears exactly <code>count</code> times in the substring.</p>
10+
11+
<p>Return <em>the number of <strong>equal count substrings</strong> in </em><code>s</code>.</p>
12+
13+
<p>A <strong>substring</strong> is a contiguous non-empty sequence of characters within a string.</p>
14+
15+
<p>&nbsp;</p>
16+
<p><strong>Example 1:</strong></p>
17+
18+
<pre>
19+
<strong>Input:</strong> s = &quot;aaabcbbcc&quot;, count = 3
20+
<strong>Output:</strong> 3
21+
<strong>Explanation:</strong>
22+
The substring that starts at index 0 and ends at index 2 is &quot;aaa&quot;.
23+
The letter &#39;a&#39; in the substring appears exactly 3 times.
24+
The substring that starts at index 3 and ends at index 8 is &quot;bcbbcc&quot;.
25+
The letters &#39;b&#39; and &#39;c&#39; in the substring appear exactly 3 times.
26+
The substring that starts at index 0 and ends at index 8 is &quot;aaabcbbcc&quot;.
27+
The letters &#39;a&#39;, &#39;b&#39;, and &#39;c&#39; in the substring appear exactly 3 times.
28+
</pre>
29+
30+
<p><strong>Example 2:</strong></p>
31+
32+
<pre>
33+
<strong>Input:</strong> s = &quot;abcd&quot;, count = 2
34+
<strong>Output:</strong> 0
35+
<strong>Explanation:</strong>
36+
The number of times each letter appears in s is less than count.
37+
Therefore, no substrings in s are equal count substrings, so return 0.
38+
</pre>
39+
40+
<p><strong>Example 3:</strong></p>
41+
42+
<pre>
43+
<strong>Input:</strong> s = &quot;a&quot;, count = 5
44+
<strong>Output:</strong> 0
45+
<strong>Explanation:</strong>
46+
The number of times each letter appears in s is less than count.
47+
Therefore, no substrings in s are equal count substrings, so return 0</pre>
48+
49+
<p>&nbsp;</p>
50+
<p><strong>Constraints:</strong></p>
51+
52+
<ul>
53+
<li><code>1 &lt;= s.length &lt;= 3 * 10<sup>4</sup></code></li>
54+
<li><code>1 &lt;= count &lt;= 3 * 10<sup>4</sup></code></li>
55+
<li><code>s</code> consists only of lowercase English letters.</li>
56+
</ul>
57+
58+
## 解法
59+
60+
<!-- 这里可写通用的实现逻辑 -->
61+
62+
<!-- tabs:start -->
63+
64+
### **Python3**
65+
66+
<!-- 这里可写当前语言的特殊实现逻辑 -->
67+
68+
```python
69+
70+
```
71+
72+
### **Java**
73+
74+
<!-- 这里可写当前语言的特殊实现逻辑 -->
75+
76+
```java
77+
78+
```
79+
80+
### **...**
81+
82+
```
83+
84+
```
85+
86+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# [2067. Number of Equal Count Substrings](https://leetcode.com/problems/number-of-equal-count-substrings)
2+
3+
[中文文档](/solution/2000-2099/2067.Number%20of%20Equal%20Count%20Substrings/README.md)
4+
5+
## Description
6+
7+
<p>You are given a <strong>0-indexed</strong> string <code>s</code> consisting of only lowercase English letters, and an integer <code>count</code>. A <strong>substring</strong> of <code>s</code> is said to be an <strong>equal count substring</strong> if, for each <strong>unique</strong> letter in the substring, it appears exactly <code>count</code> times in the substring.</p>
8+
9+
<p>Return <em>the number of <strong>equal count substrings</strong> in </em><code>s</code>.</p>
10+
11+
<p>A <strong>substring</strong> is a contiguous non-empty sequence of characters within a string.</p>
12+
13+
<p>&nbsp;</p>
14+
<p><strong>Example 1:</strong></p>
15+
16+
<pre>
17+
<strong>Input:</strong> s = &quot;aaabcbbcc&quot;, count = 3
18+
<strong>Output:</strong> 3
19+
<strong>Explanation:</strong>
20+
The substring that starts at index 0 and ends at index 2 is &quot;aaa&quot;.
21+
The letter &#39;a&#39; in the substring appears exactly 3 times.
22+
The substring that starts at index 3 and ends at index 8 is &quot;bcbbcc&quot;.
23+
The letters &#39;b&#39; and &#39;c&#39; in the substring appear exactly 3 times.
24+
The substring that starts at index 0 and ends at index 8 is &quot;aaabcbbcc&quot;.
25+
The letters &#39;a&#39;, &#39;b&#39;, and &#39;c&#39; in the substring appear exactly 3 times.
26+
</pre>
27+
28+
<p><strong>Example 2:</strong></p>
29+
30+
<pre>
31+
<strong>Input:</strong> s = &quot;abcd&quot;, count = 2
32+
<strong>Output:</strong> 0
33+
<strong>Explanation:</strong>
34+
The number of times each letter appears in s is less than count.
35+
Therefore, no substrings in s are equal count substrings, so return 0.
36+
</pre>
37+
38+
<p><strong>Example 3:</strong></p>
39+
40+
<pre>
41+
<strong>Input:</strong> s = &quot;a&quot;, count = 5
42+
<strong>Output:</strong> 0
43+
<strong>Explanation:</strong>
44+
The number of times each letter appears in s is less than count.
45+
Therefore, no substrings in s are equal count substrings, so return 0</pre>
46+
47+
<p>&nbsp;</p>
48+
<p><strong>Constraints:</strong></p>
49+
50+
<ul>
51+
<li><code>1 &lt;= s.length &lt;= 3 * 10<sup>4</sup></code></li>
52+
<li><code>1 &lt;= count &lt;= 3 * 10<sup>4</sup></code></li>
53+
<li><code>s</code> consists only of lowercase English letters.</li>
54+
</ul>
55+
56+
## Solutions
57+
58+
<!-- tabs:start -->
59+
60+
### **Python3**
61+
62+
```python
63+
64+
```
65+
66+
### **Java**
67+
68+
```java
69+
70+
```
71+
72+
### **...**
73+
74+
```
75+
76+
```
77+
78+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# [2068. 检查两个字符串是否几乎相等](https://leetcode-cn.com/problems/check-whether-two-strings-are-almost-equivalent)
2+
3+
[English Version](/solution/2000-2099/2068.Check%20Whether%20Two%20Strings%20are%20Almost%20Equivalent/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>如果两个字符串 <code>word1</code>&nbsp;和 <code>word2</code>&nbsp;中从 <code>'a'</code>&nbsp;到 <code>'z'</code>&nbsp;每一个字母出现频率之差都 <strong>不超过</strong>&nbsp;<code>3</code>&nbsp;,那么我们称这两个字符串&nbsp;<code>word1</code> 和&nbsp;<code>word2</code> <strong>几乎相等</strong>&nbsp;。</p>
10+
11+
<p>给你两个长度都为&nbsp;<code>n</code>&nbsp;的字符串&nbsp;<code>word1</code> 和&nbsp;<code>word2</code>&nbsp;,如果&nbsp;<code>word1</code>&nbsp;&nbsp;<code>word2</code>&nbsp;<strong>几乎相等</strong>&nbsp;,请你返回&nbsp;<code>true</code>&nbsp;,否则返回&nbsp;<code>false</code>&nbsp;。</p>
12+
13+
<p>一个字母 <code>x</code>&nbsp;的出现 <strong>频率</strong>&nbsp;指的是它在字符串中出现的次数。</p>
14+
15+
<p>&nbsp;</p>
16+
17+
<p><strong>示例 1:</strong></p>
18+
19+
<pre><b>输入:</b>word1 = "aaaa", word2 = "bccb"
20+
<b>输出:</b>false
21+
<b>解释:</b>字符串 "aaaa" 中有 4 个 'a' ,但是 "bccb" 中有 0 个 'a' 。
22+
两者之差为 4 ,大于上限 3 。
23+
</pre>
24+
25+
<p><strong>示例 2:</strong></p>
26+
27+
<pre><b>输入:</b>word1 = "abcdeef", word2 = "abaaacc"
28+
<b>输出:</b>true
29+
<b>解释:</b>word1 和 word2 中每个字母出现频率之差至多为 3 :
30+
- 'a' 在 word1 中出现了 1 次,在 word2 中出现了 4 次,差为 3 。
31+
- 'b' 在 word1 中出现了 1 次,在 word2 中出现了 1 次,差为 0 。
32+
- 'c' 在 word1 中出现了 1 次,在 word2 中出现了 2 次,差为 1 。
33+
- 'd' 在 word1 中出现了 1 次,在 word2 中出现了 0 次,差为 1 。
34+
- 'e' 在 word1 中出现了 2 次,在 word2 中出现了 0 次,差为 2 。
35+
- 'f' 在 word1 中出现了 1 次,在 word2 中出现了 0 次,差为 1 。
36+
</pre>
37+
38+
<p><strong>示例 3:</strong></p>
39+
40+
<pre><b>输入:</b>word1 = "cccddabba", word2 = "babababab"
41+
<b>输出:</b>true
42+
<b>解释:</b>word1 和 word2 中每个字母出现频率之差至多为 3 :
43+
- 'a' 在 word1 中出现了 2 次,在 word2 中出现了 4 次,差为 2 。
44+
- 'b' 在 word1 中出现了 2 次,在 word2 中出现了 5 次,差为 3 。
45+
- 'c' 在 word1 中出现了 3 次,在 word2 中出现了 0 次,差为 3 。
46+
- 'd' 在 word1 中出现了 2 次,在 word2 中出现了 0 次,差为 2 。
47+
</pre>
48+
49+
<p>&nbsp;</p>
50+
51+
<p><strong>提示:</strong></p>
52+
53+
<ul>
54+
<li><code>n == word1.length == word2.length</code></li>
55+
<li><code>1 &lt;= n &lt;= 100</code></li>
56+
<li><code>word1</code> 和&nbsp;<code>word2</code>&nbsp;都只包含小写英文字母。</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+
### **...**
82+
83+
```
84+
85+
```
86+
87+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# [2068. Check Whether Two Strings are Almost Equivalent](https://leetcode.com/problems/check-whether-two-strings-are-almost-equivalent)
2+
3+
[中文文档](/solution/2000-2099/2068.Check%20Whether%20Two%20Strings%20are%20Almost%20Equivalent/README.md)
4+
5+
## Description
6+
7+
<p>Two strings <code>word1</code> and <code>word2</code> are considered <strong>almost equivalent</strong> if the differences between the frequencies of each letter from <code>&#39;a&#39;</code> to <code>&#39;z&#39;</code> between <code>word1</code> and <code>word2</code> is <strong>at most</strong> <code>3</code>.</p>
8+
9+
<p>Given two strings <code>word1</code> and <code>word2</code>, each of length <code>n</code>, return <code>true</code> <em>if </em><code>word1</code> <em>and</em> <code>word2</code> <em>are <strong>almost equivalent</strong>, or</em> <code>false</code> <em>otherwise</em>.</p>
10+
11+
<p>The <strong>frequency</strong> of a letter <code>x</code> is the number of times it occurs in the string.</p>
12+
13+
<p>&nbsp;</p>
14+
<p><strong>Example 1:</strong></p>
15+
16+
<pre>
17+
<strong>Input:</strong> word1 = &quot;aaaa&quot;, word2 = &quot;bccb&quot;
18+
<strong>Output:</strong> false
19+
<strong>Explanation:</strong> There are 4 &#39;a&#39;s in &quot;aaaa&quot; but 0 &#39;a&#39;s in &quot;bccb&quot;.
20+
The difference is 4, which is more than the allowed 3.
21+
</pre>
22+
23+
<p><strong>Example 2:</strong></p>
24+
25+
<pre>
26+
<strong>Input:</strong> word1 = &quot;abcdeef&quot;, word2 = &quot;abaaacc&quot;
27+
<strong>Output:</strong> true
28+
<strong>Explanation:</strong> The differences between the frequencies of each letter in word1 and word2 are at most 3:
29+
- &#39;a&#39; appears 1 time in word1 and 4 times in word2. The difference is 3.
30+
- &#39;b&#39; appears 1 time in word1 and 1 time in word2. The difference is 0.
31+
- &#39;c&#39; appears 1 time in word1 and 2 times in word2. The difference is 1.
32+
- &#39;d&#39; appears 1 time in word1 and 0 times in word2. The difference is 1.
33+
- &#39;e&#39; appears 2 times in word1 and 0 times in word2. The difference is 2.
34+
- &#39;f&#39; appears 1 time in word1 and 0 times in word2. The difference is 1.
35+
</pre>
36+
37+
<p><strong>Example 3:</strong></p>
38+
39+
<pre>
40+
<strong>Input:</strong> word1 = &quot;cccddabba&quot;, word2 = &quot;babababab&quot;
41+
<strong>Output:</strong> true
42+
<strong>Explanation:</strong> The differences between the frequencies of each letter in word1 and word2 are at most 3:
43+
- &#39;a&#39; appears 2 times in word1 and 4 times in word2. The difference is 2.
44+
- &#39;b&#39; appears 2 times in word1 and 5 times in word2. The difference is 3.
45+
- &#39;c&#39; appears 3 times in word1 and 0 times in word2. The difference is 3.
46+
- &#39;d&#39; appears 2 times in word1 and 0 times in word2. The difference is 2.
47+
</pre>
48+
49+
<p>&nbsp;</p>
50+
<p><strong>Constraints:</strong></p>
51+
52+
<ul>
53+
<li><code>n == word1.length == word2.length</code></li>
54+
<li><code>1 &lt;= n &lt;= 100</code></li>
55+
<li><code>word1</code> and <code>word2</code> consist only of lowercase English letters.</li>
56+
</ul>
57+
58+
## Solutions
59+
60+
<!-- tabs:start -->
61+
62+
### **Python3**
63+
64+
```python
65+
66+
```
67+
68+
### **Java**
69+
70+
```java
71+
72+
```
73+
74+
### **...**
75+
76+
```
77+
78+
```
79+
80+
<!-- tabs:end -->

0 commit comments

Comments
 (0)