In this Leetcode Remove Nth Node From End of List problem solution we have given the head of a linked list, remove the nth node from the end of the list and return its head.

## Problem solution in Python.

```class Solution:
def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode:

for i in range(n):
fast = fast.next

if not fast:

while fast and fast.next:
slow = slow.next
fast = fast.next

slow.next = slow.next.next
```

## Problem solution in Java.

```public ListNode removeNthFromEnd(ListNode head, int n) {
return null;

for(int i = 1; i < n; i++)
fast = fast.next;
while(fast.next != null) {
fast = fast.next;
prev = slow;
slow = slow.next;
}
prev.next = slow.next;
}
```

## Problem solution in C++.

```class Solution {
public:
ListNode* removeNthFromEnd(ListNode* head, int n) {

//checking basic  conditions

ListNode* prev = NULL;

while(n!=0){
fast = fast->next;
n--;
}

while(fast!=NULL){
prev = slow;
fast=fast->next;
slow=slow->next;
}

if(prev==NULL){
delete slow;
}

prev->next = slow->next;
delete slow;
}
};
```

## Problem solution in C.

```struct ListNode* removeNthFromEnd(struct ListNode* head, int n)
{
struct ListNode* current;
int count = 0;

while(current != NULL)
{
current = current->next;
count++;
}

if(count==n)
return current->next;

count = count-n-1;
while(count--)
{
current = current->next;
}

current->next = current->next->next;