Skip to content

Commit 3041b33

Browse files
authored
feat: add solutions to lc problem: No.2599 (doocs#950)
1 parent 028a87b commit 3041b33

File tree

23 files changed

+516
-57
lines changed

23 files changed

+516
-57
lines changed

solution/0200-0299/0263.Ugly Number/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<pre>
3232
<strong>输入:</strong>n = 14
3333
<strong>输出:</strong>false
34-
<strong>解释:</strong>14 不是丑数,因为它包含了另外一个质因数 7
34+
<strong>解释:</strong>14 不是丑数,因为它包含了另外一个质因数&nbsp;<code>7 </code>
3535
</pre>
3636

3737
<p>&nbsp;</p>

solution/0300-0399/0387.First Unique Character in a String/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class Solution {
188188
return -1;
189189
}
190190
}
191-
```
191+
```
192192

193193
### **...**
194194

solution/0300-0399/0387.First Unique Character in a String/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class Solution {
157157
return -1;
158158
}
159159
}
160-
```
160+
```
161161

162162
### **...**
163163

solution/0600-0699/0605.Can Place Flowers/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<p>You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in <strong>adjacent</strong> plots.</p>
88

9-
<p>Given an integer array <code>flowerbed</code> containing <code>0</code>&#39;s and <code>1</code>&#39;s, where <code>0</code> means empty and <code>1</code> means not empty, and an integer <code>n</code>, return <em>if</em> <code>n</code> new flowers can be planted in the <code>flowerbed</code> without violating the no-adjacent-flowers rule.</p>
9+
<p>Given an integer array <code>flowerbed</code> containing <code>0</code>&#39;s and <code>1</code>&#39;s, where <code>0</code> means empty and <code>1</code> means not empty, and an integer <code>n</code>, return <code>true</code>&nbsp;<em>if</em> <code>n</code> <em>new flowers can be planted in the</em> <code>flowerbed</code> <em>without violating the no-adjacent-flowers rule and</em> <code>false</code> <em>otherwise</em>.</p>
1010

1111
<p>&nbsp;</p>
1212
<p><strong class="example">Example 1:</strong></p>

