19.Remove Nth Node From End of List(移除单链表中倒数第N个结点)
来源:互联网 发布:阿里云企业邮箱 编辑:程序博客网 时间:2024/06/05 23:58
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.public class Solution {
public ListNode removeNthFromEnd(ListNode head, int n) {
ListNode res = head;
int len = 0;
ListNode ahead = head;
while(ahead!=null){
len++;
ahead = ahead.next ;
}
if(n>len) return null;
if(len==n){
return head.next;
}
for(int i = 1;i<len-n;i++){
head = head.next;
}
head.next = head.next.next;
return res;
}
}
0 0
- 19.Remove Nth Node From End of List(移除单链表中倒数第N个结点)
- LeetCode | Remove Nth Node From End of List(移除链表中倒数第n个结点)
- 19. Remove Nth Node From End of List (移除链表倒数第n个节点)
- 19. Remove Nth Node From End of List(移除链表的倒数第n个节点)
- LeetCode 19 Remove Nth Node From End of List 移除倒数第N个节点
- LeetCode--Remove Nth Node From End of List(移除链表的倒数第N个节点)Python
- 删除链表的倒数第n个结点 Remove Nth Node From End of List
- Remove Nth Node From End of List 删除链表的倒数第n个结点
- 【Leecode】207Remove Nth Node From End of List删除倒数第N个结点
- Remove Nth Node From End of List "移除链表中的倒数第N项"
- leetcode 3. 移除链表的倒数第n个节点 Remove Nth Node From End of List
- LeetCode 19. Remove Nth Node From End of List--删除链表的倒数第n个结点
- Leetcode #19. Remove Nth Node From End of List 移除倒数第N个链表节点 解题小节
- [LeetCode-19] Remove Nth Node From End of List(删除倒数第N个节点)
- 【LeetCode-面试算法经典-Java实现】【019-Remove Nth Node From End of List(移除单链表的倒数第N个节点)】
- leetcode解题之 19. Remove Nth Node From End of List java 版(删除链表倒数第n个结点)
- LeetCode-19 Remove Nth Node From End of List(移除尾部第N个节点)
- LeetCodet题解--19. Remove Nth Node From End of List(删除链表的倒数第n个元素)
- c++中sizeof的分析
- 操作分布式文件之一:如何搭建配置FttpAdapter环境
- Redis
- myeclipse安装maven
- 黑马程序员—JAVA基础—GUI(图形化界面编程)
- 19.Remove Nth Node From End of List(移除单链表中倒数第N个结点)
- DevExpress(即DXperience)各版本及最新破解版下载
- 操作分布式文件之二:如何访问集群文件根目录 如何访问和操作远程文件
- Layout poj3169 差分约束
- mysql执行效率
- 一张图学会Python
- Poj 1979 Hdu 1312 Red and Black【dfs】
- RTMP协议
- bzoj-2878 迷失游乐园