We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 473299c commit c75cdfeCopy full SHA for c75cdfe
C++/LeetCodet题解(C++版).pdf
-57 Bytes
C++/chapTree.tex
@@ -1246,7 +1246,7 @@ \subsubsection{代码}
1246
1247
\begin{Code}
1248
// LeetCode, Convert Sorted Array to Binary Search Tree
1249
-// 分治法,时间复杂度O(nlogn),空间复杂度O(logn)
+// 分治法,时间复杂度O(n),空间复杂度O(logn)
1250
class Solution {
1251
public:
1252
TreeNode* sortedArrayToBST (vector<int>& num) {
@@ -1258,8 +1258,7 @@ \subsubsection{代码}
1258
RandomAccessIterator last) {
1259
const auto length = distance(first, last);
1260
1261
- if (length == 0) return nullptr; // 终止条件
1262
- if (length == 1) return new TreeNode(*first); // 收敛条件
+ if (length <= 0) return nullptr; // 终止条件
1263
1264
// 三方合并
1265
auto mid = first + length / 2;
0 commit comments