//考虑好边界条件,特别是n=1的时候
class Solution {
public:
ListNode* removeNthFromEnd(ListNode* head, int n) {
ListNode* curNodeL = head;
ListNode* curNodeR = head;
for (int i=1; i<=n; i++){
if(curNodeR->next) curNodeR = curNodeR->next;
else {
ListNode* del = head;
head = head->next;
delete del;
return head;
}
}
while(curNodeR->next){
curNodeL = curNodeL->next;
curNodeR = curNodeR->next;
}
ListNode* next = curNodeL->next;
curNodeL->next = next->next;
delete next;
return head;
}
};