【题目描述】
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个位置。
【参考答案】
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交