[刷题]Remove Nth Node From End of List
来源:互联网 发布:windows ce版本 编辑:程序博客网 时间:2024/06/07 02:33
[LintCode]Remove Nth Node From End of List
/** * Definition for ListNode. * public class ListNode { * int val; * ListNode next; * ListNode(int val) { * this.val = val; * this.next = null; * } * } */ public class Solution { /** * @param head: The first node of linked list. * @param n: An integer. * @return: The head of linked list. */ ListNode removeNthFromEnd(ListNode head, int n) { // 2015-04-29 O(n) if (head == null) { return null; } ListNode dummy = new ListNode(0); dummy.next = head; //被删除的节点可能是头节点,所以要用dummy head = dummy; ListNode nthNode = dummy; for (int i = 0; i < n; i++) { nthNode = nthNode.next; if (nthNode == null) { return null; } } while (nthNode.next != null) { head = head.next; nthNode = nthNode.next; } // 删掉head的下一个节点 head.next = head.next.next; return dummy.next; }}
0 0
- 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
- 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
- 【学习ARToolkit小记之八】 开发第一个ARToolkit程序(Developing your First Application)(续2)
- ArcGIS教程:3D 面要素
- rpc服务器不可用怎么办----wince程序调试
- Python之类(Class)的学习
- HQL 多对多,一对一关联查询
- [刷题]Remove Nth Node From End of List
- android开发之PullToRefresh (GridView 下拉刷新,上拉加载)
- hdu1429推箱子
- 水晶报表文件导出方法小结
- Enable Zombie Objects
- FCoE的基本原理和优势
- Unity3d实现的十字路口的模拟(四)
- 【mybatis】关联查询——mybatis一对多两种方式实现详解
- Berkeley database (JE)操作与下载