【leetcode】19. Remove Nth Node From End of List
来源:互联网 发布:营销网络优势 编辑:程序博客网 时间:2024/04/26 17:42
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和长度相同的时候。
/** * 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 ll = 0; var temp = head; while(temp!==null){ temp = temp.next; ll++; } var cc = ll-n; if(cc===0){ return head.next; } temp = head; while(--cc){ temp = temp.next; } temp.next = temp.next.next; return head;};
0 0
- 19. Remove Nth Node From End of List leetcode list
- [LeetCode]19.Remove Nth Node From End of List
- LeetCode 19. Remove Nth Node From End of List
- 19. Remove Nth Node From End of List Leetcode Python
- 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
- <LeetCode OJ> 19. Remove Nth Node From End of List
- 19. Remove Nth Node From End of List LeetCode
- leetcode 19. Remove Nth Node From End of List
- [LeetCode OJ] 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(JAVA)
- 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
- NOI2003 文本编辑器 块状链表
- HTML5+规范:XMLHttpRequest(管理网络请求)
- 3.5 74HC138三八译码器的应用
- 基数排序
- BZOJ 1006 [HNOI2008]神奇的国度==最大势算法
- 【leetcode】19. Remove Nth Node From End of List
- 3.6 LED灯闪烁程序
- 机器人走方格(DP/递归)
- Hibernate学习(一)--Hello Hibernate
- 4.1 二进制、十进制和十六进制
- 阿里巴巴开源前端框架--Weex实践
- Linux上安装mysql
- 4.2 C语言变量类型和范围
- I2c