Skip to content

Commit d319912

Browse files
authored
feat: add weekly contest 394 (doocs#2635)
1 parent 70c35e4 commit d319912

File tree

20 files changed

+771
-54
lines changed

20 files changed

+771
-54
lines changed

solution/0000-0099/0030.Substring with Concatenation of All Words/README_EN.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88

99
<p>You are given a string <code>s</code> and an array of strings <code>words</code>. All the strings of <code>words</code> are of <strong>the same length</strong>.</p>
1010

11-
<p>A <strong>concatenated string</strong>&nbsp;is a string that exactly contains all the strings of any permutation of <code>words</code> concatenated.</p>
11+
<p>A <strong>concatenated string</strong> is a string that exactly contains all the strings of any permutation of <code>words</code> concatenated.</p>
1212

1313
<ul>
1414
<li>For example, if <code>words = [&quot;ab&quot;,&quot;cd&quot;,&quot;ef&quot;]</code>, then <code>&quot;abcdef&quot;</code>, <code>&quot;abefcd&quot;</code>, <code>&quot;cdabef&quot;</code>, <code>&quot;cdefab&quot;</code>, <code>&quot;efabcd&quot;</code>, and <code>&quot;efcdab&quot;</code> are all concatenated strings. <code>&quot;acdbef&quot;</code> is not a concatenated string because it is not the concatenation of any permutation of <code>words</code>.</li>
1515
</ul>
1616

17-
<p>Return an array of&nbsp;<em>the starting indices</em> of all the concatenated substrings in<em> </em><code>s</code>. You can return the answer in <strong>any order</strong>.</p>
17+
<p>Return an array of <em>the starting indices</em> of all the concatenated substrings in <code>s</code>. You can return the answer in <strong>any order</strong>.</p>
1818

1919
<p>&nbsp;</p>
2020
<p><strong class="example">Example 1:</strong></p>
@@ -27,8 +27,7 @@
2727
<p><strong>Explanation:</strong></p>
2828

2929
<p>The substring starting at 0 is <code>&quot;barfoo&quot;</code>. It is the concatenation of <code>[&quot;bar&quot;,&quot;foo&quot;]</code> which is a permutation of <code>words</code>.<br />
30-
The substring starting at 9 is <code>&quot;foobar&quot;</code>. It is the concatenation of <code>[&quot;foo&quot;,&quot;bar&quot;]</code> which is a permutation of <code>words</code>.<br />
31-
The output order does not matter. Returning <code>[9,0]</code> is fine too.</p>
30+
The substring starting at 9 is <code>&quot;foobar&quot;</code>. It is the concatenation of <code>[&quot;foo&quot;,&quot;bar&quot;]</code> which is a permutation of <code>words</code>.</p>
3231
</div>
3332

3433
<p><strong class="example">Example 2:</strong></p>

solution/2800-2899/2865.Beautiful Towers I/README_EN.md

+29-41
Original file line numberDiff line numberDiff line change
@@ -6,65 +6,53 @@
66

77
## Description
88

9-
<p>You are given a <strong>0-indexed</strong> array <code>maxHeights</code> of <code>n</code> integers.</p>
9+
<p>You are given an array <code>heights</code> of <code>n</code> integers representing the number of bricks in <code>n</code> consecutive towers. Your task is to remove some bricks to form a <strong>mountain-shaped</strong> tower arrangement. In this arrangement, the tower heights are non-decreasing, reaching a maximum peak value with one or multiple consecutive towers and then non-increasing.</p>
1010

11-
<p>You are tasked with building <code>n</code> towers in the coordinate line. The <code>i<sup>th</sup></code> tower is built at coordinate <code>i</code> and has a height of <code>heights[i]</code>.</p>
11+
<p>Return the <strong>maximum possible sum</strong> of heights of a mountain-shaped tower arrangement.</p>
1212

13-
<p>A configuration of towers is <strong>beautiful</strong> if the following conditions hold:</p>
13+
<p>&nbsp;</p>
14+
<p><strong class="example">Example 1:</strong></p>
1415

15-
<ol>
16-
<li><code>1 &lt;= heights[i] &lt;= maxHeights[i]</code></li>
17-
<li><code>heights</code> is a <strong>mountain</strong> array.</li>
18-
</ol>
16+
<div class="example-block">
17+
<p><strong>Input:</strong> <span class="example-io">heights = [5,3,4,1,1]</span></p>
1918

20-
<p>Array <code>heights</code> is a <strong>mountain</strong> if there exists an index <code>i</code> such that:</p>
19+
<p><strong>Output:</strong> <span class="example-io">13</span></p>
2120

22-
<ul>
23-
<li>For all <code>0 &lt; j &lt;= i</code>, <code>heights[j - 1] &lt;= heights[j]</code></li>
24-
<li>For all <code>i &lt;= k &lt; n - 1</code>, <code>heights[k + 1] &lt;= heights[k]</code></li>
25-
</ul>
21+
<p><strong>Explanation:</strong></p>
2622

27-
<p>Return <em>the <strong>maximum possible sum of heights</strong> of a beautiful configuration of towers</em>.</p>
23+
<p>We remove some bricks to make <code>heights =&nbsp;[5,3,3,1,1]</code>, the peak is at index 0.</p>
24+
</div>
2825

29-
<p>&nbsp;</p>
30-
<p><strong class="example">Example 1:</strong></p>
26+
<p><strong class="example">Example 2:</strong></p>
3127

32-
<pre>
33-
<strong>Input:</strong> maxHeights = [5,3,4,1,1]
34-
<strong>Output:</strong> 13
35-
<strong>Explanation:</strong> One beautiful configuration with a maximum sum is heights = [5,3,3,1,1]. This configuration is beautiful since:
36-
- 1 &lt;= heights[i] &lt;= maxHeights[i]
37-
- heights is a mountain of peak i = 0.
38-
It can be shown that there exists no other beautiful configuration with a sum of heights greater than 13.</pre>
28+
<div class="example-block">
29+
<p><strong>Input:</strong> <span class="example-io">heights = [6,5,3,9,2,7]</span></p>
3930

40-
<p><strong class="example">Example 2:</strong></p>
31+
<p><strong>Output:</strong> <span class="example-io">22</span></p>
32+
33+
<p><strong>Explanation:</strong></p>
4134

42-
<pre>
43-
<strong>Input:</strong> maxHeights = [6,5,3,9,2,7]
44-
<strong>Output:</strong> 22
45-
<strong>Explanation:</strong> One beautiful configuration with a maximum sum is heights = [3,3,3,9,2,2]. This configuration is beautiful since:
46-
- 1 &lt;= heights[i] &lt;= maxHeights[i]
47-
- heights is a mountain of peak i = 3.
48-
It can be shown that there exists no other beautiful configuration with a sum of heights greater than 22.</pre>
35+
<p>We remove some bricks to make <code>heights =&nbsp;[3,3,3,9,2,2]</code>, the peak is at index 3.</p>
36+
</div>
4937

5038
<p><strong class="example">Example 3:</strong></p>
5139

52-
<pre>
53-
<strong>Input:</strong> maxHeights = [3,2,5,5,2,3]
54-
<strong>Output:</strong> 18
55-
<strong>Explanation:</strong> One beautiful configuration with a maximum sum is heights = [2,2,5,5,2,2]. This configuration is beautiful since:
56-
- 1 &lt;= heights[i] &lt;= maxHeights[i]
57-
- heights is a mountain of peak i = 2.
58-
Note that, for this configuration, i = 3 can also be considered a peak.
59-
It can be shown that there exists no other beautiful configuration with a sum of heights greater than 18.
60-
</pre>
40+
<div class="example-block">
41+
<p><strong>Input:</strong> <span class="example-io">heights = [3,2,5,5,2,3]</span></p>
42+
43+
<p><strong>Output:</strong> <span class="example-io">18</span></p>
44+
45+
<p><strong>Explanation:</strong></p>
46+
47+
<p>We remove some bricks to make <code>heights = [2,2,5,5,2,2]</code>, the peak is at index 2 or 3.</p>
48+
</div>
6149

6250
<p>&nbsp;</p>
6351
<p><strong>Constraints:</strong></p>
6452

6553
<ul>
66-
<li><code>1 &lt;= n == maxHeights &lt;= 10<sup>3</sup></code></li>
67-
<li><code>1 &lt;= maxHeights[i] &lt;= 10<sup>9</sup></code></li>
54+
<li><code>1 &lt;= n == heights &lt;= 10<sup>3</sup></code></li>
55+
<li><code>1 &lt;= heights[i] &lt;= 10<sup>9</sup></code></li>
6856
</ul>
6957

7058
## Solutions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# [3120. 统计特殊字母的数量 I](https://leetcode.cn/problems/count-the-number-of-special-characters-i)
2+
3+
[English Version](/solution/3100-3199/3120.Count%20the%20Number%20of%20Special%20Characters%20I/README_EN.md)
4+
5+
<!-- tags: -->
6+
7+
## 题目描述
8+
9+
<!-- 这里写题目描述 -->
10+
11+
<p>给你一个字符串 <code>word</code>。如果 <code>word</code> 中同时存在某个字母的小写形式和大写形式,则称这个字母为 <strong>特殊字母</strong> 。</p>
12+
13+
<p>返回 <code>word</code> 中<strong> </strong><strong>特殊字母 </strong>的数量。</p>
14+
15+
<p>&nbsp;</p>
16+
17+
<p><strong class="example">示例 1:</strong></p>
18+
19+
<div class="example-block">
20+
<p><strong>输入:</strong><span class="example-io">word = "aaAbcBC"</span></p>
21+
22+
<p><strong>输出:</strong><span class="example-io">3</span></p>
23+
24+
<p><strong>解释:</strong></p>
25+
26+
<p><code>word</code> 中的特殊字母是 <code>'a'</code>、<code>'b'</code> 和 <code>'c'</code>。</p>
27+
</div>
28+
29+
<p><strong class="example">示例 2:</strong></p>
30+
31+
<div class="example-block">
32+
<p><strong>输入:</strong><span class="example-io">word = "abc"</span></p>
33+
34+
<p><strong>输出:</strong><span class="example-io">0</span></p>
35+
36+
<p><strong>解释:</strong></p>
37+
38+
<p><code>word</code> 中不存在大小写形式同时出现的字母。</p>
39+
</div>
40+
41+
<p><strong class="example">示例 3:</strong></p>
42+
43+
<div class="example-block">
44+
<p><strong>输入:</strong><span class="example-io">word = "abBCab"</span></p>
45+
46+
<p><strong>输出:</strong>1</p>
47+
48+
<p><strong>解释:</strong></p>
49+
50+
<p><code>word</code> 中唯一的特殊字母是 <code>'b'</code>。</p>
51+
</div>
52+
53+
<p>&nbsp;</p>
54+
55+
<p><strong>提示:</strong></p>
56+
57+
<ul>
58+
<li><code>1 &lt;= word.length &lt;= 50</code></li>
59+
<li><code>word</code> 仅由小写和大写英文字母组成。</li>
60+
</ul>
61+
62+
## 解法
63+
64+
### 方法一
65+
66+
<!-- tabs:start -->
67+
68+
```python
69+
70+
```
71+
72+
```java
73+
74+
```
75+
76+
```cpp
77+
78+
```
79+
80+
```go
81+
82+
```
83+
84+
<!-- tabs:end -->
85+
86+
<!-- end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# [3120. Count the Number of Special Characters I](https://leetcode.com/problems/count-the-number-of-special-characters-i)
2+
3+
[中文文档](/solution/3100-3199/3120.Count%20the%20Number%20of%20Special%20Characters%20I/README.md)
4+
5+
<!-- tags: -->
6+
7+
## Description
8+
9+
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p>
10+
11+
<p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p>
12+
13+
<p>&nbsp;</p>
14+
<p><strong class="example">Example 1:</strong></p>
15+
16+
<div class="example-block">
17+
<p><strong>Input:</strong> <span class="example-io">word = &quot;aaAbcBC&quot;</span></p>
18+
19+
<p><strong>Output:</strong> <span class="example-io">3</span></p>
20+
21+
<p><strong>Explanation:</strong></p>
22+
23+
<p>The special characters in <code>word</code> are <code>&#39;a&#39;</code>, <code>&#39;b&#39;</code>, and <code>&#39;c&#39;</code>.</p>
24+
</div>
25+
26+
<p><strong class="example">Example 2:</strong></p>
27+
28+
<div class="example-block">
29+
<p><strong>Input:</strong> <span class="example-io">word = &quot;abc&quot;</span></p>
30+
31+
<p><strong>Output:</strong> <span class="example-io">0</span></p>
32+
33+
<p><strong>Explanation:</strong></p>
34+
35+
<p>No character in <code>word</code> appears in uppercase.</p>
36+
</div>
37+
38+
<p><strong class="example">Example 3:</strong></p>
39+
40+
<div class="example-block">
41+
<p><strong>Input:</strong> <span class="example-io">word = &quot;abBCab&quot;</span></p>
42+
43+
<p><strong>Output:</strong> 1</p>
44+
45+
<p><strong>Explanation:</strong></p>
46+
47+
<p>The only special character in <code>word</code> is <code>&#39;b&#39;</code>.</p>
48+
</div>
49+
50+
<p>&nbsp;</p>
51+
<p><strong>Constraints:</strong></p>
52+
53+
<ul>
54+
<li><code>1 &lt;= word.length &lt;= 50</code></li>
55+
<li><code>word</code> consists of only lowercase and uppercase English letters.</li>
56+
</ul>
57+
58+
## Solutions
59+
60+
### Solution 1
61+
62+
<!-- tabs:start -->
63+
64+
```python
65+
66+
```
67+
68+
```java
69+
70+
```
71+
72+
```cpp
73+
74+
```
75+
76+
```go
77+
78+
```
79+
80+
<!-- tabs:end -->
81+
82+
<!-- end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# [3121. 统计特殊字母的数量 II](https://leetcode.cn/problems/count-the-number-of-special-characters-ii)
2+
3+
[English Version](/solution/3100-3199/3121.Count%20the%20Number%20of%20Special%20Characters%20II/README_EN.md)
4+
5+
<!-- tags: -->
6+
7+
## 题目描述
8+
9+
<!-- 这里写题目描述 -->
10+
11+
<p>给你一个字符串 <code>word</code>。如果 <code>word</code> 中同时出现某个字母 <code>c</code> 的小写形式和大写形式,并且<strong> 每个 </strong>小写形式的 <code>c</code> 都出现在第一个大写形式的 <code>c</code> 之前,则称字母 <code>c</code> 是一个 <strong>特殊字母</strong> 。</p>
12+
13+
<p>返回 <code>word</code> 中 <strong>特殊字母</strong> 的数量。</p>
14+
15+
<p>&nbsp;</p>
16+
17+
<p><strong class="example">示例 1:</strong></p>
18+
19+
<div class="example-block">
20+
<p><strong>输入:</strong><span class="example-io">word = "aaAbcBC"</span></p>
21+
22+
<p><strong>输出:</strong><span class="example-io">3</span></p>
23+
24+
<p><strong>解释:</strong></p>
25+
26+
<p>特殊字母是 <code>'a'</code>、<code>'b'</code> 和 <code>'c'</code>。</p>
27+
</div>
28+
29+
<p><strong class="example">示例 2:</strong></p>
30+
31+
<div class="example-block">
32+
<p><strong>输入:</strong><span class="example-io">word = "abc"</span></p>
33+
34+
<p><strong>输出:</strong><span class="example-io">0</span></p>
35+
36+
<p><strong>解释:</strong></p>
37+
38+
<p><code>word</code> 中不存在特殊字母。</p>
39+
</div>
40+
41+
<p><strong class="example">示例 3:</strong></p>
42+
43+
<div class="example-block">
44+
<p><strong>输入:</strong><span class="example-io">word = "AbBCab"</span></p>
45+
46+
<p><strong>输出:</strong><span class="example-io">0</span></p>
47+
48+
<p><strong>解释:</strong></p>
49+
50+
<p><code>word</code> 中不存在特殊字母。</p>
51+
</div>
52+
53+
<p>&nbsp;</p>
54+
55+
<p><strong>提示:</strong></p>
56+
57+
<ul>
58+
<li><code>1 &lt;= word.length &lt;= 2 * 10<sup>5</sup></code></li>
59+
<li><code>word</code> 仅由小写和大写英文字母组成。</li>
60+
</ul>
61+
62+
## 解法
63+
64+
### 方法一
65+
66+
<!-- tabs:start -->
67+
68+
```python
69+
70+
```
71+
72+
```java
73+
74+
```
75+
76+
```cpp
77+
78+
```
79+
80+
```go
81+
82+
```
83+
84+
<!-- tabs:end -->
85+
86+
<!-- end -->

0 commit comments

Comments
 (0)