A sloution by java


  • 0
    M

    public TreeNode invertTree(TreeNode root) {

        if(null == root){
            
            return root;
        }
        
        TreeNode temp = null;
        temp = root.left;
        root.left = root.right;
        root.right = temp;
        invertTree(root.left);
        invertTree(root.right);
        return root;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.