Skip to content

Commit b529cef

Browse files
authored
feat: add new lc problems (#4617)
1 parent fa0b9d1 commit b529cef

File tree

23 files changed

+13766
-3648
lines changed

23 files changed

+13766
-3648
lines changed

solution/0000-0099/0098.Validate Binary Search Tree/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ tags:
2424
<p><strong>有效</strong> 二叉搜索树定义如下:</p>
2525

2626
<ul>
27-
<li>节点的左<span data-keyword="subtree">子树</span>只包含<strong> 小于 </strong>当前节点的数。</li>
28-
<li>节点的右子树只包含 <strong>大于</strong> 当前节点的数。</li>
27+
<li>节点的左<span data-keyword="subtree">子树</span>只包含<strong>&nbsp;严格小于 </strong>当前节点的数。</li>
28+
<li>节点的右子树只包含 <strong>严格大于</strong> 当前节点的数。</li>
2929
<li>所有左子树和右子树自身必须也是二叉搜索树。</li>
3030
</ul>
3131

solution/0000-0099/0098.Validate Binary Search Tree/README_EN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ tags:
2424
<p>A <strong>valid BST</strong> is defined as follows:</p>
2525

2626
<ul>
27-
<li>The left <span data-keyword="subtree">subtree</span> of a node contains only nodes with keys <strong>less than</strong> the node&#39;s key.</li>
28-
<li>The right subtree of a node contains only nodes with keys <strong>greater than</strong> the node&#39;s key.</li>
27+
<li>The left <span data-keyword="subtree">subtree</span> of a node contains only nodes with keys&nbsp;<strong>strictly less than</strong> the node&#39;s key.</li>
28+
<li>The right subtree of a node contains only nodes with keys <strong>strictly greater than</strong> the node&#39;s key.</li>
2929
<li>Both the left and right subtrees must also be binary search trees.</li>
3030
</ul>
3131

solution/0100-0199/0135.Candy/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ tags:
2323

2424
<ul>
2525
<li>每个孩子至少分配到 <code>1</code> 个糖果。</li>
26-
<li>相邻两个孩子评分更高的孩子会获得更多的糖果。</li>
26+
<li>相邻两个孩子中,评分更高的那个会获得更多的糖果。</li>
2727
</ul>
2828

2929
<p>请你给每个孩子分发糖果,计算并返回需要准备的 <strong>最少糖果数目</strong> 。</p>

solution/0400-0499/0472.Concatenated Words/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ tags:
88
- 数组
99
- 字符串
1010
- 动态规划
11+
- 排序
1112
---
1213

1314
<!-- problem:start -->

solution/0400-0499/0472.Concatenated Words/README_EN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ tags:
88
- Array
99
- String
1010
- Dynamic Programming
11+
- Sorting
1112
---
1213

1314
<!-- problem:start -->

solution/0400-0499/0499.The Maze III/README_EN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ tags:
2323

2424
<!-- description:start -->
2525

26-
<p>There is a ball in a <code>maze</code> with empty spaces (represented as <code>0</code>) and walls (represented as <code>1</code>). The ball can go through the empty spaces by rolling <strong>up, down, left or right</strong>, but it won&#39;t stop rolling until hitting a wall. When the ball stops, it could choose the next direction. There is also a hole in this maze. The ball will drop into the hole if it rolls onto the hole.</p>
26+
<p>There is a ball in a <code>maze</code> with empty spaces (represented as <code>0</code>) and walls (represented as <code>1</code>). The ball can go through the empty spaces by rolling <strong>up, down, left or right</strong>, but it won&#39;t stop rolling until hitting a wall. When the ball stops, it could choose the next direction (must be different from last chosen direction). There is also a hole in this maze. The ball will drop into the hole if it rolls onto the hole.</p>
2727

2828
<p>Given the <code>m x n</code> <code>maze</code>, the ball&#39;s position <code>ball</code> and the hole&#39;s position <code>hole</code>, where <code>ball = [ball<sub>row</sub>, ball<sub>col</sub>]</code> and <code>hole = [hole<sub>row</sub>, hole<sub>col</sub>]</code>, return <em>a string </em><code>instructions</code><em> of all the instructions that the ball should follow to drop in the hole with the <strong>shortest distance</strong> possible</em>. If there are multiple valid instructions, return the <strong>lexicographically minimum</strong> one. If the ball can&#39;t drop in the hole, return <code>&quot;impossible&quot;</code>.</p>
2929

solution/2100-2199/2106.Maximum Fruits Harvested After at Most K Steps/README_EN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ tags:
3333
<pre>
3434
<strong>Input:</strong> fruits = [[2,8],[6,3],[8,6]], startPos = 5, k = 4
3535
<strong>Output:</strong> 9
36-
<strong>Explanation:</strong>
36+
<strong>Explanation:</strong>
3737
The optimal way is to:
3838
- Move right to position 6 and harvest 3 fruits
3939
- Move right to position 8 and harvest 6 fruits
@@ -45,7 +45,7 @@ You moved 3 steps and harvested 3 + 6 = 9 fruits in total.
4545
<pre>
4646
<strong>Input:</strong> fruits = [[0,9],[4,1],[5,7],[6,2],[7,4],[10,9]], startPos = 5, k = 4
4747
<strong>Output:</strong> 14
48-
<strong>Explanation:</strong>
48+
<strong>Explanation:</strong>
4949
You can move at most k = 4 steps, so you cannot reach position 0 nor 10.
5050
The optimal way is to:
5151
- Harvest the 7 fruits at the starting position 5

solution/2500-2599/2561.Rearranging Fruits/README_EN.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ tags:
2424
<p>You have two fruit baskets containing <code>n</code> fruits each. You are given two <strong>0-indexed</strong> integer arrays <code>basket1</code> and <code>basket2</code> representing the cost of fruit in each basket. You want to make both baskets <strong>equal</strong>. To do so, you can use the following operation as many times as you want:</p>
2525

2626
<ul>
27-
<li>Chose two indices <code>i</code> and <code>j</code>, and swap the <code>i<font size="1">th</font>&nbsp;</code>fruit of <code>basket1</code> with the <code>j<font size="1">th</font></code>&nbsp;fruit of <code>basket2</code>.</li>
28-
<li>The cost of the swap is <code>min(basket1[i],basket2[j])</code>.</li>
27+
<li>Choose two indices <code>i</code> and <code>j</code>, and swap the <code>i<sup><font size="1">th</font></sup></code> fruit of <code>basket1</code> with the <code>j<sup><font size="1">th</font></sup></code> fruit of <code>basket2</code>.</li>
28+
<li>The cost of the swap is <code>min(basket1[i], basket2[j])</code>.</li>
2929
</ul>
3030

3131
<p>Two baskets are considered equal if sorting them according to the fruit cost makes them exactly the same baskets.</p>
@@ -55,7 +55,7 @@ tags:
5555
<ul>
5656
<li><code>basket1.length == basket2.length</code></li>
5757
<li><code>1 &lt;= basket1.length &lt;= 10<sup>5</sup></code></li>
58-
<li><code>1 &lt;= basket1[i],basket2[i]&nbsp;&lt;= 10<sup>9</sup></code></li>
58+
<li><code>1 &lt;= basket1[i], basket2[i] &lt;= 10<sup>9</sup></code></li>
5959
</ul>
6060

6161
<!-- description:end -->
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
comments: true
3+
difficulty: 简单
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3600-3699/3637.Trionic%20Array%20I/README.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3637. 三段式数组 I](https://leetcode.cn/problems/trionic-array-i)
10+
11+
[English Version](/solution/3600-3699/3637.Trionic%20Array%20I/README_EN.md)
12+
13+
## 题目描述
14+
15+
<!-- description:start -->
16+
17+
<p data-end="128" data-start="0">给你一个长度为 <code data-end="51" data-start="48">n</code> 的整数数组 <code data-end="37" data-start="31">nums</code>。</p>
18+
19+
<p data-end="128" data-start="0">如果存在索引 <code data-end="117" data-start="100">0 &lt; p &lt; q &lt; n − 1</code>,使得数组满足以下条件,则称其为 <strong data-end="76" data-start="65">三段式数组(trionic)</strong>:</p>
20+
21+
<ul>
22+
<li data-end="170" data-start="132"><code data-end="144" data-start="132">nums[0...p]</code>&nbsp;<strong>严格</strong> 递增,</li>
23+
<li data-end="211" data-start="173"><code data-end="185" data-start="173">nums[p...q]</code>&nbsp;<strong>严格</strong> 递减,</li>
24+
<li data-end="252" data-start="214"><code data-end="228" data-start="214">nums[q...n − 1]</code>&nbsp;<strong>严格</strong> 递增。</li>
25+
</ul>
26+
27+
<p data-end="315" data-is-last-node="" data-is-only-node="" data-start="254">如果 <code data-end="277" data-start="271">nums</code> 是三段式数组,返回 <code data-end="267" data-start="261">true</code>;否则,返回 <code data-end="314" data-start="307">false</code>。</p>
28+
29+
<p>&nbsp;</p>
30+
31+
<p><strong class="example">示例 1:</strong></p>
32+
33+
<div class="example-block">
34+
<p><strong>输入:</strong> <span class="example-io">nums = [1,3,5,4,2,6]</span></p>
35+
36+
<p><strong>输出:</strong> <span class="example-io">true</span></p>
37+
38+
<p><strong>解释:</strong></p>
39+
40+
<p>选择 <code data-end="91" data-start="84">p = 2</code>, <code data-end="100" data-start="93">q = 4</code>:</p>
41+
42+
<ul>
43+
<li><code data-end="130" data-start="108">nums[0...2] = [1, 3, 5]</code> 严格递增&nbsp;(<code data-end="166" data-start="155">1 &lt; 3 &lt; 5</code>)。</li>
44+
<li><code data-end="197" data-start="175">nums[2...4] = [5, 4, 2]</code> 严格递减&nbsp;(<code data-end="233" data-start="222">5 &gt; 4 &gt; 2</code>)。</li>
45+
<li><code data-end="262" data-start="242">nums[4...5] = [2, 6]</code> 严格递增&nbsp;(<code data-end="294" data-start="287">2 &lt; 6</code>)。</li>
46+
</ul>
47+
</div>
48+
49+
<p><strong class="example">示例 2:</strong></p>
50+
51+
<div class="example-block">
52+
<p><strong>输入:</strong> <span class="example-io">nums = [2,1,3]</span></p>
53+
54+
<p><strong>输出:</strong> <span class="example-io">false</span></p>
55+
56+
<p><strong>解释:</strong></p>
57+
58+
<p>无法选出能使数组满足三段式要求的&nbsp;<code>p</code> 和 <code>q</code> 。</p>
59+
</div>
60+
61+
<p>&nbsp;</p>
62+
63+
<p><strong>提示:</strong></p>
64+
65+
<ul>
66+
<li data-end="41" data-start="26"><code data-end="39" data-start="26">3 &lt;= n &lt;= 100</code></li>
67+
<li data-end="70" data-start="44"><code data-end="70" data-start="44">-1000 &lt;= nums[i] &lt;= 1000</code></li>
68+
</ul>
69+
70+
<!-- description:end -->
71+
72+
## 解法
73+
74+
<!-- solution:start -->
75+
76+
### 方法一
77+
78+
<!-- tabs:start -->
79+
80+
#### Python3
81+
82+
```python
83+
84+
```
85+
86+
#### Java
87+
88+
```java
89+
90+
```
91+
92+
#### C++
93+
94+
```cpp
95+
96+
```
97+
98+
#### Go
99+
100+
```go
101+
102+
```
103+
104+
<!-- tabs:end -->
105+
106+
<!-- solution:end -->
107+
108+
<!-- problem:end -->
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
---
2+
comments: true
3+
difficulty: Easy
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3600-3699/3637.Trionic%20Array%20I/README_EN.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3637. Trionic Array I](https://leetcode.com/problems/trionic-array-i)
10+
11+
[中文文档](/solution/3600-3699/3637.Trionic%20Array%20I/README.md)
12+
13+
## Description
14+
15+
<!-- description:start -->
16+
17+
<p data-end="128" data-start="0">You are given an integer array <code data-end="37" data-start="31">nums</code> of length <code data-end="51" data-start="48">n</code>.</p>
18+
19+
<p data-end="128" data-start="0">An array is <strong data-end="76" data-start="65">trionic</strong> if there exist indices <code data-end="117" data-start="100">0 &lt; p &lt; q &lt; n &minus; 1</code> such that:</p>
20+
21+
<ul>
22+
<li data-end="170" data-start="132"><code data-end="144" data-start="132">nums[0...p]</code> is <strong>strictly</strong> increasing,</li>
23+
<li data-end="211" data-start="173"><code data-end="185" data-start="173">nums[p...q]</code> is <strong>strictly</strong> decreasing,</li>
24+
<li data-end="252" data-start="214"><code data-end="228" data-start="214">nums[q...n &minus; 1]</code> is <strong>strictly</strong> increasing.</li>
25+
</ul>
26+
27+
<p data-end="315" data-is-last-node="" data-is-only-node="" data-start="254">Return <code data-end="267" data-start="261">true</code> if <code data-end="277" data-start="271">nums</code> is trionic, otherwise return <code data-end="314" data-start="307">false</code>.</p>
28+
29+
<p>&nbsp;</p>
30+
<p><strong class="example">Example 1:</strong></p>
31+
32+
<div class="example-block">
33+
<p><strong>Input:</strong> <span class="example-io">nums = [1,3,5,4,2,6]</span></p>
34+
35+
<p><strong>Output:</strong> <span class="example-io">true</span></p>
36+
37+
<p><strong>Explanation:</strong></p>
38+
39+
<p>Pick <code data-end="91" data-start="84">p = 2</code>, <code data-end="100" data-start="93">q = 4</code>:</p>
40+
41+
<ul>
42+
<li><code data-end="130" data-start="108">nums[0...2] = [1, 3, 5]</code> is strictly increasing (<code data-end="166" data-start="155">1 &lt; 3 &lt; 5</code>).</li>
43+
<li><code data-end="197" data-start="175">nums[2...4] = [5, 4, 2]</code> is strictly decreasing (<code data-end="233" data-start="222">5 &gt; 4 &gt; 2</code>).</li>
44+
<li><code data-end="262" data-start="242">nums[4...5] = [2, 6]</code> is strictly increasing (<code data-end="294" data-start="287">2 &lt; 6</code>).</li>
45+
</ul>
46+
</div>
47+
48+
<p><strong class="example">Example 2:</strong></p>
49+
50+
<div class="example-block">
51+
<p><strong>Input:</strong> <span class="example-io">nums = [2,1,3]</span></p>
52+
53+
<p><strong>Output:</strong> <span class="example-io">false</span></p>
54+
55+
<p><strong>Explanation:</strong></p>
56+
57+
<p>There is no way to pick <code>p</code> and <code>q</code> to form the required three segments.</p>
58+
</div>
59+
60+
<p>&nbsp;</p>
61+
<p><strong>Constraints:</strong></p>
62+
63+
<ul>
64+
<li data-end="41" data-start="26"><code data-end="39" data-start="26">3 &lt;= n &lt;= 100</code></li>
65+
<li data-end="70" data-start="44"><code data-end="70" data-start="44">-1000 &lt;= nums[i] &lt;= 1000</code></li>
66+
</ul>
67+
68+
<!-- description:end -->
69+
70+
## Solutions
71+
72+
<!-- solution:start -->
73+
74+
### Solution 1
75+
76+
<!-- tabs:start -->
77+
78+
#### Python3
79+
80+
```python
81+
82+
```
83+
84+
#### Java
85+
86+
```java
87+
88+
```
89+
90+
#### C++
91+
92+
```cpp
93+
94+
```
95+
96+
#### Go
97+
98+
```go
99+
100+
```
101+
102+
<!-- tabs:end -->
103+
104+
<!-- solution:end -->
105+
106+
<!-- problem:end -->

0 commit comments

Comments
 (0)