
思路:逐层遍历交换左右结点

我的代码:
public TreeNode Mirror(TreeNode pRoot) {
if (pRoot == null || (pRoot.left == null && pRoot.right == null)) {
return pRoot;
}
TreeNode temp = pRoot.left;
pRoot.left = pRoot.right;
pRoot.right = temp;
Mirror(pRoot.left);
Mirror(pRoot.right);
return pRoot;
}
网友评论