第19题:Remove Nth Node From End of List
来源:互联网 发布:通过网络走群众路线 编辑:程序博客网 时间:2024/06/06 20:32
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.
题目要求:删除单链表的倒数第n个节点。
编程语言:javascript
/** * Definition for singly-linked list. * function ListNode(val) { * this.val = val; * this.next = null; * } *//** * @param {ListNode} head * @param {number} n * @return {ListNode} */var removeNthFromEnd = function(head, n) { //构造一个带头结点的链表 var startNode = new ListNode(0); var slowNode = startNode; var fastNode = startNode; slowNode.next = head; for(var i=1; i<=n+1; ++i) { fastNode = fastNode.next; } while(fastNode !== null) { fastNode = fastNode.next; slowNode = slowNode.next; } slowNode.next = slowNode.next.next; return startNode.next; };
0 0
- 第19题 Remove Nth Node From End of List
- 第19题:Remove Nth Node From End of List
- leetcode第19题-Remove Nth Node From End of List
- leetcode第19题——*Remove Nth Node From End of List
- 【LeetCode】LeetCode——第19题:Remove Nth Node From End of List
- LeetCode第19题之 Remove Nth Node From End of List
- LeetCode 第 19 题 (Remove Nth Node From End of List)
- leetcode 第19题 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
- 关于在一套复制环境中使用不同版本OGG的问题
- HTML居中的三个小技巧
- 推荐给初学LSTM或者懂个大概却不完全懂的人
- 分页工具
- VMProtect怎么用_VMProtect使用教程
- 第19题:Remove Nth Node From End of List
- C++的STL算法for_each
- JAVA学习之Spring @Value使用
- SEAndroid安全机制框架分析
- 举例说明下Model的分层,Model、Logic、Service
- android应用程序启动详情之Dalvik虚拟机
- 学习使用MyEclipse时遇到的问题
- javax.servlet.http.HttpServletResponse下爆红线
- CSDN