Loading

剑指 Offer 27. 二叉树的镜像

思路

方法:先序遍历,递归

 1 class Solution {
 2 public:
 3     TreeNode* mirrorTree(TreeNode* root) {
 4         if(root == NULL) {
 5             return NULL;
 6         }
 7 
 8         TreeNode* tmp = mirrorTree(root->left);
 9         root->left = mirrorTree(root->right);
10         root->right = tmp;
11 
12         return root;
13     }
14 };

 

复杂度分析

 

posted @ 2020-10-25 11:23  拾月凄辰  阅读(76)  评论(0编辑  收藏  举报