TOP101题解 | BM33#二叉树的镜像#

二叉树的镜像

https://www.nowcoder.com/practice/a9d0ecbacef9410ca97463e4a5c83be7

/**
 * struct TreeNode {
 *	int val;
 *	struct TreeNode *left;
 *	struct TreeNode *right;
 * };
 */
/**
 * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
 * @author Senky
 * @date 2023.08.01
 * @par url https://www.nowcoder.com/creation/manager/content/584337070?type=column&status=-1
 * @brief 做了这么多的递归,条件反射就是递归交换树的左右指针
 * 
 * @param pRoot TreeNode类 
 * @return TreeNode类
 */
struct TreeNode* Mirror(struct TreeNode* pRoot ) {
    // write code here
    if(NULL == pRoot)
    {
        return pRoot;
    }

    struct TreeNode* temp = pRoot->left;
    pRoot->left = pRoot->right;
    pRoot->right= temp;

    Mirror(pRoot->left);
    Mirror(pRoot->right);
    
    return pRoot;

}

#TOP101#
TOP101-BM系列 文章被收录于专栏

系列的题解

全部评论

相关推荐

05-12 16:04
已编辑
江西财经大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务