Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8c4f972

Browse files
authored
feat: add weekly contest 380 (doocs#2215)
1 parent 4f92772 commit 8c4f972

File tree

14 files changed

+750
-0
lines changed

14 files changed

+750
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# [3005. 最大频率元素计数](https://leetcode.cn/problems/count-elements-with-maximum-frequency)
2+
3+
[English Version](/solution/3000-3099/3005.Count%20Elements%20With%20Maximum%20Frequency/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你一个由 <strong>正整数 </strong>组成的数组 <code>nums</code> 。</p>
10+
11+
<p>返回数组 <code>nums</code> 中所有具有 <strong>最大 </strong>频率的元素的 <strong>总频率 </strong>。</p>
12+
13+
<p>元素的 <strong>频率 </strong>是指该元素在数组中出现的次数。</p>
14+
15+
<p>&nbsp;</p>
16+
17+
<p><strong class="example">示例 1:</strong></p>
18+
19+
<pre>
20+
<strong>输入:</strong>nums = [1,2,2,3,1,4]
21+
<strong>输出:</strong>4
22+
<strong>解释:</strong>元素 1 和 2 的频率为 2 ,是数组中的最大频率。
23+
因此具有最大频率的元素在数组中的数量是 4 。
24+
</pre>
25+
26+
<p><strong class="example">示例 2:</strong></p>
27+
28+
<pre>
29+
<strong>输入:</strong>nums = [1,2,3,4,5]
30+
<strong>输出:</strong>5
31+
<strong>解释:</strong>数组中的所有元素的频率都为 1 ,是最大频率。
32+
因此具有最大频率的元素在数组中的数量是 5 。
33+
</pre>
34+
35+
<p>&nbsp;</p>
36+
37+
<p><strong>提示:</strong></p>
38+
39+
<ul>
40+
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
41+
<li><code>1 &lt;= nums[i] &lt;= 100</code></li>
42+
</ul>
43+
44+
## 解法
45+
46+
<!-- 这里可写通用的实现逻辑 -->
47+
48+
<!-- tabs:start -->
49+
50+
### **Python3**
51+
52+
<!-- 这里可写当前语言的特殊实现逻辑 -->
53+
54+
```python
55+
56+
```
57+
58+
### **Java**
59+
60+
<!-- 这里可写当前语言的特殊实现逻辑 -->
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 -->
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# [3005. Count Elements With Maximum Frequency](https://leetcode.com/problems/count-elements-with-maximum-frequency)
2+
3+
[中文文档](/solution/3000-3099/3005.Count%20Elements%20With%20Maximum%20Frequency/README.md)
4+
5+
## Description
6+
7+
<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers.</p>
8+
9+
<p>Return <em>the <strong>total frequencies</strong> of elements in</em><em> </em><code>nums</code>&nbsp;<em>such that those elements all have the <strong>maximum</strong> frequency</em>.</p>
10+
11+
<p>The <strong>frequency</strong> of an element is the number of occurrences of that element in the array.</p>
12+
13+
<p>&nbsp;</p>
14+
<p><strong class="example">Example 1:</strong></p>
15+
16+
<pre>
17+
<strong>Input:</strong> nums = [1,2,2,3,1,4]
18+
<strong>Output:</strong> 4
19+
<strong>Explanation:</strong> The elements 1 and 2 have a frequency of 2 which is the maximum frequency in the array.
20+
So the number of elements in the array with maximum frequency is 4.
21+
</pre>
22+
23+
<p><strong class="example">Example 2:</strong></p>
24+
25+
<pre>
26+
<strong>Input:</strong> nums = [1,2,3,4,5]
27+
<strong>Output:</strong> 5
28+
<strong>Explanation:</strong> All elements of the array have a frequency of 1 which is the maximum.
29+
So the number of elements in the array with maximum frequency is 5.
30+
</pre>
31+
32+
<p>&nbsp;</p>
33+
<p><strong>Constraints:</strong></p>
34+
35+
<ul>
36+
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
37+
<li><code>1 &lt;= nums[i] &lt;= 100</code></li>
38+
</ul>
39+
40+
## Solutions
41+
42+
<!-- tabs:start -->
43+
44+
### **Python3**
45+
46+
```python
47+
48+
```
49+
50+
### **Java**
51+
52+
```java
53+
54+
```
55+
56+
### **C++**
57+
58+
```cpp
59+
60+
```
61+
62+
### **Go**
63+
64+
```go
65+
66+
```
67+
68+
### **...**
69+
70+
```
71+
72+
```
73+
74+
<!-- tabs:end -->
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# [3006. 找出数组中的美丽下标 I](https://leetcode.cn/problems/find-beautiful-indices-in-the-given-array-i)
2+
3+
[English Version](/solution/3000-3099/3006.Find%20Beautiful%20Indices%20in%20the%20Given%20Array%20I/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你一个下标从 <strong>0</strong> 开始的字符串 <code>s</code> 、字符串 <code>a</code> 、字符串 <code>b</code> 和一个整数 <code>k</code> 。</p>
10+
11+
<p>如果下标 <code>i</code> 满足以下条件,则认为它是一个 <strong>美丽下标</strong>:</p>
12+
13+
<ul>
14+
<li><code>0 &lt;= i &lt;= s.length - a.length</code></li>
15+
<li><code>s[i..(i + a.length - 1)] == a</code></li>
16+
<li>存在下标 <code>j</code> 使得:
17+
<ul>
18+
<li><code>0 &lt;= j &lt;= s.length - b.length</code></li>
19+
<li><code>s[j..(j + b.length - 1)] == b</code></li>
20+
<li><code>|j - i| &lt;= k</code></li>
21+
</ul>
22+
</li>
23+
</ul>
24+
25+
<p>以数组形式按<strong> 从小到大排序 </strong>返回美丽下标。</p>
26+
27+
<p>&nbsp;</p>
28+
29+
<p><strong class="example">示例 1:</strong></p>
30+
31+
<pre>
32+
<strong>输入:</strong>s = "isawsquirrelnearmysquirrelhouseohmy", a = "my", b = "squirrel", k = 15
33+
<strong>输出:</strong>[16,33]
34+
<strong>解释:</strong>存在 2 个美丽下标:[16,33]。
35+
- 下标 16 是美丽下标,因为 s[16..17] == "my" ,且存在下标 4 ,满足 s[4..11] == "squirrel" 且 |16 - 4| &lt;= 15 。
36+
- 下标 33 是美丽下标,因为 s[33..34] == "my" ,且存在下标 18 ,满足 s[18..25] == "squirrel" 且 |33 - 18| &lt;= 15 。
37+
因此返回 [16,33] 作为结果。
38+
</pre>
39+
40+
<p><strong class="example">示例 2:</strong></p>
41+
42+
<pre>
43+
<strong>输入:</strong>s = "abcd", a = "a", b = "a", k = 4
44+
<strong>输出:</strong>[0]
45+
<strong>解释:</strong>存在 1 个美丽下标:[0]。
46+
- 下标 0 是美丽下标,因为 s[0..0] == "a" ,且存在下标 0 ,满足 s[0..0] == "a" 且 |0 - 0| &lt;= 4 。
47+
因此返回 [0] 作为结果。
48+
</pre>
49+
50+
<p>&nbsp;</p>
51+
52+
<p><strong>提示:</strong></p>
53+
54+
<ul>
55+
<li><code>1 &lt;= k &lt;= s.length &lt;= 10<sup>5</sup></code></li>
56+
<li><code>1 &lt;= a.length, b.length &lt;= 10</code></li>
57+
<li><code>s</code>、<code>a</code>、和 <code>b</code> 只包含小写英文字母。</li>
58+
</ul>
59+
60+
## 解法
61+
62+
<!-- 这里可写通用的实现逻辑 -->
63+
64+
<!-- tabs:start -->
65+
66+
### **Python3**
67+
68+
<!-- 这里可写当前语言的特殊实现逻辑 -->
69+
70+
```python
71+
72+
```
73+
74+
### **Java**
75+
76+
<!-- 这里可写当前语言的特殊实现逻辑 -->
77+
78+
```java
79+
80+
```
81+
82+
### **C++**
83+
84+
```cpp
85+
86+
```
87+
88+
### **Go**
89+
90+
```go
91+
92+
```
93+
94+
### **...**
95+
96+
```
97+
98+
```
99+
100+
<!-- tabs:end -->
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# [3006. Find Beautiful Indices in the Given Array I](https://leetcode.com/problems/find-beautiful-indices-in-the-given-array-i)
2+
3+
[中文文档](/solution/3000-3099/3006.Find%20Beautiful%20Indices%20in%20the%20Given%20Array%20I/README.md)
4+
5+
## Description
6+
7+
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p>
8+
9+
<p>An index <code>i</code> is <strong>beautiful</strong> if:</p>
10+
11+
<ul>
12+
<li><code>0 &lt;= i &lt;= s.length - a.length</code></li>
13+
<li><code>s[i..(i + a.length - 1)] == a</code></li>
14+
<li>There exists an index <code>j</code> such that:
15+
<ul>
16+
<li><code>0 &lt;= j &lt;= s.length - b.length</code></li>
17+
<li><code>s[j..(j + b.length - 1)] == b</code></li>
18+
<li><code>|j - i| &lt;= k</code></li>
19+
</ul>
20+
</li>
21+
</ul>
22+
23+
<p>Return <em>the array that contains beautiful indices in <strong>sorted order from smallest to largest</strong></em>.</p>
24+
25+
<p>&nbsp;</p>
26+
<p><strong class="example">Example 1:</strong></p>
27+
28+
<pre>
29+
<strong>Input:</strong> s = &quot;isawsquirrelnearmysquirrelhouseohmy&quot;, a = &quot;my&quot;, b = &quot;squirrel&quot;, k = 15
30+
<strong>Output:</strong> [16,33]
31+
<strong>Explanation:</strong> There are 2 beautiful indices: [16,33].
32+
- The index 16 is beautiful as s[16..17] == &quot;my&quot; and there exists an index 4 with s[4..11] == &quot;squirrel&quot; and |16 - 4| &lt;= 15.
33+
- The index 33 is beautiful as s[33..34] == &quot;my&quot; and there exists an index 18 with s[18..25] == &quot;squirrel&quot; and |33 - 18| &lt;= 15.
34+
Thus we return [16,33] as the result.
35+
</pre>
36+
37+
<p><strong class="example">Example 2:</strong></p>
38+
39+
<pre>
40+
<strong>Input:</strong> s = &quot;abcd&quot;, a = &quot;a&quot;, b = &quot;a&quot;, k = 4
41+
<strong>Output:</strong> [0]
42+
<strong>Explanation:</strong> There is 1 beautiful index: [0].
43+
- The index 0 is beautiful as s[0..0] == &quot;a&quot; and there exists an index 0 with s[0..0] == &quot;a&quot; and |0 - 0| &lt;= 4.
44+
Thus we return [0] as the result.
45+
</pre>
46+
47+
<p>&nbsp;</p>
48+
<p><strong>Constraints:</strong></p>
49+
50+
<ul>
51+
<li><code>1 &lt;= k &lt;= s.length &lt;= 10<sup>5</sup></code></li>
52+
<li><code>1 &lt;= a.length, b.length &lt;= 10</code></li>
53+
<li><code>s</code>, <code>a</code>, and <code>b</code> contain only 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+
### **C++**
73+
74+
```cpp
75+
76+
```
77+
78+
### **Go**
79+
80+
```go
81+
82+
```
83+
84+
### **...**
85+
86+
```
87+
88+
```
89+
90+
<!-- tabs:end -->

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /