LeetCode-Remove Nth Node From End of List
2014-09-12 00:07
316 查看
ListNode *removeNthFromEnd(ListNode *head, int n) { if(head==NULL || (head->next==NULL && n==1)) return NULL; ListNode *pNode = head; int length=0; while(pNode!=NULL) { ++length; pNode=pNode->next; } if(n>length) return head; if(n==length && head->next!=NULL) return head->next; int rest=length-n-1; pNode=head; while(rest-- && pNode!=NULL) { pNode=pNode->next; } if(n==1) pNode->next=NULL; else pNode->next=pNode->next->next; return head; }
相关文章推荐
- 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 40: 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 40: 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--Remove Nth Node From End of List
- LeetCode-Remove Nth Node From End of List
- LeetCode: Remove Nth Node From End of List