题解 | #二叉树的镜像#
二叉树的镜像
https://www.nowcoder.com/practice/a9d0ecbacef9410ca97463e4a5c83be7
/* * function TreeNode(x) { * this.val = x; * this.left = null; * this.right = null; * } */ /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param pRoot TreeNode类 * @return TreeNode类 */ function swap(pRoot){ if(pRoot == null){ return null } swap(pRoot.left); swap(pRoot.right) // let mid = new TreeNode(pRoot.left.val); // console.log("mid",mid); let mid = pRoot.left; pRoot.left = pRoot.right; pRoot.right = mid; return pRoot } function Mirror( pRoot ) { // write code here // if(pRoot == null){ // return null // } // Mirror(pRoot.left); // Mirror(pRoot.right) // // let mid = new TreeNode(pRoot.left.val); // // console.log("mid",mid); // let mid = pRoot.left; // pRoot.left = pRoot.right; // pRoot.right = mid; // return pRoot return swap(pRoot) } module.exports = { Mirror : Mirror };#我的实习求职记录#