
题目
请完成一个函数,输入一个二叉树,该函数输出它的镜像。
实现
1 2 3 4 5 6 7 8 9
|
public class { int val = 0; TreeNode left = null; TreeNode right = null;
public (int val) { this.val = val; } }
|
1 2 3 4 5 6 7 8 9 10 11 12 13
|
public void Mirror(TreeNode root) { if (root == null) return; else if (root.left == null && root.right == null) return;
TreeNode tmp = root.left; root.left = root.right; root.right = tmp;
Mirror(root.left); Mirror(root.right); }
|
近期评论