Skip to content

Commit 168d8c1

Browse files
committed
feat: add solutions to lc problem: No.2604
No.2604.Minimum Time to Eat All Grains
1 parent 4e7dd96 commit 168d8c1

File tree

23 files changed

+833
-117
lines changed

23 files changed

+833
-117
lines changed

solution/0000-0099/0026.Remove Duplicates from Sorted Array/README_EN.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44

55
## Description
66

7-
<p>Given an integer array <code>nums</code> sorted in <strong>non-decreasing order</strong>, remove the duplicates <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a> such that each unique element appears only <strong>once</strong>. The <strong>relative order</strong> of the elements should be kept the <strong>same</strong>.</p>
7+
<p>Given an integer array <code>nums</code> sorted in <strong>non-decreasing order</strong>, remove the duplicates <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a> such that each unique element appears only <strong>once</strong>. The <strong>relative order</strong> of the elements should be kept the <strong>same</strong>. Then return <em>the number of unique elements in </em><code>nums</code>.</p>
88

9-
<p>Since it is impossible to change the length of the array in some languages, you must instead have the result be placed in the <strong>first part</strong> of the array <code>nums</code>. More formally, if there are <code>k</code> elements after removing the duplicates, then the first <code>k</code> elements of <code>nums</code>&nbsp;should hold the final result. It does not matter what you leave beyond the first&nbsp;<code>k</code>&nbsp;elements.</p>
9+
<p>Consider the number of unique elements of <code>nums</code> be <code>k</code>, to get accepted, you need to do the following things:</p>
1010

11-
<p>Return <code>k</code><em> after placing the final result in the first </em><code>k</code><em> slots of </em><code>nums</code>.</p>
12-
13-
<p>Do <strong>not</strong> allocate extra space for another array. You must do this by <strong>modifying the input array <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank">in-place</a></strong> with O(1) extra memory.</p>
11+
<ul>
12+
<li>Change the array <code>nums</code> such that the first <code>k</code> elements of <code>nums</code> contain the unique elements in the order they were present in <code>nums</code> initially. The remaining elements of <code>nums</code> are not important as well as the size of <code>nums</code>.</li>
13+
<li>Return <code>k</code>.</li>
14+
</ul>
1415

1516
<p><strong>Custom Judge:</strong></p>
1617

solution/0000-0099/0027.Remove Element/README_EN.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44

55
## Description
66

7-
<p>Given an integer array <code>nums</code> and an integer <code>val</code>, remove all occurrences of <code>val</code> in <code>nums</code> <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a>. The relative order of the elements may be changed.</p>
7+
<p>Given an integer array <code>nums</code> and an integer <code>val</code>, remove all occurrences of <code>val</code> in <code>nums</code> <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a>. The order of the elements may be changed. Then return <em>the number of elements in </em><code>nums</code><em> which are not equal to </em><code>val</code>.</p>
88

9-
<p>Since it is impossible to change the length of the array in some languages, you must instead have the result be placed in the <strong>first part</strong> of the array <code>nums</code>. More formally, if there are <code>k</code> elements after removing the duplicates, then the first <code>k</code> elements of <code>nums</code> should hold the final result. It does not matter what you leave beyond the first <code>k</code> elements.</p>
9+
<p>Consider the number of elements in <code>nums</code> which are not equal to <code>val</code> be <code>k</code>, to get accepted, you need to do the following things:</p>
1010

11-
<p>Return <code>k</code><em> after placing the final result in the first </em><code>k</code><em> slots of </em><code>nums</code>.</p>
12-
13-
<p>Do <strong>not</strong> allocate extra space for another array. You must do this by <strong>modifying the input array <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank">in-place</a></strong> with O(1) extra memory.</p>
11+
<ul>
12+
<li>Change the array <code>nums</code> such that the first <code>k</code> elements of <code>nums</code> contain the elements which are not equal to <code>val</code>. The remaining elements of <code>nums</code> are not important as well as the size of <code>nums</code>.</li>
13+
<li>Return <code>k</code>.</li>
14+
</ul>
1415

1516
<p><strong>Custom Judge:</strong></p>
1617

