19. Remove Nth Node From End of List
2016-06-15 11:06
435 查看
题目:https://leetcode.com/problems/remove-nth-node-from-end-of-list/
代码:
代码:
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ public class Solution { public ListNode removeNthFromEnd(ListNode head, int n) { ListNode temp = head; int length = getlength(temp); if(length==n) { head = head.next; return head; } int t = 0; while(t<n) { temp = temp.next; t++; } ListNode cur = head; while(temp.next!=null) { cur = cur.next; temp = temp.next; } cur.next = cur.next.next; return head; } int getlength(ListNode temp){ int length = 1; while(temp.next!=null) { temp = temp.next; length++; } return length; } }
相关文章推荐
- crontab没有正确重定向导致磁盘inode节点空间满
- Swagger UI教程 API 文档神器 搭配Node使用 web api 接口文档 mvc接口文档
- ionic安装失败或者cordova安装失败解决方法
- nodejs读取图片像素
- [朝花夕拾]关于nodejs中child_process之中spawn和exec的区别
- LeetCode-237 Delete Node in a Linked List
- [leetcode] 19. Remove Nth Node From End of List python实现【easy】
- build_zone_zonelists() 初始化备用内存域链表node_zonelists
- node.js 回调函数
- 在node.js中,使用基于ORM架构的Sequelize,操作mysql数据库之增删改查
- LNK4098 defaultlib 'library' conflicts with use of other libs; use /NODEFAULTLIB:library
- 浅析Nodejs npm常用命令
- nodejs npm常用命令
- webpack共用于前后端的小坑
- ccah-500 第25题 what do you need to do when adding a new slave node to cluster
- nodejs记录一
- LeetCode:Populating Next Right Pointers in Each Node II
- 基于node.js及express实现中间件,实现post、get
- Node.JS读取文本并转化成js对象
- Populating Next Right Pointers in Each Node