/**
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param head ListNode类
* @param n int整型
* @return ListNode类
*/
struct ListNode* removeNthFromEnd(struct ListNode* head, int n ) {
// write code here
struct ListNode* phead=head;
int a=1;
if(!head)return NULL;
while(phead->next){
phead=phead->next;
a++;
}
if(n==0)return head;
a=a-n;
phead=head;
if(a==0){
head=head->next;
return head;
}
while(--a){
phead=phead->next;
}
phead->next=phead->next->next;
return head;
}