Skip to content

Commit c75cdfe

Browse files
committed
纠正时间复杂度,感谢@周婧
1 parent 473299c commit c75cdfe

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

C++/LeetCodet题解(C++版).pdf

-57 Bytes
Binary file not shown.

C++/chapTree.tex

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,7 @@ \subsubsection{代码}
12461246

12471247
\begin{Code}
12481248
// LeetCode, Convert Sorted Array to Binary Search Tree
1249-
// 分治法,时间复杂度O(nlogn),空间复杂度O(logn)
1249+
// 分治法,时间复杂度O(n),空间复杂度O(logn)
12501250
class Solution {
12511251
public:
12521252
TreeNode* sortedArrayToBST (vector<int>& num) {
@@ -1258,8 +1258,7 @@ \subsubsection{代码}
12581258
RandomAccessIterator last) {
12591259
const auto length = distance(first, last);
12601260

1261-
if (length == 0) return nullptr; // 终止条件
1262-
if (length == 1) return new TreeNode(*first); // 收敛条件
1261+
if (length <= 0) return nullptr; // 终止条件
12631262

12641263
// 三方合并
12651264
auto mid = first + length / 2;

0 commit comments

Comments
 (0)