From 4e0efc5219befc198b6372a10a9940a16fd6fd83 Mon Sep 17 00:00:00 2001 From: Yang Libin Date: Thu, 25 Jan 2024 08:20:32 +0000 Subject: [PATCH] feat: add new lc problems --- main.py | 3 +- .../README.md | 102 ++++++++++++++++++ .../README_EN.md | 100 +++++++++++++++++ solution/README.md | 1 + solution/README_EN.md | 1 + 5 files changed, 206 insertions(+), 1 deletion(-) create mode 100644 solution/3000-3099/3018.Maximum Number of Removal Queries That Can Be Processed I/README.md create mode 100644 solution/3000-3099/3018.Maximum Number of Removal Queries That Can Be Processed I/README_EN.md diff --git a/main.py b/main.py index 5970d052d393f..7e95c1a89dc01 100644 --- a/main.py +++ b/main.py @@ -149,11 +149,12 @@ def get_paths(dirs: str, m: int): break j = content.find(end) codes = content[i + len(start) : j].strip() - res = re.findall(r"```(.+?)\n(.+?)\n```", codes, re.DOTALL) + res = re.findall(r"```(.*?)\n(.*?)\n```", codes, re.S) result = [] if res: for lang, code in res: name = mapping.get(lang) + code = code or '' # 需要将 code 缩进 4 个空格 code = code.replace("\n", "\n ") code_snippet = ( diff --git a/solution/3000-3099/3018.Maximum Number of Removal Queries That Can Be Processed I/README.md b/solution/3000-3099/3018.Maximum Number of Removal Queries That Can Be Processed I/README.md new file mode 100644 index 0000000000000..fdf9f19fa22ae --- /dev/null +++ b/solution/3000-3099/3018.Maximum Number of Removal Queries That Can Be Processed I/README.md @@ -0,0 +1,102 @@ +# [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) + +[English Version](/solution/3000-3099/3018.Maximum%20Number%20of%20Removal%20Queries%20That%20Can%20Be%20Processed%20I/README_EN.md) + +## 题目描述 + + + +

You are given a 0-indexed array nums and a 0-indexed array queries.

+ +

You can do the following operation at the beginning at most once:

+ + + +

We start processing queries in the given order; for each query, we do the following:

+ + + +

Return the maximum number of queries that can be processed by doing the operation optimally.

+ +

 

+

Example 1:

+ +
+Input: nums = [1,2,3,4,5], queries = [1,2,3,4,6]
+Output: 4
+Explanation: We don't do any operation and process the queries as follows:
+1- We choose and remove nums[0] since 1 <= 1, then nums becomes [2,3,4,5].
+2- We choose and remove nums[0] since 2 <= 2, then nums becomes [3,4,5].
+3- We choose and remove nums[0] since 3 <= 3, then nums becomes [4,5].
+4- We choose and remove nums[0] since 4 <= 4, then nums becomes [5].
+5- We can not choose any elements from nums since they are not greater than or equal to 5.
+Hence, the answer is 4.
+It can be shown that we can't process more than 4 queries.
+
+ +

Example 2:

+ +
+Input: nums = [2,3,2], queries = [2,2,3]
+Output: 3
+Explanation: We don't do any operation and process the queries as follows:
+1- We choose and remove nums[0] since 2 <= 2, then nums becomes [3,2].
+2- We choose and remove nums[1] since 2 <= 2, then nums becomes [3].
+3- We choose and remove nums[0] since 3 <= 3, then nums becomes [].
+Hence, the answer is 3.
+It can be shown that we can't process more than 3 queries.
+
+ +

Example 3:

+ +
+Input: nums = [3,4,3], queries = [4,3,2]
+Output: 2
+Explanation: First we replace nums with the subsequence of nums [4,3].
+Then we can process the queries as follows:
+1- We choose and remove nums[0] since 4 <= 4, then nums becomes [3].
+2- We choose and remove nums[0] since 3 <= 3, then nums becomes [].
+3- We can not process any more queries since nums is empty.
+Hence, the answer is 2.
+It can be shown that we can't process more than 2 queries.
+
+ +

 

+

Constraints:

