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

LeetCode 226 翻转二叉树

时间:2022-09-07 08:44:47浏览次数:67  
标签:right TreeNode val nullptr 二叉树 226 root LeetCode left

/**
 * 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
From: https://www.cnblogs.com/hjy94wo/p/16664028.html

相关文章