Skip to content

Commit bea91cb

Browse files
authored
feat: add new lc problems (doocs#2263)
1 parent f57c9b9 commit bea91cb

File tree

5 files changed

+206
-1
lines changed

5 files changed

+206
-1
lines changed

main.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,12 @@ def get_paths(dirs: str, m: int):
149149
break
150150
j = content.find(end)
151151
codes = content[i + len(start) : j].strip()
152-
res = re.findall(r"```(.+?)\n(.+?)\n```", codes, re.DOTALL)
152+
res = re.findall(r"```(.*?)\n(.*?)\n```", codes, re.S)
153153
result = []
154154
if res:
155155
for lang, code in res:
156156
name = mapping.get(lang)
157+
code = code or ''
157158
# 需要将 code 缩进 4 个空格
158159
code = code.replace("\n", "\n ")
159160
code_snippet = (
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# [3018. Maximum Number of Removal Queries That Can Be Processed I](https://leetcode.cn/problems/maximum-number-of-removal-queries-that-can-be-processed-i)
2+
3+
[English Version](/solution/3000-3099/3018.Maximum%20Number%20of%20Removal%20Queries%20That%20Can%20Be%20Processed%20I/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> and a <strong>0-indexed</strong> array <code>queries</code>.</p>
10+
11+
<p>You can do the following operation at the beginning <strong>at most once</strong>:</p>
12+
13+
<ul>
14+
<li>Replace <code>nums</code> with a <span data-keyword="subsequence-array">subsequence</span> of <code>nums</code>.</li>
15+
</ul>
16+
17+
<p>We start processing queries in the given order; for each query, we do the following:</p>
18+
19+
<ul>
20+
<li>If the first <strong>and</strong> the last element of <code>nums</code> is <strong>less than</strong> <code>queries[i]</code>, the processing of queries <strong>ends</strong>.</li>
21+
<li>Otherwise, we choose either the first <strong>or</strong> the last element of <code>nums</code> if it is <strong>greater than or equal to</strong> <code>queries[i]</code>, and we <strong>remove</strong> the chosen element from <code>nums</code>.</li>
22+
</ul>
23+
24+
<p>Return <em>the <strong>maximum</strong> number of queries that can be processed by doing the operation optimally.</em></p>
25+
26+
<p>&nbsp;</p>
27+
<p><strong class="example">Example 1:</strong></p>
28+
29+
<pre>
30+
<strong>Input:</strong> nums = [1,2,3,4,5], queries = [1,2,3,4,6]
31+
<strong>Output:</strong> 4
32+
<strong>Explanation:</strong> We don&#39;t do any operation and process the queries as follows:
33+
1- We choose and remove nums[0] since 1 &lt;= 1, then nums becomes [2,3,4,5].
34+
2- We choose and remove nums[0] since 2 &lt;= 2, then nums becomes [3,4,5].
35+
3- We choose and remove nums[0] since 3 &lt;= 3, then nums becomes [4,5].
36+
4- We choose and remove nums[0] since 4 &lt;= 4, then nums becomes [5].
37+
5- We can not choose any elements from nums since they are not greater than or equal to 5.
38+
Hence, the answer is 4.
39+
It can be shown that we can&#39;t process more than 4 queries.
40+
</pre>
41+
42+
<p><strong class="example">Example 2:</strong></p>
43+
44+
<pre>
45+
<strong>Input:</strong> nums = [2,3,2], queries = [2,2,3]
46+
<strong>Output:</strong> 3
47+
<strong>Explanation:</strong> We don&#39;t do any operation and process the queries as follows:
48+
1- We choose and remove nums[0] since 2 &lt;= 2, then nums becomes [3,2].
49+
2- We choose and remove nums[1] since 2 &lt;= 2, then nums becomes [3].
50+
3- We choose and remove nums[0] since 3 &lt;= 3, then nums becomes [].
51+
Hence, the answer is 3.
52+
It can be shown that we can&#39;t process more than 3 queries.
53+
</pre>
54+
55+
<p><strong class="example">Example 3:</strong></p>
56+
57+
<pre>
58+
<strong>Input:</strong> nums = [3,4,3], queries = [4,3,2]
59+
<strong>Output:</strong> 2
60+
<strong>Explanation:</strong> First we replace nums with the subsequence of nums [4,3].
61+
Then we can process the queries as follows:
62+
1- We choose and remove nums[0] since 4 &lt;= 4, then nums becomes [3].
63+
2- We choose and remove nums[0] since 3 &lt;= 3, then nums becomes [].
64+
3- We can not process any more queries since nums is empty.
65+
Hence, the answer is 2.
66+
It can be shown that we can&#39;t process more than 2 queries.
67+
</pre>
68+
69+
<p>&nbsp;</p>
70+
<p><strong>Constraints:</strong></p>
71+
72+
<ul>
73+
<li><code>1 &lt;= nums.length &lt;= 1000</code></li>
74+
<li><code>1 &lt;= queries.length &lt;= 1000</code></li>
75+
<li><code>1 &lt;= nums[i], queries[i] &lt;= 10<sup>9</sup></code></li>
76+
</ul>
77+
78+
## 解法
79+
80+
### 方法一
81+
82+
<!-- tabs:start -->
83+
84+
```python
85+
86+
```
87+
88+
```java
89+
90+
```
91+
92+
```cpp
93+
94+
```
95+
96+
```go
97+
98+
```
99+
100+
<!-- tabs:end -->
101+
102+
<!-- end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# [3018. Maximum Number of Removal Queries That Can Be Processed I](https://leetcode.com/problems/maximum-number-of-removal-queries-that-can-be-processed-i)
2+
3+
[中文文档](/solution/3000-3099/3018.Maximum%20Number%20of%20Removal%20Queries%20That%20Can%20Be%20Processed%20I/README.md)
4+
5+
## Description
6+
7+
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> and a <strong>0-indexed</strong> array <code>queries</code>.</p>
8+
9+
<p>You can do the following operation at the beginning <strong>at most once</strong>:</p>
10+
11+
<ul>
12+
<li>Replace <code>nums</code> with a <span data-keyword="subsequence-array">subsequence</span> of <code>nums</code>.</li>
13+
</ul>
14+
15+
<p>We start processing queries in the given order; for each query, we do the following:</p>
16+
17+
<ul>
18+
<li>If the first <strong>and</strong> the last element of <code>nums</code> is <strong>less than</strong> <code>queries[i]</code>, the processing of queries <strong>ends</strong>.</li>
19+
<li>Otherwise, we choose either the first <strong>or</strong> the last element of <code>nums</code> if it is <strong>greater than or equal to</strong> <code>queries[i]</code>, and we <strong>remove</strong> the chosen element from <code>nums</code>.</li>
20+
</ul>
21+
22+
<p>Return <em>the <strong>maximum</strong> number of queries that can be processed by doing the operation optimally.</em></p>
23+
24+
<p>&nbsp;</p>
25+
<p><strong class="example">Example 1:</strong></p>
26+
27+
<pre>
28+
<strong>Input:</strong> nums = [1,2,3,4,5], queries = [1,2,3,4,6]
29+
<strong>Output:</strong> 4
30+
<strong>Explanation:</strong> We don&#39;t do any operation and process the queries as follows:
31+
1- We choose and remove nums[0] since 1 &lt;= 1, then nums becomes [2,3,4,5].
32+
2- We choose and remove nums[0] since 2 &lt;= 2, then nums becomes [3,4,5].
33+
3- We choose and remove nums[0] since 3 &lt;= 3, then nums becomes [4,5].
34+
4- We choose and remove nums[0] since 4 &lt;= 4, then nums becomes [5].
35+
5- We can not choose any elements from nums since they are not greater than or equal to 5.
36+
Hence, the answer is 4.
37+
It can be shown that we can&#39;t process more than 4 queries.
38+
</pre>
39+
40+
<p><strong class="example">Example 2:</strong></p>
41+
42+
<pre>
43+
<strong>Input:</strong> nums = [2,3,2], queries = [2,2,3]
44+
<strong>Output:</strong> 3
45+
<strong>Explanation:</strong> We don&#39;t do any operation and process the queries as follows:
46+
1- We choose and remove nums[0] since 2 &lt;= 2, then nums becomes [3,2].
47+
2- We choose and remove nums[1] since 2 &lt;= 2, then nums becomes [3].
48+
3- We choose and remove nums[0] since 3 &lt;= 3, then nums becomes [].
49+
Hence, the answer is 3.
50+
It can be shown that we can&#39;t process more than 3 queries.
51+
</pre>
52+
53+
<p><strong class="example">Example 3:</strong></p>
54+
55+
<pre>
56+
<strong>Input:</strong> nums = [3,4,3], queries = [4,3,2]
57+
<strong>Output:</strong> 2
58+
<strong>Explanation:</strong> First we replace nums with the subsequence of nums [4,3].
59+
Then we can process the queries as follows:
60+
1- We choose and remove nums[0] since 4 &lt;= 4, then nums becomes [3].
61+
2- We choose and remove nums[0] since 3 &lt;= 3, then nums becomes [].
62+
3- We can not process any more queries since nums is empty.
63+
Hence, the answer is 2.
64+
It can be shown that we can&#39;t process more than 2 queries.
65+
</pre>
66+
67+
<p>&nbsp;</p>
68+
<p><strong>Constraints:</strong></p>
69+
70+
<ul>
71+
<li><code>1 &lt;= nums.length &lt;= 1000</code></li>
72+
<li><code>1 &lt;= queries.length &lt;= 1000</code></li>
73+
<li><code>1 &lt;= nums[i], queries[i] &lt;= 10<sup>9</sup></code></li>
74+
</ul>
75+
76+
## Solutions
77+
78+
### Solution 1
79+
80+
<!-- tabs:start -->
81+
82+
```python
83+
84+
```
85+
86+
```java
87+
88+
```
89+
90+
```cpp
91+
92+
```
93+
94+
```go
95+
96+
```
97+
98+
<!-- tabs:end -->
99+
100+
<!-- end -->

solution/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -3028,6 +3028,7 @@
30283028
| 3015 | [按距离统计房屋对数目 I](/solution/3000-3099/3015.Count%20the%20Number%20of%20Houses%20at%20a%20Certain%20Distance%20I/README.md) | | 中等 | 第 381 场周赛 |
30293029
| 3016 | [输入单词需要的最少按键次数 II](/solution/3000-3099/3016.Minimum%20Number%20of%20Pushes%20to%20Type%20Word%20II/README.md) | | 中等 | 第 381 场周赛 |
30303030
| 3017 | [按距离统计房屋对数目 II](/solution/3000-3099/3017.Count%20the%20Number%20of%20Houses%20at%20a%20Certain%20Distance%20II/README.md) | | 困难 | 第 381 场周赛 |
3031+
| 3018 | [Maximum Number of Removal Queries That Can Be Processed I](/solution/3000-3099/3018.Maximum%20Number%20of%20Removal%20Queries%20That%20Can%20Be%20Processed%20I/README.md) | | 困难 | 🔒 |
30313032

30323033
## 版权
30333034

solution/README_EN.md

+1
Original file line numberDiff line numberDiff line change
@@ -3026,6 +3026,7 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
30263026
| 3015 | [Count the Number of Houses at a Certain Distance I](/solution/3000-3099/3015.Count%20the%20Number%20of%20Houses%20at%20a%20Certain%20Distance%20I/README_EN.md) | | Medium | Weekly Contest 381 |
30273027
| 3016 | [Minimum Number of Pushes to Type Word II](/solution/3000-3099/3016.Minimum%20Number%20of%20Pushes%20to%20Type%20Word%20II/README_EN.md) | | Medium | Weekly Contest 381 |
30283028
| 3017 | [Count the Number of Houses at a Certain Distance II](/solution/3000-3099/3017.Count%20the%20Number%20of%20Houses%20at%20a%20Certain%20Distance%20II/README_EN.md) | | Hard | Weekly Contest 381 |
3029+
| 3018 | [Maximum Number of Removal Queries That Can Be Processed I](/solution/3000-3099/3018.Maximum%20Number%20of%20Removal%20Queries%20That%20Can%20Be%20Processed%20I/README_EN.md) | | Hard | 🔒 |
30293030

30303031
## Copyright
30313032

0 commit comments

Comments
 (0)