建立镜像二叉树
/* function TreeNode(x) { this.val = x; this.left = null; this.right = null; } */ function Mirror(root) { // write code here if(!root) return null function buildImage(root){ if(!root.left && !root.right) return var temp = root.left root.left = root.right root.right = temp if(root.left) buildImage(root.left) if(root.right) buildImage(root.right) } buildImage(root) return root }
树算法 文章被收录于专栏
树相关算法