solution/0200-0299/0270.Closest Binary Search Tree Value/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## Description
66

7-
<p>Given the <code>root</code> of a binary search tree and a <code>target</code> value, return <em>the value in the BST that is closest to the</em> <code>target</code>.</p>
7+
<p>Given the <code>root</code> of a binary search tree and a <code>target</code> value, return <em>the value in the BST that is closest to the</em> <code>target</code>. If there are multiple answers, print the smallest.</p>
88

99
<p>&nbsp;</p>
1010
<p><strong class="example">Example 1:</strong></p>

solution/0200-0299/0274.H-Index/README_EN.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44

55
## Description
66

7-
<p>Given an array of integers <code>citations</code> where <code>citations[i]</code> is the number of citations a researcher received for their <code>i<sup>th</sup></code> paper, return compute the researcher&#39;s <code>h</code><strong>-index</strong>.</p>
7+
<p>Given an array of integers <code>citations</code> where <code>citations[i]</code> is the number of citations a researcher received for their <code>i<sup>th</sup></code> paper, return <em>the researcher&#39;s h-index</em>.</p>
88

9-
<p>According to the <a href="https://en.wikipedia.org/wiki/H-index" target="_blank">definition of h-index on Wikipedia</a>: A scientist has an index <code>h</code> if <code>h</code> of their <code>n</code> papers have at least <code>h</code> citations each, and the other <code>n &minus; h</code> papers have no more than <code>h</code> citations each.</p>
10-
11-
<p>If there are several possible values for <code>h</code>, the maximum one is taken as the <code>h</code><strong>-index</strong>.</p>
9+
<p>According to the <a href="https://en.wikipedia.org/wiki/H-index" target="_blank">definition of h-index on Wikipedia</a>: The h-index is defined as the maximum value of <code>h</code> such that the given researcher has published at least <code>h</code> papers that have each been cited at least <code>h</code> times.</p>
1210

1311
<p>&nbsp;</p>
1412
<p><strong class="example">Example 1:</strong></p>

solution/0200-0299/0275.H-Index II/README_EN.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44

55
## Description
66

7-
<p>Given an array of integers <code>citations</code> where <code>citations[i]</code> is the number of citations a researcher received for their <code>i<sup>th</sup></code> paper and <code>citations</code>&nbsp;is sorted in an <strong>ascending order</strong>, return compute the researcher&#39;s <code>h</code><strong>-index</strong>.</p>
7+
<p>Given an array of integers <code>citations</code> where <code>citations[i]</code> is the number of citations a researcher received for their <code>i<sup>th</sup></code> paper and <code>citations</code> is sorted in <strong>ascending order</strong>, return <em>the researcher&#39;s h-index</em>.</p>
88

9-
<p>According to the <a href="https://en.wikipedia.org/wiki/H-index" target="_blank">definition of h-index on Wikipedia</a>: A scientist has an index <code>h</code> if <code>h</code> of their <code>n</code> papers have at least <code>h</code> citations each, and the other <code>n &minus; h</code> papers have no more than <code>h</code> citations each.</p>
10-
11-
<p>If there are several possible values for <code>h</code>, the maximum one is taken as the <code>h</code><strong>-index</strong>.</p>
9+
<p>According to the <a href="https://en.wikipedia.org/wiki/H-index" target="_blank">definition of h-index on Wikipedia</a>: The h-index is defined as the maximum value of <code>h</code> such that the given researcher has published at least <code>h</code> papers that have each been cited at least <code>h</code> times.</p>
1210

1311
<p>You must write an algorithm that runs in logarithmic time.</p>
1412

solution/0400-0499/0427.Construct Quad Tree/README_EN.md

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

55
## Description
66

7-
<p>Given a <code>n * n</code> matrix <code>grid</code> of <code>0&#39;s</code> and <code>1&#39;s</code> only. We want to represent the <code>grid</code> with a Quad-Tree.</p>
7+
<p>Given a <code>n * n</code> matrix <code>grid</code> of <code>0&#39;s</code> and <code>1&#39;s</code> only. We want to represent <code>grid</code> with a Quad-Tree.</p>
88

