Why i cannot use ref argument ????? C# solution


  • 0
    public ListNode RemoveNthFromEnd(ref ListNode head, int n)
    {
                if (head != null)
                {
                        if (C_Lvl >= n)
                        {
                            if (head.next != null)
                            {
                                head.val = head.next.val;
                            }
                            else
                            {
                                head = null;
                                return head;
                            }
                        }
                        ++C_Lvl;
                        RemoveNthFromEnd(ref head.next, n);
                }
                return head;
    }

  • 0

    code has no problem. but not allowed to use ref-argument. That doesn't make sense.

    1ms-2ms


Log in to reply
 

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