[Leetcode]Remove Nth Node From End of List
来源:互联网 发布:苹果手机免费小说软件 编辑:程序博客网 时间:2024/06/03 06:15
Given a linked list, remove the nth node from the end of list and return its head. For example,
Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the linked list becomes 1->2->3->5.
Note:
Given n will always be valid.
Try to do this in one pass.
删除链表的倒数第n个元素。n保证合法。要求走一趟搞定。
代码来自这位大神
简直牛X!
ListNode *removeNthFromEnd(ListNode *head, int n){ListNode dummy(-1);dummy.next = head;ListNode *pre = &dummy;while (--n > 0) head = head->next;while (head->next){pre = pre->next;head = head->next;}pre->next = pre->next->next;return dummy.next;}
0 0
- LeetCode[Linked List]: Remove Nth Node From End of List
- 19. Remove Nth Node From End of List leetcode list
- [Leetcode]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 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 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
- linux0.12内核bootsect.S
- hihocoder#1049之二叉树遍历问题
- PCM
- Cgroup maintainer李泽帆:解剖Linux内核容器技术
- Android四大基本组件介绍与生命周期
- [Leetcode]Remove Nth Node From End of List
- CVPR2012——Ali Borji的三篇saliency
- app信息:PackageInfo+ApplicationInfo+ActivityInfo/ServiceInfo/ProviderInfo+PermissionInfo+...
- 谱聚类:Spectral Clustering
- 论坛邮件搜索群发软件_猫神qq邮件群发软件_美的电子邮件系统
- Android中已经不推荐使用的模块
- 第四周项目2-分数类的雏形
- 深入理解C语言
- 判断点在多边形内的多种写法