《剑指Offer》 面试题27 二叉树的镜像
作者:
萨缪 | 来源:发表于
2019-11-04 19:25 被阅读0次

图片.png
源代码
/*
struct TreeNode {
int val;
struct TreeNode *left;
struct TreeNode *right;
TreeNode(int x) :
val(x), left(NULL), right(NULL) {
}
};*/
class Solution {
public:
void Mirror(TreeNode *pRoot) {
//左子树变为右子树 右子树变为左子树
if (pRoot == NULL) {
return;
}
if (pRoot->left == NULL && pRoot->right == NULL) {
return;
}
TreeNode * temp = NULL;
temp = pRoot->left;
pRoot->left = pRoot->right;
pRoot->right = temp;
if (pRoot->left)
Mirror(pRoot->left);
if (pRoot->right);
Mirror(pRoot->right);
}
};
本文标题:《剑指Offer》 面试题27 二叉树的镜像
本文链接:https://www.haomeiwen.com/subject/mbzdbctx.html
网友评论