9-
<p>Return <em>the root of the Quad-Tree</em> representing the <code>grid</code>.</p>
10-
11-
<p>Notice that you can assign the value of a node to <strong>True</strong> or <strong>False</strong> when <code>isLeaf</code> is <strong>False</strong>, and both are <strong>accepted</strong> in the answer.</p>
9+
<p>Return <em>the root of the Quad-Tree representing </em><code>grid</code>.</p>
1210

1311
<p>A Quad-Tree is a tree data structure in which each internal node has exactly four children. Besides, each node has two attributes:</p>
1412

1513
<ul>
16-
<li><code>val</code>: True if the node represents a grid of 1&#39;s or False if the node represents a grid of 0&#39;s.</li>
17-
<li><code>isLeaf</code>: True if the node is leaf node on the tree or False if the node has the four children.</li>
14+
<li><code>val</code>: True if the node represents a grid of 1&#39;s or False if the node represents a grid of 0&#39;s. Notice that you can assign the <code>val</code> to True or False when <code>isLeaf</code> is False, and both are accepted in the answer.</li>
15+
<li><code>isLeaf</code>: True if the node is a leaf node on the tree or False if the node has four children.</li>
1816
</ul>
1917

2018
<pre>
@@ -39,7 +37,7 @@ class Node {
3937

4038
<p><strong>Quad-Tree format:</strong></p>
4139

42-
<p>The output represents the serialized format of a Quad-Tree using level order traversal, where <code>null</code> signifies a path terminator where no node exists below.</p>
40+
<p>You don&#39;t need to read this section for solving the problem. This is only if you want to understand the output format here. The output represents the serialized format of a Quad-Tree using level order traversal, where <code>null</code> signifies a path terminator where no node exists below.</p>
4341

4442
<p>It is very similar to the serialization of the binary tree. The only difference is that the node is represented as a list <code>[isLeaf, val]</code>.</p>
4543

solution/0800-0899/0807.Max Increase to Keep City Skyline/README_EN.md

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

77
<p>There is a city composed of <code>n x n</code> blocks, where each block contains a single building shaped like a vertical square prism. You are given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code> where <code>grid[r][c]</code> represents the <strong>height</strong> of the building located in the block at row <code>r</code> and column <code>c</code>.</p>
88

9-
<p>A city&#39;s <strong>skyline</strong> is the the outer contour formed by all the building when viewing the side of the city from a distance. The <strong>skyline</strong> from each cardinal direction north, east, south, and west may be different.</p>
9+
<p>A city&#39;s <strong>skyline</strong> is the&nbsp;outer contour formed by all the building when viewing the side of the city from a distance. The <strong>skyline</strong> from each cardinal direction north, east, south, and west may be different.</p>
1010

1111
<p>We are allowed to increase the height of <strong>any number of buildings by any amount</strong> (the amount can be different per building). The height of a <code>0</code>-height building can also be increased. However, increasing the height of a building should <strong>not</strong> affect the city&#39;s <strong>skyline</strong> from any cardinal direction.</p>
1212

solution/1200-1299/1238.Circular Permutation in Binary Representation/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@
1818

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

21-
<pre><strong>输入:</strong>n = 2, start = 3
21+
<pre>
22+
<strong>输入:</strong>n = 2, start = 3
2223
<strong>输出:</strong>[3,2,0,1]
2324
<strong>解释:</strong>这个排列的二进制表示是 (11,10,00,01)
2425
所有的相邻元素都有一位是不同的,另一个有效的排列是 [3,1,0,2]
2526
</pre>
2627

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

29-
<pre><strong>输出:</strong>n = 3, start = 2
30+
<pre>
31+
<strong>输入:</strong>n = 3, start = 2
3032
<strong>输出:</strong>[2,6,7,5,4,0,1,3]
3133
<strong>解释:</strong>这个排列的二进制表示是 (010,110,111,101,100,000,001,011)
3234
</pre>

solution/1200-1299/1287.Element Appearing More Than 25% In Sorted Array/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ var findSpecialInteger = function (arr) {
114114

115115
### **PHP**
116116

117-
```php
117+
```php
118118
class Solution {
119119
/**
120120
* @param Integer[] $arr

solution/1600-1699/1637.Widest Vertical Area Between Two Points Containing No Points/README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
# [1637. 两点之间不包含任何点的最宽垂直面积](https://leetcode.cn/problems/widest-vertical-area-between-two-points-containing-no-points)
1+
# [1637. 两点之间不包含任何点的最宽垂直区域](https://leetcode.cn/problems/widest-vertical-area-between-two-points-containing-no-points)
22

33
[English Version](/solution/1600-1699/1637.Widest%20Vertical%20Area%20Between%20Two%20Points%20Containing%20No%20Points/README_EN.md)
44

55
## 题目描述
66

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

9-
<p>给你 <code>n</code> 个二维平面上的点 <code>points</code> ,其中 <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> ,请你返回两点之间内部不包含任何点的 <strong>最宽垂直面积</strong> 的宽度。</p>
9+
<p>给你&nbsp;<code>n</code>&nbsp;个二维平面上的点 <code>points</code> ,其中&nbsp;<code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>&nbsp;,请你返回两点之间内部不包含任何点的&nbsp;<strong>最宽垂直区域</strong> 的宽度。</p>
1010

11-
<p><strong>垂直面积</strong> 的定义是固定宽度,而 y 轴上无限延伸的一块区域(也就是高度为无穷大)。 <strong>最宽垂直面积</strong> 为宽度最大的一个垂直面积。</p>
11+
<p><strong>垂直区域</strong> 的定义是固定宽度,而 y 轴上无限延伸的一块区域(也就是高度为无穷大)。 <strong>最宽垂直区域</strong> 为宽度最大的一个垂直区域。</p>
1212

13-
<p>请注意,垂直区域 <strong>边上</strong> 的点 <strong>不在</strong> 区域内。</p>
13+
<p>请注意,垂直区域&nbsp;<strong>边上</strong>&nbsp;的点&nbsp;<strong>不在</strong>&nbsp;区域内。</p>
1414

15-
<p> </p>
15+
<p>&nbsp;</p>
1616

1717
<p><strong>示例 1:</strong></p>
1818
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1600-1699/1637.Widest%20Vertical%20Area%20Between%20Two%20Points%20Containing%20No%20Points/images/points3.png" style="width: 276px; height: 371px;" />​
@@ -29,15 +29,15 @@
2929
<b>输出:</b>3
3030
</pre>
3131

32-
<p> </p>
32+
<p>&nbsp;</p>
3333

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

3636
<ul>
3737
<li><code>n == points.length</code></li>
38-
<li><code>2 <= n <= 10<sup>5</sup></code></li>
38+
<li><code>2 &lt;= n &lt;= 10<sup>5</sup></code></li>
3939
<li><code>points[i].length == 2</code></li>
40-
<li><code>0 <= x<sub>i</sub>, y<sub>i</sub> <= 10<sup>9</sup></code></li>
40+
<li><code>0 &lt;= x<sub>i</sub>, y<sub>i</sub>&nbsp;&lt;= 10<sup>9</sup></code></li>
4141
</ul>
4242

4343
## 解法

solution/1600-1699/1644.Lowest Common Ancestor of a Binary Tree II/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class Solution {
127127

128128
public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
129129
dfs(root, p, q);
130-
return ans;
130+
return ans;
131131
}
132132

133133
private boolean dfs(TreeNode root, TreeNode p, TreeNode q) {

solution/1600-1699/1644.Lowest Common Ancestor of a Binary Tree II/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class Solution {
9898

9999
public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
100100
dfs(root, p, q);
101-
return ans;
101+
return ans;
102102
}
103103

104104
private boolean dfs(TreeNode root, TreeNode p, TreeNode q) {

solution/2600-2699/2601.Prime Subtraction Operation/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class Solution {
108108
}
109109
return true;
110110
}
111-
111+
112112
private int search(List<Integer> nums, int x) {
113113
int l = 0, r = nums.size();
114114
while (l < r) {

0 commit comments

Comments
 (0)