You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: solution/0000-0099/0098.Validate Binary Search Tree/README_EN.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,8 +24,8 @@ tags:
24
24
<p>A <strong>valid BST</strong> is defined as follows:</p>
25
25
26
26
<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's key.</li>
28
-
<li>The right subtree of a node contains only nodes with keys <strong>greater than</strong> the node's key.</li>
27
+
<li>The left <span data-keyword="subtree">subtree</span> of a node contains only nodes with keys <strong>strictly less than</strong> the node's key.</li>
28
+
<li>The right subtree of a node contains only nodes with keys <strong>strictly greater than</strong> the node's key.</li>
29
29
<li>Both the left and right subtrees must also be binary search trees.</li>
Copy file name to clipboardExpand all lines: solution/0400-0499/0499.The Maze III/README_EN.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,7 +23,7 @@ tags:
23
23
24
24
<!-- description:start -->
25
25
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'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'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>
27
27
28
28
<p>Given the <code>m x n</code> <code>maze</code>, the ball's position <code>ball</code> and the hole'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't drop in the hole, return <code>"impossible"</code>.</p>
Copy file name to clipboardExpand all lines: solution/0800-0899/0853.Car Fleet/README_EN.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ tags:
21
21
22
22
<p>There are <code>n</code> cars at given miles away from the starting mile 0, traveling to reach the mile <code>target</code>.</p>
23
23
24
-
<p>You are given two integer array <code>position</code> and <code>speed</code>, both of length <code>n</code>, where <code>position[i]</code> is the starting mile of the <code>i<sup>th</sup></code> car and <code>speed[i]</code> is the speed of the <code>i<sup>th</sup></code> car in miles per hour.</p>
24
+
<p>You are given two integer arrays <code>position</code> and <code>speed</code>, both of length <code>n</code>, where <code>position[i]</code> is the starting mile of the <code>i<sup>th</sup></code> car and <code>speed[i]</code> is the speed of the <code>i<sup>th</sup></code> car in miles per hour.</p>
25
25
26
26
<p>A car cannot pass another car, but it can catch up and then travel next to it at the speed of the slower car.</p>
Copy file name to clipboardExpand all lines: solution/0900-0999/0904.Fruit Into Baskets/README_EN.md
+63-4Lines changed: 63 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -75,7 +75,7 @@ If we had started at the first tree, we would only pick from trees [1,2].
75
75
76
76
We use a hash table $cnt$ to maintain the types and corresponding quantities of fruits in the current window, and use two pointers $j$ and $i$ to maintain the left and right boundaries of the window.
77
77
78
-
We traverse the `fruits` array, add the current fruit $x$ to the window, i.e., $cnt[x]++$, then judge whether the types of fruits in the current window exceed $2$. If it exceeds $2$, we need to move the left boundary $j$ of the window to the right until the types of fruits in the window do not exceed $2$. Then we update the answer, i.e., $ans = \max(ans, i - j + 1)$.
78
+
We traverse the $\textit{fruits}$ array, add the current fruit $x$ to the window, i.e., $cnt[x]++$, then judge whether the types of fruits in the current window exceed $2$. If it exceeds $2$, we need to move the left boundary $j$ of the window to the right until the types of fruits in the window do not exceed $2$. Then we update the answer, i.e., $ans = \max(ans, i - j + 1)$.
79
79
80
80
After the traversal ends, we can get the final answer.
81
81
@@ -95,7 +95,7 @@ j i
95
95
j i
96
96
```
97
97
98
-
The time complexity is $O(n)$, and the space complexity is $O(1)$. Here, $n$ is the length of the `fruits` array.
98
+
The time complexity is $O(n)$, and the space complexity is $O(1)$. Here, $n$ is the length of the $\textit{fruits}$ array.
In Solution 1, we find that the window size sometimes increases and sometimes decreases, which requires us to update the answer each time.
250
280
251
281
But what this problem actually asks for is the maximum number of fruits, that is, the "largest" window. We don't need to shrink the window, we just need to let the window monotonically increase. So the code omits the operation of updating the answer each time, and only needs to return the size of the window as the answer after the traversal ends.
252
282
253
-
The time complexity is $O(n)$, and the space complexity is $O(1)$. Here, $n$ is the length of the `fruits` array.
283
+
The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is the length of the $\textit{fruits}$ array.
0 commit comments