226 Invert Binary Tree

/**
 * 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;
};

  

posted @ 2015-10-05 09:18  calmound  阅读(185)  评论(2编辑  收藏  举报