作弊啊!
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
private:
map<int,ListNode*>mp;
public:
ListNode* removeNthFromEnd(ListNode* head, int n) {
ListNode* p = head;
int i = 0;
while(p)
{
mp[i++] = p;
p = p->next;
}
n = i-n;
if(n == 0) return head->next;
mp[n-1]->next = mp[n]->next;
return head;
}
};