LeetCode——19. Remove Nth Node From End of List
来源:互联网 发布:苹果电脑mac地址 编辑:程序博客网 时间:2024/05/01 17:12
大年初一来一题:思想很简单,就是两个指针相距n,后一个指针走到尾节点时前一个指针的下一个节点即为要删除的节点,思想简单,但是不同的写法时间复杂度相差不小,经过优化,下列算法beats59%
public class Solution { public ListNode removeNthFromEnd(ListNode head, int n) { ListNode preDelete,toLastNode; ListNode headNode=new ListNode(0); headNode.next=head; preDelete=toLastNode=headNode; while(toLastNode.next!=null){ n--; if(n<0){ preDelete=preDelete.next; } toLastNode=toLastNode.next; } preDelete.next=preDelete.next.next; return headNode.next; }}
0 0
- LeetCode——Remove Nth Node From End of List
- Remove Nth Node From End of List —— Leetcode
- leetcode—Remove Nth Node From End of List
- 19. Remove Nth Node From End of List leetcode list
- Algorithms—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
- 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)
- 已知二叉树的后序遍历和中序遍历求前序遍历(二叉树)
- 安卓逆向系列教程 4.1 字符串资源
- 洛谷P1316 丢瓶盖
- 面向对象
- Tips for preparing input data in caffe
- LeetCode——19. Remove Nth Node From End of List
- JS实现轮播图
- poj 2838 Cow Sorting 树状数组 两种思路
- wamp出现You don’t have permission to access/on this server提示
- #matlab#1.预测广东省甘蔗产量
- Maven 菜鸟教程 1 安装和配置
- 1023. Have Fun with Numbers (20)
- 文章标题
- How do Convolutional Neural Networks work?