[刷题]Nth to Last Node in List
2015-08-28 15:18
483 查看
[LintCode]Nth to Last Node in 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: Nth to last node of a singly linked list. */ ListNode nthToLast(ListNode head, int n) { // 2015-08-28 if (head == null) { return null; } ListNode fast = head; ListNode slow = head; for (int i = 0; i < n; i++) { fast = fast.next; } while (fast != null) { slow = slow.next; fast = fast.next; } return slow; } }
相关文章推荐
- [leetcode] 25.Reverse Nodes in k-Group
- jade模板引擎学习笔记(WebsStorm9.0.3+ nodejs+express+jade)
- NodeJS优缺点及适用场景讨论
- 既然nodejs是单线程的,那么它怎么处理多请求高并发的?
- 基于NodeJS的全栈式开发(基于NodeJS的前后端分离)
- 格式化ha 集群namenode报错
- AngularJS+Node.js实现在线聊天室
- [leetcode] 24.Swap Nodes in Pairs
- AngularJS+Node.js实现在线聊天室
- Node系列——Node系列中异常捕获的一个重要思考
- Node系列——Node中的异常处理。
- node.js
- HDU 4587 TWO NODES(割点,连通块,枚举)
- NodeJS优缺点及适用场景讨论
- Leetcode 222 Count Complete Tree Nodes 完全二叉树的结点数
- Merge Two Sorted Lists
- downgrade node homebrew
- 关于《Node.js 包教不包会》中cookie 与 session的补充
- Ubuntu下搭建NodeJS+Express WEB开发框架
- npm WARN uninstall not installed in /Users/hrt0kmt/node_modules: "xxx"