/**
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
class Solution {
public:
/**
*
* @param head ListNode类
* @param n int整型
* @return ListNode类
*/
ListNode* removeNthFromEnd(ListNode* head, int n) {
// write code here
ListNode *start=new ListNode(-1);
start->next=head;
ListNode *pre=start;
ListNode *cur=head;
ListNode *fast=head;
while(n--){
fast=fast->next;
}
while(fast!=NULL){
fast=fast->next;
cur=cur->next;
pre=pre->next;
}
pre->next=cur->next;
free(cur);
return start->next;
}
};