美文网首页
226. 翻转二叉树

226. 翻转二叉树

作者: 小时候浪死了 | 来源:发表于2018-10-21 11:33 被阅读0次

示例:

输入:

     4
   /    \
  2      7
 / \   /  \
1   3  6   9
输出:

     4
   /    \
  7     2
 / \   / \
9   6 3   1
class Solution {
public:
    TreeNode* invertTree(TreeNode* root) {
        Inver(root);
        return root;
    }
private:
    void Inver(TreeNode* t)
    {
        if(t==NULL)
            return;
        TreeNode *tmp=t->left;
        t->left=t->right;
        t->right=tmp;
        Inver(t->left);
        Inver(t->right);
    }
};

相关文章

网友评论

      本文标题:226. 翻转二叉树

      本文链接:https://www.haomeiwen.com/subject/spqbzftx.html