zoukankan      html  css  js  c++  java
  • JZ018二叉树的镜像

    二叉树的镜像

    题目描述

    操作给定的二叉树,将其变换为源二叉树的镜像。

    题目链接: 二叉树的镜像

    代码

    /**
     * 标题:二叉树的镜像
     * 题目描述
     * 操作给定的二叉树,将其变换为源二叉树的镜像。
     * 题目链接:
     * https://www.nowcoder.com/practice/564f4c26aa584921bc75623e48ca3011?tpId=13&&tqId=11171&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking
     */
    public class Jz18 {
    
        /**
         * 递归法
         *
         * @param root
         */
        public static void mirror(TreeNode root) {
            if (root == null || (root.left == null && root.right == null)) {
                return;
            }
            TreeNode temp = root.left;
            root.left = root.right;
            root.right = temp;
            mirror(root.left);
            mirror(root.right);
        }
    
        public static void main(String[] args) {
            TreeNode root = new TreeNode(1);
            mirror(root);
        }
    }
    

    【每日寄语】 世上最耀眼的光芒除了太阳还有你努力的模样。

  • 相关阅读:
    orbis 链接 .a的问题
    程序的循环结构
    程序分支控制
    字符类型及常用的函数
    数字数据类型
    基础练习
    了解计算机
    python基础练习
    markdown基本使用
    jupyterhub
  • 原文地址:https://www.cnblogs.com/kaesar/p/15655617.html
Copyright © 2011-2022 走看看