236. 二叉树的最近公共祖先 - 中等

236. 二叉树的最近公共祖先
递归解法
- 时间复杂度
O(n) 其中 N 是二叉树的节点数,所有节点都会被访问一次。 - 空间复杂度
O(n) 其中 N 是二叉树的节点数。递归调用的栈深度取决于二叉树的高度,二叉树最坏情况下为一条链,此时高度为 N,因此空间复杂度为 O(N)。
1 | var commTree: TreeNode? |
- Post title:236. 二叉树的最近公共祖先 - 中等
- Post author:xxxixxxx
- Create time:2021-02-24 14:35:00
- Post link:https://xxxixxx.github.io/2021/02/24/2000-015-236. 二叉树的最近公共祖先/
- Copyright Notice:All articles in this blog are licensed under BY-NC-SA unless stating additionally.
Comments