简单题
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode * removeNthFromEnd(ListNode* head, int n) {
ListNode *pre = NULL, *l = head, *r = head;
while (n--) r = r->next;
while (r) r = r->next, pre = l, l = l->next;
if (pre) pre->next = l->next;
else head = l->next;
delete(l);
return head;
}
};