Share my C# solution


  • 0
    E
    public int NodeLocation = 0;
    public ListNode RemoveNthFromEnd(ListNode head, int n) 
    {
            ListNode objResult;
            
            if (head.next != null) head.next = RemoveNthFromEnd(head.next, n);
            NodeLocation++;
    
    
            if (NodeLocation == n )
            {
                if (head.next != null) objResult = head.next;
                else objResult = null;
            }
            else
            {
                objResult = head;
            }
            return objResult;
    }

Log in to reply
 

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