Problem: Remove Nth Node From End of List

Given the head of a linked list, remove the nth node from the end of the list and return its head.

Example 1:

Screenshot 2022-08-08 153820.png

Input: head = [1,2,3,4,5], n = 2 Output: [1,2,3,5]

Screenshot 2022-08-08 153601.png

Screenshot 2022-08-08 153626.png

```class Solution { public ListNode removeNthFromEnd(ListNode head, int n) { ListNode temp = head; int len=0;

    if(head==null || head.next==null)
        return null;

    while(temp!=null){
        temp=temp.next;
        len++;
    }

    if(len==n)
        return head.next;

    int frontlen = len-n-1;

    ListNode first=head.next;
    ListNode second = head;

    int count=0;

    while(first!=null){
        if(count==frontlen){
            second.next=first.next;
            break;
        }else{
            first=first.next;
            second=second.next;
            count++;
        }
    }

    return head;
}

} ```