leecode第二百二十六题(翻转二叉树)

Posted cjt-blog

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leecode第二百二十六题(翻转二叉树)相关的知识,希望对你有一定的参考价值。

技术图片

/**
 * 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:
    void core_code(TreeNode* root) 
        TreeNode* node_temp=root->left;//交换左右子节点
        root->left=root->right;
        root->right=node_temp;
        
        if(root->left!=NULL)
            core_code(root->left);//分别对左右子节点做同一操作
        if(root->right!=NULL)
            core_code(root->right);
    
    
    TreeNode* invertTree(TreeNode* root) 
        if(root==NULL)//首先判断边界
            return root;
        core_code(root);
        return root;
    
;

分析:

菜了菜了。

以上是关于leecode第二百二十六题(翻转二叉树)的主要内容,如果未能解决你的问题,请参考以下文章