Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 67eff10

Browse files
committed
feat: add lc problems: No.1858-1866
1 parent df9bee6 commit 67eff10

File tree

27 files changed

+1523
-5
lines changed

27 files changed

+1523
-5
lines changed

‎solution/0400-0499/0432.All O`one Data Structure/README_EN.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# [432. All O`one Data Structure](https://leetcode.com/problems/all-oone-data-structure)
1+
# [432. All Oone Data Structure](https://leetcode.com/problems/all-oone-data-structure)
22

33
[中文文档](/solution/0400-0499/0432.All%20O%60one%20Data%20Structure/README.md)
44

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# [1858. ](https://leetcode-cn.com/problems/longest-word-with-all-prefixes)
2+
3+
[English Version](/solution/1800-1899/1858.Longest%20Word%20With%20All%20Prefixes/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
None
10+
11+
## 解法
12+
13+
<!-- 这里可写通用的实现逻辑 -->
14+
15+
<!-- tabs:start -->
16+
17+
### **Python3**
18+
19+
<!-- 这里可写当前语言的特殊实现逻辑 -->
20+
21+
```python
22+
23+
```
24+
25+
### **Java**
26+
27+
<!-- 这里可写当前语言的特殊实现逻辑 -->
28+
29+
```java
30+
31+
```
32+
33+
### **...**
34+
35+
```
36+
37+
```
38+
39+
<!-- tabs:end -->
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# [1858. Longest Word With All Prefixes](https://leetcode.com/problems/longest-word-with-all-prefixes)
2+
3+
[中文文档](/solution/1800-1899/1858.Longest%20Word%20With%20All%20Prefixes/README.md)
4+
5+
## Description
6+
7+
<p>Given an array of strings <code>words</code>, find the <strong>longest</strong> string in <code>words</code> such that <strong>every prefix</strong> of it is also in <code>words</code>.</p>
8+
9+
<ul>
10+
<li>For example, let <code>words = [&quot;a&quot;, &quot;app&quot;, &quot;ap&quot;]</code>. The string <code>&quot;app&quot;</code> has prefixes <code>&quot;ap&quot;</code> and <code>&quot;a&quot;</code>, all of which are in <code>words</code>.</li>
11+
</ul>
12+
13+
<p>Return <em>the string described above. If there is more than one string with the same length, return the <strong>lexicographically smallest</strong> one, and if no string exists, return </em><code>&quot;&quot;</code>.</p>
14+
15+
<p>&nbsp;</p>
16+
17+
<p><strong>Example 1:</strong></p>
18+
19+
<pre>
20+
21+
<strong>Input:</strong> words = [&quot;k&quot;,&quot;ki&quot;,&quot;kir&quot;,&quot;kira&quot;, &quot;kiran&quot;]
22+
23+
<strong>Output:</strong> &quot;kiran&quot;
24+
25+
<strong>Explanation:</strong> &quot;kiran&quot; has prefixes &quot;kira&quot;, &quot;kir&quot;, &quot;ki&quot;, and &quot;k&quot;, and all of them appear in words.
26+
27+
</pre>
28+
29+
<p><strong>Example 2:</strong></p>
30+
31+
<pre>
32+
33+
<strong>Input:</strong> words = [&quot;a&quot;, &quot;banana&quot;, &quot;app&quot;, &quot;appl&quot;, &quot;ap&quot;, &quot;apply&quot;, &quot;apple&quot;]
34+
35+
<strong>Output:</strong> &quot;apple&quot;
36+
37+
<strong>Explanation:</strong> Both &quot;apple&quot; and &quot;apply&quot; have all their prefixes in words.
38+
39+
However, &quot;apple&quot; is lexicographically smaller, so we return that.
40+
41+
</pre>
42+
43+
<p><strong>Example 3:</strong></p>
44+
45+
<pre>
46+
47+
<strong>Input:</strong> words = [&quot;abc&quot;, &quot;bc&quot;, &quot;ab&quot;, &quot;qwe&quot;]
48+
49+
<strong>Output:</strong> &quot;&quot;
50+
51+
</pre>
52+
53+
<p>&nbsp;</p>
54+
55+
<p><strong>Constraints:</strong></p>
56+
57+
<ul>
58+
<li><code>1 &lt;= words.length &lt;= 10<sup>5</sup></code></li>
59+
<li><code>1 &lt;= words[i].length &lt;= 10<sup>5</sup></code></li>
60+
<li><code>1 &lt;= sum(words[i].length) &lt;= 10<sup>5</sup></code></li>
61+
</ul>
62+
63+
## Solutions
64+
65+
<!-- tabs:start -->
66+
67+
### **Python3**
68+
69+
```python
70+
71+
```
72+
73+
### **Java**
74+
75+
```java
76+
77+
```
78+
79+
### **...**
80+
81+
```
82+
83+
```
84+
85+
<!-- tabs:end -->
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# [1859. 将句子排序](https://leetcode-cn.com/problems/sorting-the-sentence)
2+
3+
[English Version](/solution/1800-1899/1859.Sorting%20the%20Sentence/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>一个 <strong>句子</strong> 指的是一个序列的单词用单个空格连接起来,且开头和结尾没有任何空格。每个单词都只包含小写或大写英文字母。</p>
10+
11+
<p>我们可以给一个句子添加 <strong>从 1 开始的单词位置索引 </strong>,并且将句子中所有单词 <strong>打乱顺序</strong> 。</p>
12+
13+
<ul>
14+
<li>比方说,句子 <code>"This is a sentence"</code> 可以被打乱顺序得到 <code>"sentence4 a3 is2 This1"</code> 或者 <code>"is2 sentence4 This1 a3"</code> 。</li>
15+
</ul>
16+
17+
<p>给你一个 <strong>打乱顺序</strong> 的句子 <code>s</code> ,它包含的单词不超过 <code>9</code> 个,请你重新构造并得到原本顺序的句子。</p>
18+
19+
<p> </p>
20+
21+
<p><strong>示例 1:</strong></p>
22+
23+
<pre>
24+
<b>输入:</b>s = "is2 sentence4 This1 a3"
25+
<b>输出:</b>"This is a sentence"
26+
<b>解释:</b>将 s 中的单词按照初始位置排序,得到 "This1 is2 a3 sentence4" ,然后删除数字。
27+
</pre>
28+
29+
<p><strong>示例 2:</strong></p>
30+
31+
<pre>
32+
<b>输入:</b>s = "Myself2 Me1 I4 and3"
33+
<b>输出:</b>"Me Myself and I"
34+
<b>解释:</b>将 s 中的单词按照初始位置排序,得到 "Me1 Myself2 and3 I4" ,然后删除数字。</pre>
35+
36+
<p> </p>
37+
38+
<p><strong>提示:</strong></p>
39+
40+
<ul>
41+
<li><code>2 <= s.length <= 200</code></li>
42+
<li><code>s</code> 只包含小写和大写英文字母、空格以及从 <code>1</code> 到 <code>9</code> 的数字。</li>
43+
<li><code>s</code> 中单词数目为 <code>1</code> 到 <code>9</code> 个。</li>
44+
<li><code>s</code> 中的单词由单个空格分隔。</li>
45+
<li><code>s</code> 不包含任何前导或者后缀空格。</li>
46+
</ul>
47+
48+
49+
## 解法
50+
51+
<!-- 这里可写通用的实现逻辑 -->
52+
53+
<!-- tabs:start -->
54+
55+
### **Python3**
56+
57+
<!-- 这里可写当前语言的特殊实现逻辑 -->
58+
59+
```python
60+
61+
```
62+
63+
### **Java**
64+
65+
<!-- 这里可写当前语言的特殊实现逻辑 -->
66+
67+
```java
68+
69+
```
70+
71+
### **...**
72+
73+
```
74+
75+
```
76+
77+
<!-- tabs:end -->
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# [1859. Sorting the Sentence](https://leetcode.com/problems/sorting-the-sentence)
2+
3+
[中文文档](/solution/1800-1899/1859.Sorting%20the%20Sentence/README.md)
4+
5+
## Description
6+
7+
<p>A <strong>sentence</strong> is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of lowercase and uppercase English letters.</p>
8+
9+
10+
11+
<p>A sentence can be <strong>shuffled</strong> by appending the <strong>1-indexed word position</strong> to each word then rearranging the words in the sentence.</p>
12+
13+
14+
15+
<ul>
16+
<li>For example, the sentence <code>&quot;This is a sentence&quot;</code> can be shuffled as <code>&quot;sentence4 a3 is2 This1&quot;</code> or <code>&quot;is2 sentence4 This1 a3&quot;</code>.</li>
17+
</ul>
18+
19+
20+
21+
<p>Given a <strong>shuffled sentence</strong> <code>s</code> containing no more than <code>9</code> words, reconstruct and return <em>the original sentence</em>.</p>
22+
23+
24+
25+
<p>&nbsp;</p>
26+
27+
<p><strong>Example 1:</strong></p>
28+
29+
30+
31+
<pre>
32+
33+
<strong>Input:</strong> s = &quot;is2 sentence4 This1 a3&quot;
34+
35+
<strong>Output:</strong> &quot;This is a sentence&quot;
36+
37+
<strong>Explanation:</strong> Sort the words in s to their original positions &quot;This1 is2 a3 sentence4&quot;, then remove the numbers.
38+
39+
</pre>
40+
41+
42+
43+
<p><strong>Example 2:</strong></p>
44+
45+
46+
47+
<pre>
48+
49+
<strong>Input:</strong> s = &quot;Myself2 Me1 I4 and3&quot;
50+
51+
<strong>Output:</strong> &quot;Me Myself and I&quot;
52+
53+
<strong>Explanation:</strong> Sort the words in s to their original positions &quot;Me1 Myself2 and3 I4&quot;, then remove the numbers.
54+
55+
</pre>
56+
57+
58+
59+
<p>&nbsp;</p>
60+
61+
<p><strong>Constraints:</strong></p>
62+
63+
64+
65+
<ul>
66+
<li><code>2 &lt;= s.length &lt;= 200</code></li>
67+
<li><code>s</code> consists of lowercase and uppercase English letters, spaces, and digits from <code>1</code> to <code>9</code>.</li>
68+
<li>The number of words in <code>s</code> is between <code>1</code> and <code>9</code>.</li>
69+
<li>The words in <code>s</code> are separated by a single space.</li>
70+
<li><code>s</code> contains no leading or trailing spaces.</li>
71+
</ul>
72+
73+
## Solutions
74+
75+
<!-- tabs:start -->
76+
77+
### **Python3**
78+
79+
```python
80+
81+
```
82+
83+
### **Java**
84+
85+
```java
86+
87+
```
88+
89+
### **...**
90+
91+
```
92+
93+
```
94+
95+
<!-- tabs:end -->
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# [1860. 增长的内存泄露](https://leetcode-cn.com/problems/incremental-memory-leak)
2+
3+
[English Version](/solution/1800-1899/1860.Incremental%20Memory%20Leak/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你两个整数 <code>memory1</code> 和 <code>memory2</code> 分别表示两个内存条剩余可用内存的位数。现在有一个程序每秒递增的速度消耗着内存。</p>
10+
11+
<p>在第 <code>i</code> 秒(秒数从 1 开始),有 <code>i</code> 位内存被分配到 <strong>剩余内存较多</strong> 的内存条(如果两者一样多,则分配到第一个内存条)。如果两者剩余内存都不足 <code>i</code> 位,那么程序将 <b>意外退出</b> 。</p>
12+
13+
<p>请你返回一个数组,包含<em> </em><code>[crashTime, memory1<sub>crash</sub>, memory2<sub>crash</sub>]</code> ,其中 <code>crashTime</code>是程序意外退出的时间(单位为秒),<em> </em><code>memory1<sub>crash</sub></code><em> </em>和<em> </em><code>memory2<sub>crash</sub></code><em> </em>分别是两个内存条最后剩余内存的位数。</p>
14+
15+
<p> </p>
16+
17+
<p><strong>示例 1:</strong></p>
18+
19+
<pre><b>输入:</b>memory1 = 2, memory2 = 2
20+
<b>输出:</b>[3,1,0]
21+
<b>解释:</b>内存分配如下:
22+
- 第 1 秒,内存条 1 被占用 1 位内存。内存条 1 现在有 1 位剩余可用内存。
23+
- 第 2 秒,内存条 2 被占用 2 位内存。内存条 2 现在有 0 位剩余可用内存。
24+
- 第 3 秒,程序意外退出,两个内存条分别有 1 位和 0 位剩余可用内存。
25+
</pre>
26+
27+
<p><strong>示例 2:</strong></p>
28+
29+
<pre><b>输入:</b>memory1 = 8, memory2 = 11
30+
<b>输出:</b>[6,0,4]
31+
<b>解释:</b>内存分配如下:
32+
- 第 1 秒,内存条 2 被占用 1 位内存,内存条 2 现在有 10 位剩余可用内存。
33+
- 第 2 秒,内存条 2 被占用 2 位内存,内存条 2 现在有 8 位剩余可用内存。
34+
- 第 3 秒,内存条 1 被占用 3 位内存,内存条 1 现在有 5 位剩余可用内存。
35+
- 第 4 秒,内存条 2 被占用 4 位内存,内存条 2 现在有 4 位剩余可用内存。
36+
- 第 5 秒,内存条 1 被占用 5 位内存,内存条 1 现在有 0 位剩余可用内存。
37+
- 第 6 秒,程序意外退出,两个内存条分别有 0 位和 4 位剩余可用内存。
38+
</pre>
39+
40+
<p> </p>
41+
42+
<p><strong>提示:</strong></p>
43+
44+
<ul>
45+
<li><code>0 &lt;= memory1, memory2 &lt;= 2<sup>31</sup> - 1</code></li>
46+
</ul>
47+
48+
49+
## 解法
50+
51+
<!-- 这里可写通用的实现逻辑 -->
52+
53+
<!-- tabs:start -->
54+
55+
### **Python3**
56+
57+
<!-- 这里可写当前语言的特殊实现逻辑 -->
58+
59+
```python
60+
61+
```
62+
63+
### **Java**
64+
65+
<!-- 这里可写当前语言的特殊实现逻辑 -->
66+
67+
```java
68+
69+
```
70+
71+
### **...**
72+
73+
```
74+
75+
```
76+
77+
<!-- tabs:end -->

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /