其他分享
首页 > 其他分享> > leetCode226

leetCode226

作者:互联网

/**
 * 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* invertTree(TreeNode* root) {
        if(root)
        {
            TreeNode* tmp = root->left;
            root->left = root->right;
            root->right = tmp;
            invertTree(root->left);
            invertTree(root->right);
        }
        return root;
    }
};

 

标签:leetCode226,right,TreeNode,val,invertTree,root,left
来源: https://blog.csdn.net/qq_36257146/article/details/102753523