Remove Nth Node From End of List
来源:互联网 发布:做假章的软件 编辑:程序博客网 时间:2024/06/14 03:55
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.
主要考察链表指针的操作以及对边界异常情况的处理,C++代码如下:
class Solution {public: ListNode *removeNthFromEnd(ListNode *head, int n) { ListNode *pNodeOne = head, *pNodeTwo = head; while (pNodeTwo != NULL) { pNodeTwo = pNodeTwo->next; if (n-- < 0) pNodeOne = pNodeOne->next; } if (n == 0) head = head->next; else pNodeOne->next = pNodeOne->next->next; return head; }};
0 0
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node from End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- Remove Nth Node From End of List
- 03-3. 12-24小时制(15)
- 窗体的视图切换效果
- 03-4. 成绩转换(15)
- 对gridview绑定数据的操作方法及自定义显示内容
- Java Socket编程 标准范例(多线程)
- Remove Nth Node From End of List
- xtrabackup<三、增量备份脚本>
- 转载01:正确的认识浏览器兼容性问题
- thrift说明和测试
- ubuntu12.04中安装jdk
- 【LeetCode】Scramble String 解题报告
- YTUOJ-输入n个数和输出调整后的n个数
- 输入3个整数a,b,c。要求按由大到小的顺序将他们输出,用函数实现。
- 第二大的数