0ms 5-line recursive Java solution


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

Log in to reply
 

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