标签:rom nod list ret while next for ++ from
class Solution {
public:
ListNode* removeNthFromEnd(ListNode* head, int n) {
if (!head->next) return NULL;
ListNode *pre = head, *cur = head;
for (int i = 0; i < n; ++i) cur = cur->next;
if (!cur) return head->next;
while (cur->next) {
cur = cur->next;
pre = pre->next;
}
pre->next = pre->next->next;
return head;
}
};leetcode 19 Remove Nth Node From End of List
标签:rom nod list ret while next for ++ from
原文地址:http://www.cnblogs.com/wangkun1993/p/6388135.html