Recursive Java Solution


  • 0
    T
    public TreeNode invertTree(TreeNode root) {
            if(root == null){
                return null;
            }
            TreeNode left = root.left;
            TreeNode right = root.right;
            
            invertTree(left);
            invertTree(right);
            
            root.left = right;
            root.right = left;
            
            return root;
            
        }
    

Log in to reply
 

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