剑指 Offer 27. 二叉树的镜像bahttps://leetcode.cn/problems/er-cha-shu-de-jing-xiang-lcof/
| 2023-8-7
0  |  阅读时长 0 分钟
Date
Jul 28, 2023
need_review
need_review
type
剑指 Offer(第 2 版)
undo
undo
难度
简单
请完成一个函数,输入一个二叉树,该函数输出它的镜像。
例如输入:
4    /   \   2     7  / \   / \ 1   3 6   9
镜像输出:
4    /   \   7     2  / \   / \ 9   6 3   1
示例 1:
限制:
0 <= 节点个数 <= 1000
注意:本题与主站 226 题相同:https://leetcode-cn.com/problems/invert-binary-tree/

解法1
dfs 翻转左右子树
notion image
解法2
dfs 使用栈来代替递归
notion image
  • Giscus
目录