0
点赞
收藏
分享

微信扫一扫

LeetCode-热题100:108. 将有序数组转换为二叉搜索树

解题思路:用队列进行前序遍历的同时把节点的左节点和右节点交换

具体代码如下:

class Solution {
public:
    TreeNode* invertTree(TreeNode* root) {
        if (root == NULL) return root;
        swap(root->left, root->right);  // 中
        invertTree(root->left);         // 左
        invertTree(root->right);        // 右
        return root;
    }
};

 具体题目如下:

翻转一棵二叉树。

226.翻转二叉树

举报

相关推荐

0 条评论