二叉树的镜像

来源:互联网 发布:stc单片机程序烧录 编辑:程序博客网 时间:2024/05/28 09:32
////class TreeNode {// int val = 0;// TreeNode left = null;// TreeNode right = null;//// public TreeNode(int val) {// this.val = val;//// }// }public class Solution {    public void Mirror(TreeNode root) {        if(root == null) return;        TreeNode left = root.left;        TreeNode right = root.right;        if(left != null) Mirror(left);        if(right != null) Mirror(right);        root.left = right;        root.right = left;    }}
原创粉丝点击