226 Invert Binary Tree

2018-04-18 10:54:05 浏览数 (1)

代码语言:javascript复制
/**
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */
/**
 * @param {TreeNode} root
 * @return {TreeNode}
 */
var invertTree = function(root) {
    if(root == null) return null;
    var tmpNode = root.left;
    root.left = invertTree(root.right);
    root.right = invertTree(tmpNode);
    return root;
};

0 人点赞