Skip to content

Commit cc5d541

Browse files
acbinidoocs
andauthored
feat: add biweekly contest 118 (doocs#2015)
--------- Co-authored-by: Doocs Bot <doocs-bot@outlook.com>
1 parent 69c4702 commit cc5d541

File tree

18 files changed

+849
-3
lines changed

18 files changed

+849
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# [2942. 查找包含给定字符的单词](https://leetcode.cn/problems/find-words-containing-character)
2+
3+
[English Version](/solution/2900-2999/2942.Find%20Words%20Containing%20Character/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你一个下标从 <strong>0</strong>&nbsp;开始的字符串数组&nbsp;<code>words</code>&nbsp;和一个字符&nbsp;<code>x</code>&nbsp;。</p>
10+
11+
<p>请你返回一个 <strong>下标数组</strong>&nbsp;,表示下标在数组中对应的单词包含字符 <code>x</code>&nbsp;。</p>
12+
13+
<p><b>注意</b>&nbsp;,返回的数组可以是&nbsp;<strong>任意</strong>&nbsp;顺序。</p>
14+
15+
<p>&nbsp;</p>
16+
17+
<p><strong class="example">示例 1:</strong></p>
18+
19+
<pre>
20+
<b>输入:</b>words = ["leet","code"], x = "e"
21+
<b>输出:</b>[0,1]
22+
<b>解释:</b>"e" 在两个单词中都出现了:"l<em><strong>ee</strong></em>t" 和 "cod<em><strong>e</strong></em>" 。所以我们返回下标 0 和 1 。
23+
</pre>
24+
25+
<p><strong class="example">示例 2:</strong></p>
26+
27+
<pre>
28+
<b>输入:</b>words = ["abc","bcd","aaaa","cbc"], x = "a"
29+
<b>输出:</b>[0,2]
30+
<b>解释:</b>"a" 在 "<em><strong>a</strong></em>bc" 和 "<em><strong>aaaa</strong></em>" 中出现了,所以我们返回下标 0 和 2 。
31+
</pre>
32+
33+
<p><strong class="example">示例 3:</strong></p>
34+
35+
<pre>
36+
<b>输入:</b>words = ["abc","bcd","aaaa","cbc"], x = "z"
37+
<b>输出:</b>[]
38+
<b>解释:</b>"z" 没有在任何单词中出现。所以我们返回空数组。
39+
</pre>
40+
41+
<p>&nbsp;</p>
42+
43+
<p><strong>提示:</strong></p>
44+
45+
<ul>
46+
<li><code>1 &lt;= words.length &lt;= 50</code></li>
47+
<li><code>1 &lt;= words[i].length &lt;= 50</code></li>
48+
<li><code>x</code>&nbsp;是一个小写英文字母。</li>
49+
<li><code>words[i]</code>&nbsp;只包含小写英文字母。</li>
50+
</ul>
51+
52+
## 解法
53+
54+
<!-- 这里可写通用的实现逻辑 -->
55+
56+
<!-- tabs:start -->
57+
58+
### **Python3**
59+
60+
<!-- 这里可写当前语言的特殊实现逻辑 -->
61+
62+
```python
63+
64+
```
65+
66+
### **Java**
67+
68+
<!-- 这里可写当前语言的特殊实现逻辑 -->
69+
70+
```java
71+
72+
```
73+
74+
### **C++**
75+
76+
```cpp
77+
78+
```
79+
80+
### **Go**
81+
82+
```go
83+
84+
```
85+
86+
### **...**
87+
88+
```
89+
90+
```
91+
92+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# [2942. Find Words Containing Character](https://leetcode.com/problems/find-words-containing-character)
2+
3+
[中文文档](/solution/2900-2999/2942.Find%20Words%20Containing%20Character/README.md)
4+
5+
## Description
6+
7+
<p>You are given a <strong>0-indexed</strong> array of strings <code>words</code> and a character <code>x</code>.</p>
8+
9+
<p>Return <em>an <strong>array of indices</strong> representing the words that contain the character </em><code>x</code>.</p>
10+
11+
<p><strong>Note</strong> that the returned array may be in <strong>any</strong> order.</p>
12+
13+
<p>&nbsp;</p>
14+
<p><strong class="example">Example 1:</strong></p>
15+
16+
<pre>
17+
<strong>Input:</strong> words = [&quot;leet&quot;,&quot;code&quot;], x = &quot;e&quot;
18+
<strong>Output:</strong> [0,1]
19+
<strong>Explanation:</strong> &quot;e&quot; occurs in both words: &quot;l<strong><u>ee</u></strong>t&quot;, and &quot;cod<u><strong>e</strong></u>&quot;. Hence, we return indices 0 and 1.
20+
</pre>
21+
22+
<p><strong class="example">Example 2:</strong></p>
23+
24+
<pre>
25+
<strong>Input:</strong> words = [&quot;abc&quot;,&quot;bcd&quot;,&quot;aaaa&quot;,&quot;cbc&quot;], x = &quot;a&quot;
26+
<strong>Output:</strong> [0,2]
27+
<strong>Explanation:</strong> &quot;a&quot; occurs in &quot;<strong><u>a</u></strong>bc&quot;, and &quot;<u><strong>aaaa</strong></u>&quot;. Hence, we return indices 0 and 2.
28+
</pre>
29+
30+
<p><strong class="example">Example 3:</strong></p>
31+
32+
<pre>
33+
<strong>Input:</strong> words = [&quot;abc&quot;,&quot;bcd&quot;,&quot;aaaa&quot;,&quot;cbc&quot;], x = &quot;z&quot;
34+
<strong>Output:</strong> []
35+
<strong>Explanation:</strong> &quot;z&quot; does not occur in any of the words. Hence, we return an empty array.
36+
</pre>
37+
38+
<p>&nbsp;</p>
39+
<p><strong>Constraints:</strong></p>
40+
41+
<ul>
42+
<li><code>1 &lt;= words.length &lt;= 50</code></li>
43+
<li><code>1 &lt;= words[i].length &lt;= 50</code></li>
44+
<li><code>x</code> is a lowercase English letter.</li>
45+
<li><code>words[i]</code> consists only of lowercase English letters.</li>
46+
</ul>
47+
48+
## Solutions
49+
50+
<!-- tabs:start -->
51+
52+
### **Python3**
53+
54+
```python
55+
56+
```
57+
58+
### **Java**
59+
60+
```java
61+
62+
```
63+
64+
### **C++**
65+
66+
```cpp
67+
68+
```
69+
70+
### **Go**
71+
72+
```go
73+
74+
```
75+
76+
### **...**
77+
78+
```
79+
80+
```
81+
82+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# [2943. 最大化网格图中正方形空洞的面积](https://leetcode.cn/problems/maximize-area-of-square-hole-in-grid)
2+
3+
[English Version](/solution/2900-2999/2943.Maximize%20Area%20of%20Square%20Hole%20in%20Grid/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你一个网格图,由&nbsp;<code>n + 2</code>&nbsp;条 <strong>横线段</strong>&nbsp;&nbsp;<code>m + 2</code>&nbsp;&nbsp;<strong>竖线段</strong>&nbsp;组成,一开始所有区域均为&nbsp;<code>1 x 1</code>&nbsp;的单元格。</p>
10+
11+
<p>所有线段的编号从 <strong>1</strong>&nbsp;开始。</p>
12+
13+
<p>给你两个整数&nbsp;<code>n</code> 和&nbsp;<code>m</code>&nbsp;。</p>
14+
15+
<p>同时给你两个整数数组&nbsp;<code>hBars</code> 和&nbsp;<code>vBars</code>&nbsp;。</p>
16+
17+
<ul>
18+
<li><code>hBars</code> 包含区间&nbsp;<code>[2, n + 1]</code>&nbsp;内&nbsp;<strong>互不相同</strong>&nbsp;的横线段编号。</li>
19+
<li><code>vBars</code>&nbsp;包含&nbsp;<code>[2, m + 1]</code>&nbsp;内&nbsp;<strong>互不相同的</strong>&nbsp;竖线段编号。</li>
20+
</ul>
21+
22+
<p>如果满足以下条件之一,你可以 <strong>移除</strong>&nbsp;两个数组中的部分线段:</p>
23+
24+
<ul>
25+
<li>如果移除的是横线段,它必须是&nbsp;<code>hBars</code>&nbsp;中的值。</li>
26+
<li>如果移除的是竖线段,它必须是&nbsp;<code>vBars</code>&nbsp;中的值。</li>
27+
</ul>
28+
29+
<p>请你返回移除一些线段后(<strong>可能不移除任何线段)</strong>,剩余网格图中 <strong>最大正方形</strong>&nbsp;空洞的面积,正方形空洞的意思是正方形 <strong>内部</strong> 不含有任何线段。</p>
30+
31+
<p>&nbsp;</p>
32+
33+
<p><strong class="example">示例 1:</strong></p>
34+
35+
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2900-2999/2943.Maximize%20Area%20of%20Square%20Hole%20in%20Grid/images/screenshot-from-2023-11-05-22-40-25.png" style="width: 411px; height: 220px;" /></p>
36+
37+
<pre>
38+
<b>输入:</b>n = 2, m = 1, hBars = [2,3], vBars = [2]
39+
<b>输出:</b>4
40+
<b>解释:</b>左边的图是一开始的网格图。
41+
横线编号的范围是区间 [1,4] ,竖线编号的范围是区间 [1,3] 。
42+
可以移除的横线段为 [2,3] ,竖线段为 [2] 。
43+
一种得到最大正方形面积的方法是移除横线段 2 和竖线段 2 。
44+
操作后得到的网格图如右图所示。
45+
正方形空洞面积为 4。
46+
无法得到面积大于 4 的正方形空洞。
47+
所以答案为 4 。
48+
</pre>
49+
50+
<p><strong class="example">示例 2:</strong></p>
51+
52+
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2900-2999/2943.Maximize%20Area%20of%20Square%20Hole%20in%20Grid/images/screenshot-from-2023-11-04-17-01-02.png" style="width: 368px; height: 145px;" /></p>
53+
54+
<pre>
55+
<b>输入:</b>n = 1, m = 1, hBars = [2], vBars = [2]
56+
<b>输出:</b>4
57+
<b>解释:</b>左边的图是一开始的网格图。
58+
横线编号的范围是区间 [1,3] ,竖线编号的范围是区间 [1,3] 。
59+
可以移除的横线段为 [2] ,竖线段为 [2] 。
60+
一种得到最大正方形面积的方法是移除横线段 2 和竖线段 2 。
61+
操作后得到的网格图如右图所示。
62+
正方形空洞面积为 4。
63+
无法得到面积大于 4 的正方形空洞。
64+
所以答案为 4 。
65+
</pre>
66+
67+
<p><strong class="example">示例 3:</strong></p>
68+
69+
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2900-2999/2943.Maximize%20Area%20of%20Square%20Hole%20in%20Grid/images/screenshot-from-2023-11-05-22-33-35.png" style="width: 648px; height: 218px;" /></p>
70+
71+
<pre>
72+
<b>输入:</b>n = 2, m = 3, hBars = [2,3], vBars = [2,3,4]
73+
<b>输出:</b>9
74+
<b>解释:</b>左边的图是一开始的网格图。
75+
横线编号的范围是区间 [1,4] ,竖线编号的范围是区间 [1,5] 。
76+
可以移除的横线段为 [2,3] ,竖线段为 [2,3,4] 。
77+
一种得到最大正方形面积的方法是移除横线段 2、3 和竖线段 3、4 。
78+
操作后得到的网格图如右图所示。
79+
正方形空洞面积为 9。
80+
无法得到面积大于 9 的正方形空洞。
81+
所以答案为 9 。
82+
</pre>
83+
84+
<p>&nbsp;</p>
85+
86+
<p><strong>提示:</strong></p>
87+
88+
<ul>
89+
<li><code>1 &lt;= n &lt;= 10<sup>9</sup></code></li>
90+
<li><code>1 &lt;= m &lt;= 10<sup>9</sup></code></li>
91+
<li><code>1 &lt;= hBars.length &lt;= 100</code></li>
92+
<li><code>2 &lt;= hBars[i] &lt;= n + 1</code></li>
93+
<li><code>1 &lt;= vBars.length &lt;= 100</code></li>
94+
<li><code>2 &lt;= vBars[i] &lt;= m + 1</code></li>
95+
<li><code>hBars</code>&nbsp;中的值互不相同。</li>
96+
<li><code>vBars</code> 中的值互不相同。</li>
97+
</ul>
98+
99+
## 解法
100+
101+
<!-- 这里可写通用的实现逻辑 -->
102+
103+
<!-- tabs:start -->
104+
105+
### **Python3**
106+
107+
<!-- 这里可写当前语言的特殊实现逻辑 -->
108+
109+
```python
110+
111+
```
112+
113+
### **Java**
114+
115+
<!-- 这里可写当前语言的特殊实现逻辑 -->
116+
117+
```java
118+
119+
```
120+
121+
### **C++**
122+
123+
```cpp
124+
125+
```
126+
127+
### **Go**
128+
129+
```go
130+
131+
```
132+
133+
### **...**
134+
135+
```
136+
137+
```
138+
139+
<!-- tabs:end -->

0 commit comments

Comments
 (0)