solution/0600-0699/0665.Non-decreasing Array/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class Solution {
7777
}
7878
return true;
7979
}
80-
80+
8181
private boolean isSorted(int[] nums) {
8282
for (int i = 0; i < nums.length - 1; ++i) {
8383
if (nums[i] > nums[i + 1]) {

solution/1400-1499/1406.Stone Game III/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class Solution {
8383
private int n;
8484
private int[] s;
8585
private Integer[] f;
86-
86+
8787
public String stoneGameIII(int[] stoneValue) {
8888
n = stoneValue.length;
8989
s = new int[n + 1];
@@ -95,7 +95,7 @@ class Solution {
9595
int b = s[n] - a;
9696
return a == b ? "Tie" : a > b ? "Alice" : "Bob";
9797
}
98-
98+
9999
private int dfs(int i) {
100100
if (i >= n) {
101101
return 0;

solution/1600-1699/1630.Arithmetic Subarrays/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@
6363

6464
函数 $check(nums, l, r)$ 的实现逻辑如下:
6565

66-
- 首先,我们计算子数组的长度 $n = r - l + 1$,并将子数组中的元素放入集合 $s$ 中,方便后续的查找;
67-
- 然后,我们获取子数组中的最小值 $a_1$ 和最大值 $a_n$,如果 $a_n - a_1$ 不能被 $n - 1$ 整除,那么子数组不可能形成等差数列,直接返回 $false$;否则,我们计算等差数列的公差 $d = \frac{a_n - a_1}{n - 1}$;
68-
- 接下来从 $a_1$ 开始,依次计算等差数列中第 $i$ 项元素,如果第 $i$ 项元素 $a_1 + (i - 1) \times d$ 不在集合 $s$ 中,那么子数组不可能形成等差数列,直接返回 $false$;否则,当我们遍历完所有的元素,说明子数组可以重新排列形成等差数列,返回 $true$。
66+
- 首先,我们计算子数组的长度 $n = r - l + 1$,并将子数组中的元素放入集合 $s$ 中,方便后续的查找;
67+
- 然后,我们获取子数组中的最小值 $a_1$ 和最大值 $a_n$,如果 $a_n - a_1$ 不能被 $n - 1$ 整除,那么子数组不可能形成等差数列,直接返回 $false$;否则,我们计算等差数列的公差 $d = \frac{a_n - a_1}{n - 1}$;
68+
- 接下来从 $a_1$ 开始,依次计算等差数列中第 $i$ 项元素,如果第 $i$ 项元素 $a_1 + (i - 1) \times d$ 不在集合 $s$ 中,那么子数组不可能形成等差数列,直接返回 $false$;否则,当我们遍历完所有的元素,说明子数组可以重新排列形成等差数列,返回 $true$。
6969

7070
在主函数中,我们遍历所有的查询,对于每个查询 $l[i]$ 和 $r[i]$,我们调用函数 $check(nums, l[i], r[i])$ 判断子数组是否可以重新排列形成等差数列,将结果存入答案数组中。
7171

@@ -86,7 +86,7 @@ class Solution:
8686
a1, an = min(nums[l: l + n]), max(nums[l: l + n])
8787
d, mod = divmod(an - a1, n - 1)
8888
return mod == 0 and all((a1 + (i - 1) * d) in s for i in range(1, n))
89-
89+
9090
return [check(nums, left, right) for left, right in zip(l, r)]
9191
```
9292

solution/1600-1699/1630.Arithmetic Subarrays/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class Solution:
6868
a1, an = min(nums[l: l + n]), max(nums[l: l + n])
6969
d, mod = divmod(an - a1, n - 1)
7070
return mod == 0 and all((a1 + (i - 1) * d) in s for i in range(1, n))
71-
71+
7272
return [check(nums, left, right) for left, right in zip(l, r)]
7373
```
7474

solution/1600-1699/1638.Count Substrings That Differ by One Character/README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66

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

9-
<p>给你两个字符串 <code>s</code> 和 <code>t</code> ,请你找出 <code>s</code> 中的非空子串的数目,这些子串满足替换 <strong>一个不同字符</strong> 以后,是 <code>t</code> 串的子串。换言之,请你找到 <code>s</code> 和 <code>t</code> 串中 <strong>恰好</strong> 只有一个字符不同的子字符串对的数目。</p>
9+
<p>给你两个字符串&nbsp;<code>s</code> 和&nbsp;<code>t</code>&nbsp;,请你找出 <code>s</code>&nbsp;中的非空子串的数目,这些子串满足替换 <strong>一个不同字符</strong>&nbsp;以后,是 <code>t</code>&nbsp;串的子串。换言之,请你找到 <code>s</code>&nbsp;和 <code>t</code>&nbsp;串中 <strong>恰好</strong>&nbsp;只有一个字符不同的子字符串对的数目。</p>
1010

11-
<p>比方说, <code>"<strong>compute</strong>r"</code> 和 <code>"<strong>computa</strong>tion"</code> 加粗部分只有一个字符不同: <code>'e'</code>/<code>'a'</code> ,所以这一对子字符串会给答案加 1 。</p>
11+
<p>比方说,&nbsp;<code>"<u>compute</u>r"</code>&nbsp;and&nbsp;<code>"<u>computa</u>tion"&nbsp;</code>只有一个字符不同:&nbsp;<code>'e'</code>/<code>'a'</code>&nbsp;,所以这一对子字符串会给答案加 1 。</p>
1212

1313
<p>请你返回满足上述条件的不同子字符串对数目。</p>
1414

15-
<p>一个 <strong>子字符串</strong> 是一个字符串中连续的字符。</p>
15+
<p>一个 <strong>子字符串</strong>&nbsp;是一个字符串中连续的字符。</p>
1616

17-
<p> </p>
17+
<p>&nbsp;</p>
1818

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

@@ -57,13 +57,13 @@
5757
<b>输出:</b>10
5858
</pre>
5959

60-
<p> </p>
60+
<p>&nbsp;</p>
6161

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

6464
<ul>
65-
<li><code>1 <= s.length, t.length <= 100</code></li>
66-
<li><code>s</code> 和 <code>t</code> 都只包含小写英文字母。</li>
65+
<li><code>1 &lt;= s.length, t.length &lt;= 100</code></li>
66+
<li><code>s</code> 和&nbsp;<code>t</code>&nbsp;都只包含小写英文字母。</li>
6767
</ul>
6868

6969
## 解法

solution/1700-1799/1760.Minimum Limit of Balls in a Bag/README_EN.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010

1111
<ul>
1212
<li>Take any bag of balls and divide it into two new bags with a <strong>positive </strong>number of balls.
13+
1314
<ul>
1415
<li>For example, a bag of <code>5</code> balls can become two new bags of <code>1</code> and <code>4</code> balls, or two new bags of <code>2</code> and <code>3</code> balls.</li>
1516
</ul>
1617
</li>
18+
1719
</ul>
1820

1921
<p>Your penalty is the <strong>maximum</strong> number of balls in a bag. You want to <strong>minimize</strong> your penalty after the operations.</p>

solution/1900-1999/1943.Describe the Painting/README.md

+10-7
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,19 @@
3636
<p>&nbsp;</p>
3737

3838
<p><strong>示例 1:</strong></p>
39-
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1900-1999/1943.Describe%20the%20Painting/images/1.png" style="width: 529px; height: 241px;">
40-
<pre><b>输入:</b>segments = [[1,4,5],[4,7,7],[1,7,9]]
39+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1900-1999/1943.Describe%20the%20Painting/images/1.png" style="width: 529px; height: 241px;" />
40+
<pre>
41+
<b>输入:</b>segments = [[1,4,5],[4,7,7],[1,7,9]]
4142
<b>输出:</b>[[1,4,14],[4,7,16]]
42-
<strong>解释:</strong>绘画借故偶可以表示为
43+
<strong>解释:</strong>绘画结果可以表示为
4344
- [1,4) 颜色为 {5,9} (和为 14),分别来自第一和第二个线段。
4445
- [4,7) 颜色为 {7,9} (和为 16),分别来自第二和第三个线段。
4546
</pre>
4647

4748
<p><strong>示例 2:</strong></p>
48-
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1900-1999/1943.Describe%20the%20Painting/images/2.png" style="width: 532px; height: 219px;">
49-
<pre><b>输入:</b>segments = [[1,7,9],[6,8,15],[8,10,7]]
49+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1900-1999/1943.Describe%20the%20Painting/images/2.png" style="width: 532px; height: 219px;" />
50+
<pre>
51+
<b>输入:</b>segments = [[1,7,9],[6,8,15],[8,10,7]]
5052
<b>输出:</b>[[1,6,9],[6,7,24],[7,8,15],[8,10,7]]
5153
<b>解释:</b>绘画结果可以以表示为:
5254
- [1,6) 颜色为 9 ,来自第一个线段。
@@ -56,8 +58,9 @@
5658
</pre>
5759

5860
<p><strong>示例 3:</strong></p>
59-
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1900-1999/1943.Describe%20the%20Painting/images/c1.png" style="width: 529px; height: 289px;">
60-
<pre><b>输入:</b>segments = [[1,4,5],[1,4,7],[4,7,1],[4,7,11]]
61+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1900-1999/1943.Describe%20the%20Painting/images/c1.png" style="width: 529px; height: 289px;" />
62+
<pre>
63+
<b>输入:</b>segments = [[1,4,5],[1,4,7],[4,7,1],[4,7,11]]
6164
<b>输出:</b>[[1,4,12],[4,7,12]]
6265
<strong>解释:</strong>绘画结果可以表示为:
6366
- [1,4) 颜色为 {5,7} (和为 12),分别来自第一和第二个线段。

solution/2200-2299/2251.Number of Flowers in Full Bloom/README_EN.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
## Description
66

7-
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>flowers</code>, where <code>flowers[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means the <code>i<sup>th</sup></code> flower will be in <strong>full bloom</strong> from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> (<strong>inclusive</strong>). You are also given a <strong>0-indexed</strong> integer array <code>persons</code> of size <code>n</code>, where <code>persons[i]</code> is the time that the <code>i<sup>th</sup></code> person will arrive to see the flowers.</p>
7+
<p>You are given a <strong>0-indexed</strong> 2D integer array <code>flowers</code>, where <code>flowers[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> means the <code>i<sup>th</sup></code> flower will be in <strong>full bloom</strong> from <code>start<sub>i</sub></code> to <code>end<sub>i</sub></code> (<strong>inclusive</strong>). You are also given a <strong>0-indexed</strong> integer array <code>people</code> of size <code>n</code>, where <code>poeple[i]</code> is the time that the <code>i<sup>th</sup></code> person will arrive to see the flowers.</p>
88

99
<p>Return <em>an integer array </em><code>answer</code><em> of size </em><code>n</code><em>, where </em><code>answer[i]</code><em> is the <strong>number</strong> of flowers that are in full bloom when the </em><code>i<sup>th</sup></code><em> person arrives.</em></p>
1010

1111
<p>&nbsp;</p>
1212
<p><strong class="example">Example 1:</strong></p>
1313
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2200-2299/2251.Number%20of%20Flowers%20in%20Full%20Bloom/images/ex1new.jpg" style="width: 550px; height: 216px;" />
1414
<pre>
15-
<strong>Input:</strong> flowers = [[1,6],[3,7],[9,12],[4,13]], persons = [2,3,7,11]
15+
<strong>Input:</strong> flowers = [[1,6],[3,7],[9,12],[4,13]], poeple = [2,3,7,11]
1616
<strong>Output:</strong> [1,2,2,2]
1717
<strong>Explanation: </strong>The figure above shows the times when the flowers are in full bloom and when the people arrive.
1818
For each person, we return the number of flowers in full bloom during their arrival.
@@ -21,7 +21,7 @@ For each person, we return the number of flowers in full bloom during their arri
2121
<p><strong class="example">Example 2:</strong></p>
2222
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2200-2299/2251.Number%20of%20Flowers%20in%20Full%20Bloom/images/ex2new.jpg" style="width: 450px; height: 195px;" />
2323
<pre>
24-
<strong>Input:</strong> flowers = [[1,10],[3,3]], persons = [3,3,2]
24+
<strong>Input:</strong> flowers = [[1,10],[3,3]], poeple = [3,3,2]
2525
<strong>Output:</strong> [2,2,1]
2626
<strong>Explanation:</strong> The figure above shows the times when the flowers are in full bloom and when the people arrive.
2727
For each person, we return the number of flowers in full bloom during their arrival.
@@ -34,8 +34,8 @@ For each person, we return the number of flowers in full bloom during their arri
3434
<li><code>1 &lt;= flowers.length &lt;= 5 * 10<sup>4</sup></code></li>
3535
<li><code>flowers[i].length == 2</code></li>
3636
<li><code>1 &lt;= start<sub>i</sub> &lt;= end<sub>i</sub> &lt;= 10<sup>9</sup></code></li>
37-
<li><code>1 &lt;= persons.length &lt;= 5 * 10<sup>4</sup></code></li>
38-
<li><code>1 &lt;= persons[i] &lt;= 10<sup>9</sup></code></li>
37+
<li><code>1 &lt;= people.length &lt;= 5 * 10<sup>4</sup></code></li>
38+
<li><code>1 &lt;= people[i] &lt;= 10<sup>9</sup></code></li>
3939
</ul>
4040

4141
## Solutions

0 commit comments

Comments
 (0)