[LeetCode] Invert Binary Tree 翻转二叉树

版权声明:欢迎转载。转载请注明地址:https://blog.csdn.net/weixin_32820767 https://blog.csdn.net/weixin_32820767/article/details/82860337

Invert a binary tree.

在这里插入图片描述

// Recursion
class Solution {
public:
    TreeNode* invertTree(TreeNode* root) {
        if (!root) return NULL;
        TreeNode *tmp = root->left;
        root->left = invertTree(root->right);
        root->right = invertTree(tmp);
        return root;
    }
};

猜你喜欢

转载自blog.csdn.net/weixin_32820767/article/details/82860337