Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [432. All O`one Data Structure](https://leetcode.com/problems/all-oone-data-structure)
# [432. All O one Data Structure](https://leetcode.com/problems/all-oone-data-structure)

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

Expand Down
39 changes: 39 additions & 0 deletions solution/1800-1899/1858.Longest Word With All Prefixes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# [1858. ](https://leetcode-cn.com/problems/longest-word-with-all-prefixes)

[English Version](/solution/1800-1899/1858.Longest%20Word%20With%20All%20Prefixes/README_EN.md)

## 题目描述

<!-- 这里写题目描述 -->

None

## 解法

<!-- 这里可写通用的实现逻辑 -->

<!-- tabs:start -->

### **Python3**

<!-- 这里可写当前语言的特殊实现逻辑 -->

```python

```

### **Java**

<!-- 这里可写当前语言的特殊实现逻辑 -->

```java

```

### **...**

```

```

<!-- tabs:end -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# [1858. Longest Word With All Prefixes](https://leetcode.com/problems/longest-word-with-all-prefixes)

[中文文档](/solution/1800-1899/1858.Longest%20Word%20With%20All%20Prefixes/README.md)

## Description

<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>

<ul>
<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>
</ul>

<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>

<p>&nbsp;</p>

<p><strong>Example 1:</strong></p>

<pre>

<strong>Input:</strong> words = [&quot;k&quot;,&quot;ki&quot;,&quot;kir&quot;,&quot;kira&quot;, &quot;kiran&quot;]

<strong>Output:</strong> &quot;kiran&quot;

<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.

</pre>

<p><strong>Example 2:</strong></p>

<pre>

<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;]

<strong>Output:</strong> &quot;apple&quot;

<strong>Explanation:</strong> Both &quot;apple&quot; and &quot;apply&quot; have all their prefixes in words.

However, &quot;apple&quot; is lexicographically smaller, so we return that.

</pre>

<p><strong>Example 3:</strong></p>

<pre>

<strong>Input:</strong> words = [&quot;abc&quot;, &quot;bc&quot;, &quot;ab&quot;, &quot;qwe&quot;]

<strong>Output:</strong> &quot;&quot;

</pre>

<p>&nbsp;</p>

<p><strong>Constraints:</strong></p>

<ul>
<li><code>1 &lt;= words.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= words[i].length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= sum(words[i].length) &lt;= 10<sup>5</sup></code></li>
</ul>

## Solutions

<!-- tabs:start -->

### **Python3**

```python

```

### **Java**

```java

```

### **...**

```

```

<!-- tabs:end -->
77 changes: 77 additions & 0 deletions solution/1800-1899/1859.Sorting the Sentence/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# [1859. 将句子排序](https://leetcode-cn.com/problems/sorting-the-sentence)

[English Version](/solution/1800-1899/1859.Sorting%20the%20Sentence/README_EN.md)

## 题目描述

<!-- 这里写题目描述 -->

<p>一个 <strong>句子</strong> 指的是一个序列的单词用单个空格连接起来,且开头和结尾没有任何空格。每个单词都只包含小写或大写英文字母。</p>

<p>我们可以给一个句子添加 <strong>从 1 开始的单词位置索引 </strong>,并且将句子中所有单词 <strong>打乱顺序</strong> 。</p>

<ul>
<li>比方说,句子 <code>"This is a sentence"</code> 可以被打乱顺序得到 <code>"sentence4 a3 is2 This1"</code> 或者 <code>"is2 sentence4 This1 a3"</code> 。</li>
</ul>

<p>给你一个 <strong>打乱顺序</strong> 的句子 <code>s</code> ,它包含的单词不超过 <code>9</code> 个,请你重新构造并得到原本顺序的句子。</p>

<p> </p>

<p><strong>示例 1:</strong></p>

<pre>
<b>输入:</b>s = "is2 sentence4 This1 a3"
<b>输出:</b>"This is a sentence"
<b>解释:</b>将 s 中的单词按照初始位置排序,得到 "This1 is2 a3 sentence4" ,然后删除数字。
</pre>

<p><strong>示例 2:</strong></p>

<pre>
<b>输入:</b>s = "Myself2 Me1 I4 and3"
<b>输出:</b>"Me Myself and I"
<b>解释:</b>将 s 中的单词按照初始位置排序,得到 "Me1 Myself2 and3 I4" ,然后删除数字。</pre>

<p> </p>

<p><strong>提示:</strong></p>

<ul>
<li><code>2 <= s.length <= 200</code></li>
<li><code>s</code> 只包含小写和大写英文字母、空格以及从 <code>1</code> 到 <code>9</code> 的数字。</li>
<li><code>s</code> 中单词数目为 <code>1</code> 到 <code>9</code> 个。</li>
<li><code>s</code> 中的单词由单个空格分隔。</li>
<li><code>s</code> 不包含任何前导或者后缀空格。</li>
</ul>


## 解法

<!-- 这里可写通用的实现逻辑 -->

<!-- tabs:start -->

### **Python3**

<!-- 这里可写当前语言的特殊实现逻辑 -->

```python

```

### **Java**

<!-- 这里可写当前语言的特殊实现逻辑 -->

```java

```

### **...**

```

```

<!-- tabs:end -->
95 changes: 95 additions & 0 deletions solution/1800-1899/1859.Sorting the Sentence/README_EN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# [1859. Sorting the Sentence](https://leetcode.com/problems/sorting-the-sentence)

[中文文档](/solution/1800-1899/1859.Sorting%20the%20Sentence/README.md)

## Description

<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>



<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>



<ul>
<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>
</ul>



<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>



<p>&nbsp;</p>

<p><strong>Example 1:</strong></p>



<pre>

<strong>Input:</strong> s = &quot;is2 sentence4 This1 a3&quot;

<strong>Output:</strong> &quot;This is a sentence&quot;

<strong>Explanation:</strong> Sort the words in s to their original positions &quot;This1 is2 a3 sentence4&quot;, then remove the numbers.

</pre>



<p><strong>Example 2:</strong></p>



<pre>

<strong>Input:</strong> s = &quot;Myself2 Me1 I4 and3&quot;

<strong>Output:</strong> &quot;Me Myself and I&quot;

<strong>Explanation:</strong> Sort the words in s to their original positions &quot;Me1 Myself2 and3 I4&quot;, then remove the numbers.

</pre>



<p>&nbsp;</p>

<p><strong>Constraints:</strong></p>



<ul>
<li><code>2 &lt;= s.length &lt;= 200</code></li>
<li><code>s</code> consists of lowercase and uppercase English letters, spaces, and digits from <code>1</code> to <code>9</code>.</li>
<li>The number of words in <code>s</code> is between <code>1</code> and <code>9</code>.</li>
<li>The words in <code>s</code> are separated by a single space.</li>
<li><code>s</code> contains no leading or trailing spaces.</li>
</ul>

## Solutions

<!-- tabs:start -->

### **Python3**

```python

```

### **Java**

```java

```

### **...**

```

```

<!-- tabs:end -->
77 changes: 77 additions & 0 deletions solution/1800-1899/1860.Incremental Memory Leak/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# [1860. 增长的内存泄露](https://leetcode-cn.com/problems/incremental-memory-leak)

[English Version](/solution/1800-1899/1860.Incremental%20Memory%20Leak/README_EN.md)

## 题目描述

<!-- 这里写题目描述 -->

<p>给你两个整数 <code>memory1</code> 和 <code>memory2</code> 分别表示两个内存条剩余可用内存的位数。现在有一个程序每秒递增的速度消耗着内存。</p>

<p>在第 <code>i</code> 秒(秒数从 1 开始),有 <code>i</code> 位内存被分配到 <strong>剩余内存较多</strong> 的内存条(如果两者一样多,则分配到第一个内存条)。如果两者剩余内存都不足 <code>i</code> 位,那么程序将 <b>意外退出</b> 。</p>

<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>

<p> </p>

<p><strong>示例 1:</strong></p>

<pre><b>输入:</b>memory1 = 2, memory2 = 2
<b>输出:</b>[3,1,0]
<b>解释:</b>内存分配如下:
- 第 1 秒,内存条 1 被占用 1 位内存。内存条 1 现在有 1 位剩余可用内存。
- 第 2 秒,内存条 2 被占用 2 位内存。内存条 2 现在有 0 位剩余可用内存。
- 第 3 秒,程序意外退出,两个内存条分别有 1 位和 0 位剩余可用内存。
</pre>

<p><strong>示例 2:</strong></p>

<pre><b>输入:</b>memory1 = 8, memory2 = 11
<b>输出:</b>[6,0,4]
<b>解释:</b>内存分配如下:
- 第 1 秒,内存条 2 被占用 1 位内存,内存条 2 现在有 10 位剩余可用内存。
- 第 2 秒,内存条 2 被占用 2 位内存,内存条 2 现在有 8 位剩余可用内存。
- 第 3 秒,内存条 1 被占用 3 位内存,内存条 1 现在有 5 位剩余可用内存。
- 第 4 秒,内存条 2 被占用 4 位内存,内存条 2 现在有 4 位剩余可用内存。
- 第 5 秒,内存条 1 被占用 5 位内存,内存条 1 现在有 0 位剩余可用内存。
- 第 6 秒,程序意外退出,两个内存条分别有 0 位和 4 位剩余可用内存。
</pre>

<p> </p>

<p><strong>提示:</strong></p>

<ul>
<li><code>0 &lt;= memory1, memory2 &lt;= 2<sup>31</sup> - 1</code></li>
</ul>


## 解法

<!-- 这里可写通用的实现逻辑 -->

<!-- tabs:start -->

### **Python3**

<!-- 这里可写当前语言的特殊实现逻辑 -->

```python

```

### **Java**

<!-- 这里可写当前语言的特殊实现逻辑 -->

```java

```

### **...**

```

```

<!-- tabs:end -->
Loading