其他分享
首页 > 其他分享> > 剑指OFFER----面试题27. 二叉树的镜像

剑指OFFER----面试题27. 二叉树的镜像

作者:互联网

链接:https://leetcode-cn.com/problems/er-cha-shu-de-jing-xiang-lcof/

 

代码:

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    TreeNode* mirrorTree(TreeNode* root) {
        if (!root) return root;
        mirrorTree(root->left);
        mirrorTree(root->right);
        swap(root->left, root->right);
        return root;
    }
};

 

标签:面试题,27,TreeNode,int,right,二叉树,mirrorTree,root,left
来源: https://www.cnblogs.com/clown9804/p/12363375.html