Lintcode166 Nth to Last Node in List solution 题解

来源:互联网 发布:尼康优化校准设置技巧 编辑:程序博客网 时间:2024/06/07 04:56

【题目描述】

Find the nth to last element of a singly linked list.

The minimum number of nodes in list is n.

找到单链表倒数第n个节点,保证链表中节点的最少数量为n。

【题目链接】

www.lintcode.com/en/problem/nth-to-last-node-in-list/

【题目解析】

这一道找倒数第n个结点的链表题,可用双指针做。

由于链表没有得到长度的值,只能通过一个一个移来进行判断

可fast先走n,然后fast和slow一起走,直到fast为null,slow的位置就是倒数第n个位置。

【参考答案】

www.jiuzhang.com/solutions/nth-to-last-node-in-list/

原创粉丝点击