199. 二叉树的右视图
199. 二叉树的右视图
解法一 BFS 广度优先 层序遍历
- 时间复杂度
O(n) 每个节点访问一次 - 空间复杂度
O(n)
1 | func rightSideView(_ root: TreeNode?) -> [Int] { |
解法二 DFS 深度优先 前序遍历 变形
- 时间复杂度
O(n) 每个节点访问一次 - 空间复杂度
O(n)
1 | var ans: [Int] = [] |
- Post title:199. 二叉树的右视图
- Post author:xxxixxxx
- Create time:2021-02-24 23:22:00
- Post link:https://xxxixxx.github.io/2021/02/24/2000-021-199. 二叉树的右视图/
- Copyright Notice:All articles in this blog are licensed under BY-NC-SA unless stating additionally.
Comments