标签:遍历 public log view ide == str class alt
先序遍历,交换子树即可,注意空节点的情况,这种简单题考的就是细节...
/* 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) return; if(pRoot->left == NULL && pRoot->right == NULL) return; swap(pRoot->left, pRoot->right); if(pRoot->left) Mirror(pRoot->left); if(pRoot->right) Mirror(pRoot->right); } };
标签:遍历 public log view ide == str class alt
原文地址:http://www.cnblogs.com/dupengcheng/p/7662665.html