* 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 *r,*l;
r=l=head;
int m=0,k=0;
while(r){
++m;
if(m<=n+1){
k=n+1-m;
r=r->next;
}
else {
r=r->next;
l=l->next;
}
}
if(k==1){
head=head->next;
}
else {
r=l->next;
l->next=r->next;
}
return head;
}
};