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/0100-0199/0108.Convert Sorted Array to Binary Search Tree/README_EN.md
+72-48
Original file line number
Diff line number
Diff line change
@@ -57,19 +57,19 @@ tags:
57
57
58
58
### Solution 1: Binary Search + Recursion
59
59
60
-
We design a recursive function $dfs(l, r)$, which indicates that the node values of the current binary search tree to be constructed are all within the index range $[l, r]$ of the array `nums`. This function returns the root node of the constructed binary search tree.
60
+
We design a recursive function $\textit{dfs}(l, r)$, which represents that the values of the nodes to be constructed in the current binary search tree are within the index range $[l, r]$ of the array $\textit{nums}$. This function returns the root node of the constructed binary search tree.
61
61
62
-
The execution process of the function $dfs(l, r)$ is as follows:
62
+
The execution process of the function $\textit{dfs}(l, r)$ is as follows:
63
63
64
-
1. If $l > r$, it means the current array is empty, return `null`.
65
-
2. If $l \leq r$, take the element with the index $mid = \lfloor \frac{l + r}{2} \rfloor$ in the array as the root node of the current binary search tree, where $\lfloor x \rfloor$ represents rounding down $x$.
66
-
3. Recursively construct the left subtree of the current binary search tree, whose root node value is the element with the index $mid - 1$ in the array, and the node values of the left subtree are all within the index range $[l, mid - 1]$ of the array.
67
-
4. Recursively construct the right subtree of the current binary search tree, whose root node value is the element with the index $mid + 1$ in the array, and the node values of the right subtree are all within the index range $[mid + 1, r]$ of the array.
64
+
1. If $l > r$, it means the current array is empty, so return `null`.
65
+
2. If $l \leq r$, take the element at index $\textit{mid} = \lfloor \frac{l + r}{2} \rfloor$ of the array as the root node of the current binary search tree, where $\lfloor x \rfloor$ denotes the floor function of $x$.
66
+
3. Recursively construct the left subtree of the current binary search tree, with the root node's value being the element at index $\textit{mid} - 1$ of the array. The values of the nodes in the left subtree are within the index range $[l, \textit{mid} - 1]$ of the array.
67
+
4. Recursively construct the right subtree of the current binary search tree, with the root node's value being the element at index $\textit{mid} + 1$ of the array. The values of the nodes in the right subtree are within the index range $[\textit{mid} + 1, r]$ of the array.
68
68
5. Return the root node of the current binary search tree.
69
69
70
-
The answer is the return value of the function $dfs(0, n - 1)$.
70
+
The answer is the return value of the function $\textit{dfs}(0, n - 1)$.
71
71
72
-
The time complexity is $O(n)$, and the space complexity is $O(\log n)$. Here, $n$ is the length of the array `nums`.
72
+
The time complexity is $O(n)$, and the space complexity is $O(\log n)$. Here, $n$ is the length of the array $\textit{nums}$.
73
73
74
74
<!-- tabs:start -->
75
75
@@ -84,13 +84,11 @@ The time complexity is $O(n)$, and the space complexity is $O(\log n)$. Here, $n
0 commit comments