LeetCode "Remove Nth Node From End of List"
2014-07-23 11:41
218 查看
Another Double pointer solution. 1A!
class Solution { public: ListNode *removeNthFromEnd(ListNode *head, int n) { ListNode *p = NULL; ListNode *p0 = head; ListNode *p1 = head; ListNode *pre1 = NULL; while (--n) p0 = p0->next; while (p0->next) { p0 = p0->next; pre1 = p1; p1 = p1->next; } if (p1 == head) p = head->next; else { pre1->next = p1->next; p = head; } return p; } };
相关文章推荐
- [LeetCode-Algorithms-19] "Remove Nth Node From End of List" (2017.11.16-WEEK11)
- leetcode 40: Remove Nth Node From End of List
- [Leetcode 19] 19 Remove Nth Node From End Of List
- leetcode--Remove Nth Node From End of List
- leetcode Remove Nth Node From End of List
- [leetcode刷题系列]Remove Nth Node From End of List
- LeetCode 19: Remove Nth Node From End of List
- LeetCode-Remove Nth Node From End of List
- LeetCode - Remove Nth Node From End of List
- LeetCode_Remove Nth Node From End of List
- Leetcode 19 Remove Nth Node From End of List
- LeetCode 笔记系列四 Remove Nth Node From End of List
- LeetCode: Remove Nth Node From End of List
- [LeetCode] Remove Nth Node From End of List 解题报告
- leetcode -- Remove Nth Node From End of List
- LeetCode Online Judge 题目C# 练习 - Remove Nth Node From End of List
- [Leetcode] Remove Nth Node From End of List
- [Leetcode] Remove Nth Node From End of List
- leetcode 40: Remove Nth Node From End of List
- LeetCode: Remove Nth Node From End of List