+ + + +## 解法 + +### 方法一 + + + +```python + +``` + +```java + +``` + +```cpp + +``` + +```go + +``` + + + + diff --git a/solution/3000-3099/3018.Maximum Number of Removal Queries That Can Be Processed I/README_EN.md b/solution/3000-3099/3018.Maximum Number of Removal Queries That Can Be Processed I/README_EN.md new file mode 100644 index 0000000000000..032dc551a05fc --- /dev/null +++ b/solution/3000-3099/3018.Maximum Number of Removal Queries That Can Be Processed I/README_EN.md @@ -0,0 +1,100 @@ +# [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) + +[中文文档](/solution/3000-3099/3018.Maximum%20Number%20of%20Removal%20Queries%20That%20Can%20Be%20Processed%20I/README.md) + +## Description + +

You are given a 0-indexed array nums and a 0-indexed array queries.

+ +

You can do the following operation at the beginning at most once:

+ + + +

We start processing queries in the given order; for each query, we do the following:

+ + + +

Return the maximum number of queries that can be processed by doing the operation optimally.

+ +

 

+

Example 1:

+ +
+Input: nums = [1,2,3,4,5], queries = [1,2,3,4,6]
+Output: 4
+Explanation: We don't do any operation and process the queries as follows:
+1- We choose and remove nums[0] since 1 <= 1, then nums becomes [2,3,4,5].
+2- We choose and remove nums[0] since 2 <= 2, then nums becomes [3,4,5].
+3- We choose and remove nums[0] since 3 <= 3, then nums becomes [4,5].
+4- We choose and remove nums[0] since 4 <= 4, then nums becomes [5].
+5- We can not choose any elements from nums since they are not greater than or equal to 5.
+Hence, the answer is 4.
+It can be shown that we can't process more than 4 queries.
+
+ +

Example 2:

+ +
+Input: nums = [2,3,2], queries = [2,2,3]
+Output: 3
+Explanation: We don't do any operation and process the queries as follows:
+1- We choose and remove nums[0] since 2 <= 2, then nums becomes [3,2].
+2- We choose and remove nums[1] since 2 <= 2, then nums becomes [3].
+3- We choose and remove nums[0] since 3 <= 3, then nums becomes [].
+Hence, the answer is 3.
+It can be shown that we can't process more than 3 queries.
+
+ +

Example 3:

+ +
+Input: nums = [3,4,3], queries = [4,3,2]
+Output: 2
+Explanation: First we replace nums with the subsequence of nums [4,3].
+Then we can process the queries as follows:
+1- We choose and remove nums[0] since 4 <= 4, then nums becomes [3].
+2- We choose and remove nums[0] since 3 <= 3, then nums becomes [].
+3- We can not process any more queries since nums is empty.
+Hence, the answer is 2.
+It can be shown that we can't process more than 2 queries.
+
+ +

 

+

Constraints:

+ + + +## Solutions + +### Solution 1 + + + +```python + +``` + +```java + +``` + +```cpp + +``` + +```go + +``` + + + + diff --git a/solution/README.md b/solution/README.md index 5c824be64d59b..218d58e30bab1 100644 --- a/solution/README.md +++ b/solution/README.md @@ -3028,6 +3028,7 @@ | 3015 | [按距离统计房屋对数目 I](/solution/3000-3099/3015.Count%20the%20Number%20of%20Houses%20at%20a%20Certain%20Distance%20I/README.md) | | 中等 | 第 381 场周赛 | | 3016 | [输入单词需要的最少按键次数 II](/solution/3000-3099/3016.Minimum%20Number%20of%20Pushes%20to%20Type%20Word%20II/README.md) | | 中等 | 第 381 场周赛 | | 3017 | [按距离统计房屋对数目 II](/solution/3000-3099/3017.Count%20the%20Number%20of%20Houses%20at%20a%20Certain%20Distance%20II/README.md) | | 困难 | 第 381 场周赛 | +| 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) | | 困难 | 🔒 | ## 版权 diff --git a/solution/README_EN.md b/solution/README_EN.md index ae33c77ce6478..bf59ec0029b8d 100644 --- a/solution/README_EN.md +++ b/solution/README_EN.md @@ -3026,6 +3026,7 @@ Press Control + F(or Command + F on | 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 | | 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 | | 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 | +| 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 | 🔒 | ## Copyright