Java 1 ms Solution


  • 0
    A
    public TreeNode invertTree(TreeNode root) {
    
            if (root == null){
                return null;
            }
            else{
                TreeNode temp = new TreeNode(root.val);
    
                temp.left = invertTree(root.right);
                temp.right = invertTree(root.left);
                return temp;
            }
    

Log in to reply
 

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