其他分享
首页 > 其他分享> > LeetCode 226 翻转二叉树

LeetCode 226 翻转二叉树

作者:互联网

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

        return root;
    }
};

标签:right,TreeNode,val,nullptr,二叉树,226,root,LeetCode,left
来源: https://www.cnblogs.com/hjy94wo/p/16664028.html