From 53aae73d2ba19bf516b8c6cec6b68c21e9217956 Mon Sep 17 00:00:00 2001 From: look Date: Tue, 11 Apr 2023 22:30:22 +0800 Subject: [PATCH] =?UTF-8?q?look=E7=AC=AC=E4=BA=8C=E6=AC=A1=E6=8F=90?= =?UTF-8?q?=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- alg.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/alg.md b/alg.md index 8a4ef77..6529d80 100644 --- a/alg.md +++ b/alg.md @@ -82,3 +82,9 @@ print(preorderTraversal(root)) ​ 对于一个长度为 `n` 的不重复的整数数组 `nums`,构建最大二叉树的时间复杂度为 $O(n\log n)$。 ​ 在构建最大二叉树的过程中,每个节点最多会被访问两次,因此时间复杂度为 $O(n)$。而在最坏情况下,数组中的每个数都会成为树的根节点,因此二叉树的深度为 $O(n)$,所以总的时间复杂度为 $O(n\log n)$。 + +## 空间复杂度 + +​ 对于一个长度为 `n` 的不重复的整数数组 `nums`,构建最大二叉树的空间复杂度为 $O(n)$。 + +在构建最大二叉树的过程中,每个节点最多会被访问两次,因此递归栈的空间复杂度为 $O(n)$。此外,由于最大二叉树的节点数为 $n$,因此需要额外的 $O(n)$ 的空间来存储二叉树的节点。因此总的空间复杂度为 $O(n)$。 \ No newline at end of file -- Gitee