226. 翻转二叉树

leetCode

DFS

/**
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */
/**
 * @param {TreeNode} root
 * @return {TreeNode}
 */
var mirrorTree = function(root) {
    if (root === null) return null
    let left = mirrorTree(root.left)
    let right = mirrorTree(root.right)
    root.right = left
    root.left = right
    return root
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
更新时间: 2022-03-25 17:04