Skip to content

Commit 1516ff8

Browse files
committed
chore: add new lc problems: No.2113+
Add new lc problems: No.2113~2122
1 parent f8d6aa1 commit 1516ff8

File tree

29 files changed

+10417
-8494
lines changed

29 files changed

+10417
-8494
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# [2113. Elements in Array After Removing and Replacing Elements](https://leetcode-cn.com/problems/elements-in-array-after-removing-and-replacing-elements)
2+
3+
[English Version](/solution/2100-2199/2113.Elements%20in%20Array%20After%20Removing%20and%20Replacing%20Elements/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. Initially on minute <code>0</code>, the array is unchanged. Every minute, the <strong>leftmost</strong> element in <code>nums</code> is removed until no elements remain. Then, every minute, one element is appended to the <strong>end</strong> of <code>nums</code>, in the order they were removed in, until the original array is restored. This process repeats indefinitely.</p>
10+
11+
<ul>
12+
<li>For example, the array <code>[0,1,2]</code> would change as follows: <code>[0,1,2] &rarr; [1,2] &rarr; [2] &rarr; [] &rarr; [0] &rarr; [0,1] &rarr; [0,1,2] &rarr; [1,2] &rarr; [2] &rarr; [] &rarr; [0] &rarr; [0,1] &rarr; [0,1,2] &rarr; ...</code></li>
13+
</ul>
14+
15+
<p>You are also given a 2D integer array <code>queries</code> of size <code>n</code> where <code>queries[j] = [time<sub>j</sub>, index<sub>j</sub>]</code>. The answer to the <code>j<sup>th</sup></code> query is:</p>
16+
17+
<ul>
18+
<li><code>nums[index<sub>j</sub>]</code> if <code>index<sub>j</sub> &lt; nums.length</code> at minute <code>time<sub>j</sub></code></li>
19+
<li><code>-1</code> if <code>index<sub>j</sub> &gt;= nums.length</code> at minute <code>time<sub>j</sub></code></li>
20+
</ul>
21+
22+
<p>Return <em>an integer array <code>ans</code> of size </em><code>n</code> <em>where </em><code>ans[j]</code><em> is the answer to the </em><code>j<sup>th</sup></code><em> query</em>.</p>
23+
24+
<p>&nbsp;</p>
25+
<p><strong>Example 1:</strong></p>
26+
27+
<pre>
28+
<strong>Input:</strong> nums = [0,1,2], queries = [[0,2],[2,0],[3,2],[5,0]]
29+
<strong>Output:</strong> [2,2,-1,0]
30+
<strong>Explanation:</strong>
31+
Minute 0: [0,1,2] - All elements are in the nums.
32+
Minute 1: [1,2] - The leftmost element, 0, is removed.
33+
Minute 2: [2] - The leftmost element, 1, is removed.
34+
Minute 3: [] - The leftmost element, 2, is removed.
35+
Minute 4: [0] - 0 is added to the end of nums.
36+
Minute 5: [0,1] - 1 is added to the end of nums.
37+
38+
At minute 0, nums[2] is 2.
39+
At minute 2, nums[0] is 2.
40+
At minute 3, nums[2] does not exist.
41+
At minute 5, nums[0] is 0.
42+
</pre>
43+
44+
<p><strong>Example 2:</strong></p>
45+
46+
<pre>
47+
<strong>Input:</strong> nums = [2], queries = [[0,0],[1,0],[2,0],[3,0]]
48+
<strong>Output:</strong> [2,-1,2,-1]
49+
Minute 0: [2] - All elements are in the nums.
50+
Minute 1: [] - The leftmost element, 2, is removed.
51+
Minute 2: [2] - 2 is added to the end of nums.
52+
Minute 3: [] - The leftmost element, 2, is removed.
53+
54+
At minute 0, nums[0] is 2.
55+
At minute 1, nums[0] does not exist.
56+
At minute 2, nums[0] is 2.
57+
At minute 3, nums[0] does not exist.
58+
</pre>
59+
60+
<p>&nbsp;</p>
61+
<p><strong>Constraints:</strong></p>
62+
63+
<ul>
64+
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
65+
<li><code>0 &lt;= nums[i] &lt;= 100</code></li>
66+
<li><code>n == queries.length</code></li>
67+
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
68+
<li><code>queries[j].length == 2</code></li>
69+
<li><code>0 &lt;= time<sub>j</sub> &lt;= 10<sup>5</sup></code></li>
70+
<li><code>0 &lt;= index<sub>j</sub> &lt; nums.length</code></li>
71+
</ul>
72+
73+
## 解法
74+
75+
<!-- 这里可写通用的实现逻辑 -->
76+
77+
<!-- tabs:start -->
78+
79+
### **Python3**
80+
81+
<!-- 这里可写当前语言的特殊实现逻辑 -->
82+
83+
```python
84+
85+
```
86+
87+
### **Java**
88+
89+
<!-- 这里可写当前语言的特殊实现逻辑 -->
90+
91+
```java
92+
93+
```
94+
95+
### **TypeScript**
96+
97+
<!-- 这里可写当前语言的特殊实现逻辑 -->
98+
99+
```ts
100+
101+
```
102+
103+
### **...**
104+
105+
```
106+
107+
```
108+
109+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# [2113. Elements in Array After Removing and Replacing Elements](https://leetcode.com/problems/elements-in-array-after-removing-and-replacing-elements)
2+
3+
[中文文档](/solution/2100-2199/2113.Elements%20in%20Array%20After%20Removing%20and%20Replacing%20Elements/README.md)
4+
5+
## Description
6+
7+
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. Initially on minute <code>0</code>, the array is unchanged. Every minute, the <strong>leftmost</strong> element in <code>nums</code> is removed until no elements remain. Then, every minute, one element is appended to the <strong>end</strong> of <code>nums</code>, in the order they were removed in, until the original array is restored. This process repeats indefinitely.</p>
8+
9+
<ul>
10+
<li>For example, the array <code>[0,1,2]</code> would change as follows: <code>[0,1,2] &rarr; [1,2] &rarr; [2] &rarr; [] &rarr; [0] &rarr; [0,1] &rarr; [0,1,2] &rarr; [1,2] &rarr; [2] &rarr; [] &rarr; [0] &rarr; [0,1] &rarr; [0,1,2] &rarr; ...</code></li>
11+
</ul>
12+
13+
<p>You are also given a 2D integer array <code>queries</code> of size <code>n</code> where <code>queries[j] = [time<sub>j</sub>, index<sub>j</sub>]</code>. The answer to the <code>j<sup>th</sup></code> query is:</p>
14+
15+
<ul>
16+
<li><code>nums[index<sub>j</sub>]</code> if <code>index<sub>j</sub> &lt; nums.length</code> at minute <code>time<sub>j</sub></code></li>
17+
<li><code>-1</code> if <code>index<sub>j</sub> &gt;= nums.length</code> at minute <code>time<sub>j</sub></code></li>
18+
</ul>
19+
20+
<p>Return <em>an integer array <code>ans</code> of size </em><code>n</code> <em>where </em><code>ans[j]</code><em> is the answer to the </em><code>j<sup>th</sup></code><em> query</em>.</p>
21+
22+
<p>&nbsp;</p>
23+
<p><strong>Example 1:</strong></p>
24+
25+
<pre>
26+
<strong>Input:</strong> nums = [0,1,2], queries = [[0,2],[2,0],[3,2],[5,0]]
27+
<strong>Output:</strong> [2,2,-1,0]
28+
<strong>Explanation:</strong>
29+
Minute 0: [0,1,2] - All elements are in the nums.
30+
Minute 1: [1,2] - The leftmost element, 0, is removed.
31+
Minute 2: [2] - The leftmost element, 1, is removed.
32+
Minute 3: [] - The leftmost element, 2, is removed.
33+
Minute 4: [0] - 0 is added to the end of nums.
34+
Minute 5: [0,1] - 1 is added to the end of nums.
35+
36+
At minute 0, nums[2] is 2.
37+
At minute 2, nums[0] is 2.
38+
At minute 3, nums[2] does not exist.
39+
At minute 5, nums[0] is 0.
40+
</pre>
41+
42+
<p><strong>Example 2:</strong></p>
43+
44+
<pre>
45+
<strong>Input:</strong> nums = [2], queries = [[0,0],[1,0],[2,0],[3,0]]
46+
<strong>Output:</strong> [2,-1,2,-1]
47+
Minute 0: [2] - All elements are in the nums.
48+
Minute 1: [] - The leftmost element, 2, is removed.
49+
Minute 2: [2] - 2 is added to the end of nums.
50+
Minute 3: [] - The leftmost element, 2, is removed.
51+
52+
At minute 0, nums[0] is 2.
53+
At minute 1, nums[0] does not exist.
54+
At minute 2, nums[0] is 2.
55+
At minute 3, nums[0] does not exist.
56+
</pre>
57+
58+
<p>&nbsp;</p>
59+
<p><strong>Constraints:</strong></p>
60+
61+
<ul>
62+
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
63+
<li><code>0 &lt;= nums[i] &lt;= 100</code></li>
64+
<li><code>n == queries.length</code></li>
65+
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
66+
<li><code>queries[j].length == 2</code></li>
67+
<li><code>0 &lt;= time<sub>j</sub> &lt;= 10<sup>5</sup></code></li>
68+
<li><code>0 &lt;= index<sub>j</sub> &lt; nums.length</code></li>
69+
</ul>
70+
71+
## Solutions
72+
73+
<!-- tabs:start -->
74+
75+
### **Python3**
76+
77+
```python
78+
79+
```
80+
81+
### **Java**
82+
83+
```java
84+
85+
```
86+
87+
### **TypeScript**
88+
89+
```ts
90+
91+
```
92+
93+
### **...**
94+
95+
```
96+
97+
```
98+
99+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# [2114. 句子中的最多单词数](https://leetcode-cn.com/problems/maximum-number-of-words-found-in-sentences)
2+
3+
[English Version](/solution/2100-2199/2114.Maximum%20Number%20of%20Words%20Found%20in%20Sentences/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>一个 <strong>句子</strong>&nbsp;由一些 <strong>单词</strong>&nbsp;以及它们之间的单个空格组成,句子的开头和结尾不会有多余空格。</p>
10+
11+
<p>给你一个字符串数组&nbsp;<code>sentences</code>&nbsp;,其中&nbsp;<code>sentences[i]</code>&nbsp;表示单个 <strong>句子</strong>&nbsp;。</p>
12+
13+
<p>请你返回单个句子里 <strong>单词的最多数目</strong>&nbsp;。</p>
14+
15+
<p>&nbsp;</p>
16+
17+
<p><strong>示例 1:</strong></p>
18+
19+
<pre><b>输入:</b>sentences = ["alice and bob love leetcode", "i think so too", <em><strong>"this is great thanks very much"</strong></em>]
20+
<b>输出:</b>6
21+
<b>解释:</b>
22+
- 第一个句子 "alice and bob love leetcode" 总共有 5 个单词。
23+
- 第二个句子 "i think so too" 总共有 4 个单词。
24+
- 第三个句子 "this is great thanks very much" 总共有 6 个单词。
25+
所以,单个句子中有最多单词数的是第三个句子,总共有 6 个单词。
26+
</pre>
27+
28+
<p><strong>示例 2:</strong></p>
29+
30+
<pre><b>输入:</b>sentences = ["please wait", <em><strong>"continue to fight"</strong></em>, <em><strong>"continue to win"</strong></em>]
31+
<b>输出:</b>3
32+
<b>解释:</b>可能有多个句子有相同单词数。
33+
这个例子中,第二个句子和第三个句子(加粗斜体)有相同数目的单词数。
34+
</pre>
35+
36+
<p>&nbsp;</p>
37+
38+
<p><strong>提示:</strong></p>
39+
40+
<ul>
41+
<li><code>1 &lt;= sentences.length &lt;= 100</code></li>
42+
<li><code>1 &lt;= sentences[i].length &lt;= 100</code></li>
43+
<li><code>sentences[i]</code>&nbsp;只包含小写英文字母和&nbsp;<code>' '</code>&nbsp;。</li>
44+
<li><code>sentences[i]</code>&nbsp;的开头和结尾都没有空格。</li>
45+
<li><code>sentences[i]</code>&nbsp;中所有单词由单个空格隔开。</li>
46+
</ul>
47+
48+
## 解法
49+
50+
<!-- 这里可写通用的实现逻辑 -->
51+
52+
<!-- tabs:start -->
53+
54+
### **Python3**
55+
56+
<!-- 这里可写当前语言的特殊实现逻辑 -->
57+
58+
```python
59+
60+
```
61+
62+
### **Java**
63+
64+
<!-- 这里可写当前语言的特殊实现逻辑 -->
65+
66+
```java
67+
68+
```
69+
70+
### **TypeScript**
71+
72+
<!-- 这里可写当前语言的特殊实现逻辑 -->
73+
74+
```ts
75+
76+
```
77+
78+
### **...**
79+
80+
```
81+
82+
```
83+
84+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# [2114. Maximum Number of Words Found in Sentences](https://leetcode.com/problems/maximum-number-of-words-found-in-sentences)
2+
3+
[中文文档](/solution/2100-2199/2114.Maximum%20Number%20of%20Words%20Found%20in%20Sentences/README.md)
4+
5+
## Description
6+
7+
<p>A <strong>sentence</strong> is a list of <strong>words</strong> that are separated by a single space&nbsp;with no leading or trailing spaces.</p>
8+
9+
<p>You are given an array of strings <code>sentences</code>, where each <code>sentences[i]</code> represents a single <strong>sentence</strong>.</p>
10+
11+
<p>Return <em>the <strong>maximum number of words</strong> that appear in a single sentence</em>.</p>
12+
13+
<p>&nbsp;</p>
14+
<p><strong>Example 1:</strong></p>
15+
16+
<pre>
17+
<strong>Input:</strong> sentences = [&quot;alice and bob love leetcode&quot;, &quot;i think so too&quot;, <u>&quot;this is great thanks very much&quot;</u>]
18+
<strong>Output:</strong> 6
19+
<strong>Explanation:</strong>
20+
- The first sentence, &quot;alice and bob love leetcode&quot;, has 5 words in total.
21+
- The second sentence, i think so too&quot;, has 4 words in total.
22+
- The third sentence, &quot;this is great thanks very much&quot;, has 6 words in total.
23+
Thus, the maximum number of words in a single sentence comes from the third sentence, which has 6 words.
24+
</pre>
25+
26+
<p><strong>Example 2:</strong></p>
27+
28+
<pre>
29+
<strong>Input:</strong> sentences = [&quot;please wait&quot;, <u>&quot;continue to fight&quot;</u>, <u>&quot;continue to win&quot;</u>]
30+
<strong>Output:</strong> 3
31+
<strong>Explanation:</strong> It is possible that multiple sentences contain the same number of words.
32+
In this example, the second and third sentences (underlined) have the same number of words.
33+
</pre>
34+
35+
<p>&nbsp;</p>
36+
<p><strong>Constraints:</strong></p>
37+
38+
<ul>
39+
<li><code>1 &lt;= sentences.length &lt;= 100</code></li>
40+
<li><code>1 &lt;= sentences[i].length &lt;= 100</code></li>
41+
<li><code>sentences[i]</code> consists only of lowercase English letters and <code>&#39; &#39;</code> only.</li>
42+
<li><code>sentences[i]</code> does not have leading or trailing spaces.</li>
43+
<li>All the words in <code>sentences[i]</code> are separated by a single space.</li>
44+
</ul>
45+
46+
## Solutions
47+
48+
<!-- tabs:start -->
49+
50+
### **Python3**
51+
52+
```python
53+
54+
```
55+
56+
### **Java**
57+
58+
```java
59+
60+
```
61+
62+
### **TypeScript**
63+
64+
```ts
65+
66+
```
67+
68+
### **...**
69+
70+
```
71+
72+
```
73+
74+
<!-- tabs:end -->

0 commit comments

Comments
 (0)