class Solution { public: ListNode *removeNthFromEnd(ListNode *head, int n) { if (head == NULL) return NULL; ListNode* pre = NULL; ListNode* cur = head; ListNode* fast= cur; for (int i=1; i<n; i++) { fast = fast->next; } while (fast->next != NULL) { pre = cur; cur = cur->next; fast= fast->next; } if (pre == NULL) { return head->next; } else { pre->next = cur->next; return head; } } };
一次过呗
LeetCode Remove Nth Node From End of List,布布扣,bubuko.com
LeetCode Remove Nth Node From End of List
原文:http://www.cnblogs.com/lailailai/p/3853462.html