Skip to content

Commit d743a81

Browse files
committed
feat: add solutions to lc problems: No.2481~2488
* No.2481.Minimum Cuts to Divide a Circle * No.2482.Difference Between Ones and Zeros in Row and Column * No.2483.Minimum Penalty for a Shop * No.2484.Count Palindromic Subsequences * No.2485.Find the Pivot Integer * No.2486.Append Characters to String to Make Subsequence * No.2487.Remove Nodes From Linked List * No.2488.Count Subarrays With Median K
1 parent fb86085 commit d743a81

File tree

74 files changed

+3584
-61
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+3584
-61
lines changed

lcp/LCP 52. 二叉搜索树染色/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
3333
**示例 2:**
3434

35-
> 输入:`root = [4,2,7,1,null,5,null,null,null,null,6]`
36-
> `ops = [[0,2,2],[1,1,5],[0,4,5],[1,5,7]]`
35+
> 输入:`root = [4,2,7,1,null,5,null,null,null,null,6]` > `ops = [[0,2,2],[1,1,5],[0,4,5],[1,5,7]]`
3736
>
3837
> 输出:`5`
3938
>

lcp/LCP 61. 气温变化趋势/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
>
2323
> 输出:`2`
2424
>
25-
> 解释:如下表所示, 第 `2~4` 天两地气温变化趋势相同,且持续时间最长,因此返回 `4-2=2`
26-
> ![image.png](https://fastly.jsdelivr.net/gh/doocs/leetcode@main/lcp/LCP%2061.%20%E6%B0%94%E6%B8%A9%E5%8F%98%E5%8C%96%E8%B6%8B%E5%8A%BF/images/1663902654-hlrSvs-image.png)
25+
> 解释:如下表所示, 第 `2~4` 天两地气温变化趋势相同,且持续时间最长,因此返回 `4-2=2` > ![image.png](https://fastly.jsdelivr.net/gh/doocs/leetcode@main/lcp/LCP%2061.%20%E6%B0%94%E6%B8%A9%E5%8F%98%E5%8C%96%E8%B6%8B%E5%8A%BF/images/1663902654-hlrSvs-image.png)
2726
2827
**示例 2:**
2928

solution/0400-0499/0467.Unique Substrings in Wraparound String/README_EN.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,45 @@
44

55
## Description
66

7-
<p>We define the string <code>s</code> to be the infinite wraparound string of <code>&quot;abcdefghijklmnopqrstuvwxyz&quot;</code>, so <code>s</code> will look like this:</p>
7+
<p>We define the string <code>base</code> to be the infinite wraparound string of <code>&quot;abcdefghijklmnopqrstuvwxyz&quot;</code>, so <code>base</code> will look like this:</p>
88

99
<ul>
1010
<li><code>&quot;...zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd....&quot;</code>.</li>
1111
</ul>
1212

13-
<p>Given a string <code>p</code>, return <em>the number of <strong>unique non-empty substrings</strong> of </em><code>p</code><em> are present in </em><code>s</code>.</p>
13+
<p>Given a string <code>s</code>, return <em>the number of <strong>unique non-empty substrings</strong> of </em><code>s</code><em> are present in </em><code>base</code>.</p>
1414

1515
<p>&nbsp;</p>
1616
<p><strong class="example">Example 1:</strong></p>
1717

1818
<pre>
19-
<strong>Input:</strong> p = &quot;a&quot;
19+
<strong>Input:</strong> s = &quot;a&quot;
2020
<strong>Output:</strong> 1
21-
Explanation: Only the substring &quot;a&quot; of p is in s.
21+
<strong>Explanation:</strong> Only the substring &quot;a&quot; of s is in base.
2222
</pre>
2323

2424
<p><strong class="example">Example 2:</strong></p>
2525

2626
<pre>
27-
<strong>Input:</strong> p = &quot;cac&quot;
27+
<strong>Input:</strong> s = &quot;cac&quot;
2828
<strong>Output:</strong> 2
29-
<strong>Explanation:</strong> There are two substrings (&quot;a&quot;, &quot;c&quot;) of p in s.
29+
<strong>Explanation:</strong> There are two substrings (&quot;a&quot;, &quot;c&quot;) of s in base.
3030
</pre>
3131

3232
<p><strong class="example">Example 3:</strong></p>
3333

3434
<pre>
35-
<strong>Input:</strong> p = &quot;zab&quot;
35+
<strong>Input:</strong> s = &quot;zab&quot;
3636
<strong>Output:</strong> 6
37-
<strong>Explanation:</strong> There are six substrings (&quot;z&quot;, &quot;a&quot;, &quot;b&quot;, &quot;za&quot;, &quot;ab&quot;, and &quot;zab&quot;) of p in s.
37+
<strong>Explanation:</strong> There are six substrings (&quot;z&quot;, &quot;a&quot;, &quot;b&quot;, &quot;za&quot;, &quot;ab&quot;, and &quot;zab&quot;) of s in base.
3838
</pre>
3939

4040
<p>&nbsp;</p>
4141
<p><strong>Constraints:</strong></p>
4242

4343
<ul>
44-
<li><code>1 &lt;= p.length &lt;= 10<sup>5</sup></code></li>
45-
<li><code>p</code> consists of lowercase English letters.</li>
44+
<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
45+
<li><code>s</code> consists of lowercase English letters.</li>
4646
</ul>
4747

4848
## Solutions

solution/0500-0599/0587.Erect the Fence/README_EN.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,35 @@
66

77
<p>You are given an array <code>trees</code> where <code>trees[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents the ___location of a tree in the garden.</p>
88

9-
<p>You are asked to fence the entire garden using the minimum length of rope as it is expensive. The garden is well fenced only if <strong>all the trees are enclosed</strong>.</p>
9+
<p>Fence the entire garden using the minimum length of rope, as it is expensive. The garden is well-fenced only if <strong>all the trees are enclosed</strong>.</p>
1010

11-
<p>Return <em>the coordinates of trees that are exactly located on the fence perimeter</em>.</p>
11+
<p>Return <em>the coordinates of trees that are exactly located on the fence perimeter</em>. You may return the answer in <strong>any order</strong>.</p>
1212

1313
<p>&nbsp;</p>
1414
<p><strong class="example">Example 1:</strong></p>
15-
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0500-0599/0587.Erect%20the%20Fence/images/erect2-plane.jpg" style="width: 509px; height: 500px;" />
15+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0500-0599/0587.Erect%20the%20Fence/images/erect2-plane.jpg" style="width: 400px; height: 393px;" />
1616
<pre>
17-
<strong>Input:</strong> points = [[1,1],[2,2],[2,0],[2,4],[3,3],[4,2]]
18-
<strong>Output:</strong> [[1,1],[2,0],[3,3],[2,4],[4,2]]
17+
<strong>Input:</strong> trees = [[1,1],[2,2],[2,0],[2,4],[3,3],[4,2]]
18+
<strong>Output:</strong> [[1,1],[2,0],[4,2],[3,3],[2,4]]
19+
<strong>Explanation:</strong> All the trees will be on the perimeter of the fence except the tree at [2, 2], which will be inside the fence.
1920
</pre>
2021

2122
<p><strong class="example">Example 2:</strong></p>
22-
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0500-0599/0587.Erect%20the%20Fence/images/erect1-plane.jpg" style="width: 509px; height: 500px;" />
23+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0500-0599/0587.Erect%20the%20Fence/images/erect1-plane.jpg" style="width: 400px; height: 393px;" />
2324
<pre>
24-
<strong>Input:</strong> points = [[1,2],[2,2],[4,2]]
25+
<strong>Input:</strong> trees = [[1,2],[2,2],[4,2]]
2526
<strong>Output:</strong> [[4,2],[2,2],[1,2]]
27+
<strong>Explanation:</strong> The fence forms a line that passes through all the trees.
2628
</pre>
2729

2830
<p>&nbsp;</p>
2931
<p><strong>Constraints:</strong></p>
3032

3133
<ul>
32-
<li><code>1 &lt;= points.length &lt;= 3000</code></li>
33-
<li><code>points[i].length == 2</code></li>
34+
<li><code>1 &lt;= trees.length &lt;= 3000</code></li>
35+
<li><code>trees[i].length == 2</code></li>
3436
<li><code>0 &lt;= x<sub>i</sub>, y<sub>i</sub> &lt;= 100</code></li>
35-
<li>All the given points are <strong>unique</strong>.</li>
37+
<li>All the given positions are <strong>unique</strong>.</li>
3638
</ul>
3739

3840
## Solutions

solution/0600-0699/0608.Tree Node/README_EN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ The given structure is always a valid tree.
3030

3131
<p>Write an SQL query to report the type of each node in the tree.</p>
3232

33-
<p>Return the result table <strong>ordered</strong> by <code>id</code> <strong>in ascending order</strong>.</p>
33+
<p>Return the result table in <strong>any order</strong>.</p>
3434

3535
<p>The query result format is in the following example.</p>
3636

solution/0800-0899/0809.Expressive Words/README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,36 @@
66

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

9-
<p>有时候人们会用重复写一些字母来表示额外的感受,比如 <code>"hello" -> "heeellooo"</code>, <code>"hi" -> "hiii"</code>。我们将相邻字母都相同的一串字符定义为相同字母组,例如:"h", "eee", "ll", "ooo"。</p>
9+
<p>有时候人们会用重复写一些字母来表示额外的感受,比如 <code>"hello" -&gt; "heeellooo"</code>, <code>"hi" -&gt; "hiii"</code>。我们将相邻字母都相同的一串字符定义为相同字母组,例如:"h", "eee", "ll", "ooo"。</p>
1010

11-
<p>对于一个给定的字符串 S ,如果另一个单词能够通过将一些字母组扩张从而使其和 S 相同,我们将这个单词定义为可扩张的(stretchy)。扩张操作定义如下:选择一个字母组(包含字母 <code>c</code> ),然后往其中添加相同的字母 <code>c</code> 使其长度达到 3 或以上。</p>
11+
<p>对于一个给定的字符串 S ,如果另一个单词能够通过将一些字母组扩张从而使其和 S 相同,我们将这个单词定义为可扩张的(stretchy)。扩张操作定义如下:选择一个字母组(包含字母&nbsp;<code>c</code>&nbsp;),然后往其中添加相同的字母&nbsp;<code>c</code>&nbsp;使其长度达到 3 或以上。</p>
1212

13-
<p>例如,以 "hello" 为例,我们可以对字母组 "o" 扩张得到 "hellooo",但是无法以同样的方法得到 "helloo" 因为字母组 "oo" 长度小于 3。此外,我们可以进行另一种扩张 "ll" -> "lllll" 以获得 "helllllooo"。如果 <code>S = "helllllooo"</code>,那么查询词 "hello" 是可扩张的,因为可以对它执行这两种扩张操作使得 <code>query = "hello" -> "hellooo" -"helllllooo" = S</code>。</p>
13+
<p>例如,以&nbsp;"hello" 为例,我们可以对字母组&nbsp;"o" 扩张得到 "hellooo",但是无法以同样的方法得到 "helloo" 因为字母组 "oo" 长度小于&nbsp;3。此外,我们可以进行另一种扩张 "ll" -&gt; "lllll" 以获得&nbsp;"helllllooo"。如果&nbsp;<code>s = "helllllooo"</code>,那么查询词&nbsp;"hello" 是可扩张的,因为可以对它执行这两种扩张操作使得&nbsp;<code>query = "hello" -&gt; "hellooo" -&gt;&nbsp;"helllllooo" = s</code>。</p>
1414

1515
<p>输入一组查询单词,输出其中可扩张的单词数量。</p>
1616

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

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

2121
<pre>
2222
<strong>输入:</strong>
23-
S = "heeellooo"
23+
s = "heeellooo"
2424
words = ["hello", "hi", "helo"]
2525
<strong>输出:</strong>1
2626
<strong>解释</strong>:
2727
我们能通过扩张 "hello" 的 "e" 和 "o" 来得到 "heeellooo"。
2828
我们不能通过扩张 "helo" 来得到 "heeellooo" 因为 "ll" 的长度小于 3 。
2929
</pre>
3030

31-
<p> </p>
31+
<p>&nbsp;</p>
3232

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

3535
<ul>
36-
<li><code>0 <= len(S) <= 100</code>。</li>
37-
<li><code>0 <= len(words) <= 100</code>。</li>
38-
<li><code>0 <= len(words[i]) <= 100</code>。</li>
39-
<li><code>S</code> 和所有在 <code>words</code> 中的单词都只由小写字母组成。</li>
36+
<li><code>1 &lt;= s.length, words.length &lt;= 100</code></li>
37+
<li><code>1 &lt;= words[i].length &lt;= 100</code></li>
38+
<li><font color="#c7254e" face="Menlo, Monaco, Consolas, Courier New, monospace"><span style="font-size: 12.6px; background-color: rgb(249, 242, 244);">s</span></font> 和所有在&nbsp;<code>words</code>&nbsp;中的单词都只由小写字母组成。</li>
4039
</ul>
4140

4241
## 解法

solution/1700-1799/1752.Check if Array Is Sorted and Rotated/README.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@
7272
```python
7373
class Solution:
7474
def check(self, nums: List[int]) -> bool:
75-
n = len(nums)
76-
return sum(v > nums[(i + 1) % n] for i, v in enumerate(nums)) <= 1
75+
return sum(v > nums[(i + 1) % len(nums)] for i, v in enumerate(nums)) <= 1
7776
```
7877

7978
### **Java**
@@ -83,9 +82,8 @@ class Solution:
8382
```java
8483
class Solution {
8584
public boolean check(int[] nums) {
86-
int n = nums.length;
8785
int cnt = 0;
88-
for (int i = 0; i < n; ++i) {
86+
for (int i = 0, n = nums.length; i < n; ++i) {
8987
if (nums[i] > nums[(i + 1) % n]) {
9088
++cnt;
9189
}
@@ -101,9 +99,8 @@ class Solution {
10199
class Solution {
102100
public:
103101
bool check(vector<int>& nums) {
104-
int n = nums.size();
105102
int cnt = 0;
106-
for (int i = 0; i < n; ++i) {
103+
for (int i = 0, n = nums.size(); i < n; ++i) {
107104
cnt += nums[i] > (nums[(i + 1) % n]);
108105
}
109106
return cnt <= 1;
@@ -115,10 +112,9 @@ public:
115112
116113
```go
117114
func check(nums []int) bool {
118-
n := len(nums)
119115
cnt := 0
120116
for i, v := range nums {
121-
if v > nums[(i+1)%n] {
117+
if v > nums[(i+1)%len(nums)] {
122118
cnt++
123119
}
124120
}

solution/1700-1799/1752.Check if Array Is Sorted and Rotated/README_EN.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,16 @@ You can rotate the array by x = 0 positions (i.e. no rotation) to make nums.
5454
```python
5555
class Solution:
5656
def check(self, nums: List[int]) -> bool:
57-
n = len(nums)
58-
return sum(v > nums[(i + 1) % n] for i, v in enumerate(nums)) <= 1
57+
return sum(v > nums[(i + 1) % len(nums)] for i, v in enumerate(nums)) <= 1
5958
```
6059

6160
### **Java**
6261

6362
```java
6463
class Solution {
6564
public boolean check(int[] nums) {
66-
int n = nums.length;
6765
int cnt = 0;
68-
for (int i = 0; i < n; ++i) {
66+
for (int i = 0, n = nums.length; i < n; ++i) {
6967
if (nums[i] > nums[(i + 1) % n]) {
7068
++cnt;
7169
}
@@ -81,9 +79,8 @@ class Solution {
8179
class Solution {
8280
public:
8381
bool check(vector<int>& nums) {
84-
int n = nums.size();
8582
int cnt = 0;
86-
for (int i = 0; i < n; ++i) {
83+
for (int i = 0, n = nums.size(); i < n; ++i) {
8784
cnt += nums[i] > (nums[(i + 1) % n]);
8885
}
8986
return cnt <= 1;
@@ -95,10 +92,9 @@ public:
9592
9693
```go
9794
func check(nums []int) bool {
98-
n := len(nums)
9995
cnt := 0
10096
for i, v := range nums {
101-
if v > nums[(i+1)%n] {
97+
if v > nums[(i+1)%len(nums)] {
10298
cnt++
10399
}
104100
}

solution/1700-1799/1752.Check if Array Is Sorted and Rotated/Solution.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
class Solution {
22
public:
33
bool check(vector<int>& nums) {
4-
int n = nums.size();
54
int cnt = 0;
6-
for (int i = 0; i < n; ++i) {
5+
for (int i = 0, n = nums.size(); i < n; ++i) {
76
cnt += nums[i] > (nums[(i + 1) % n]);
87
}
98
return cnt <= 1;

solution/1700-1799/1752.Check if Array Is Sorted and Rotated/Solution.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
func check(nums []int) bool {
2-
n := len(nums)
32
cnt := 0
43
for i, v := range nums {
5-
if v > nums[(i+1)%n] {
4+
if v > nums[(i+1)%len(nums)] {
65
cnt++
76
}
87
}

0 commit comments

Comments
 (0)