《剑指offer》练习-面试题27-二叉树的镜像

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

package offer;

public class Solution27 {
	public void Mirror(TreeNode root) {
		if (root == null)
			return;

		if (root.left == null && root.right == null)
			return;

		TreeNode tmp = root.left;
		root.left = root.right;
		root.right = tmp;

		if (root.left != null)
			Mirror(root.left);
		if (root.right != null)
			Mirror(root.right);
	}

}

递归自己就带了循环的意思了,条件用判断条件,而不是循环条件。

猜你喜欢

转载自blog.csdn.net/sinat_34548226/article/details/81211336