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

 

 

C++:

 1 /*
 2 struct TreeNode {
 3     int val;
 4     struct TreeNode *left;
 5     struct TreeNode *right;
 6     TreeNode(int x) :
 7             val(x), left(NULL), right(NULL) {
 8     }
 9 };*/
10 class Solution {
11 public:
12     void Mirror(TreeNode *pRoot) {
13         if (pRoot == NULL)
14             return ;
15         TreeNode * t = pRoot->left ;
16         pRoot->left = pRoot->right ;
17         pRoot->right = t ;
18         Mirror(pRoot->left) ;
19         Mirror(pRoot->right) ;
20     }
21 };

 

相关文章:

猜你喜欢
  • 2021-12-25
  • 2021-06-17
  • 2021-08-23
  • 2021-11-20
  • 2021-06-04
相关资源
相似解决方案