Leetcode156-上下翻转二叉树

  • 构建二叉树的题
class Solution {
    public TreeNode upsideDownBinaryTree(TreeNode root) {
        if(root==null){
            return null;
        }

        if(root.left==null){
            return root;
        }

        TreeNode LE=root.left;
        TreeNode RI=root.right;

        TreeNode res=upsideDownBinaryTree(root.left);//走到最左边

        root.left=null;
        root.right=null;
        LE.right=root;
        LE.left=RI;
        return res;

    }
}
posted @ 2022-04-26 11:26  fao99  阅读(39)  评论(0)    收藏  举报