题解 | #二叉树的镜像#

二叉树的镜像

http://www.nowcoder.com/practice/a9d0ecbacef9410ca97463e4a5c83be7

package org.example.test;

public class MirrorTest {

    static public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        public TreeNode(int val) {
            this.val = val;
        }
    }

    /**
     * 左右互相交换即可
     *
     * @param pRoot
     * @return
     */
    public TreeNode Mirror(TreeNode pRoot) {
        // write code here
        if (pRoot == null) {
            return null;
        }
        TreeNode left = pRoot.left;
        TreeNode right = pRoot.right;
        pRoot.left = right;
        pRoot.right = left;
        Mirror(left);
        Mirror(right);
        return pRoot;
    }

}
算法 文章被收录于专栏

数据结构和算法

全部评论

相关推荐

吴offer选手:HR:我KPI到手了就行,合不合适关我什么事
点赞 评论 收藏
分享
能干的三文鱼刷了10...:公司可能有弄嵌入式需要会画pcb的需求,而且pcb能快速直观看出一个人某方面的实力。看看是否有面试资格。问你问题也能ai出来,pcb这东西能作假概率不高
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-04 18:06
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务