Lintcode166 Nth to Last Node in List solution 题解
2017-11-30 15:07
211 查看
【题目描述】
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/
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/
相关文章推荐
- Nth to Last Node in List
- lintcode-easy-Nth to Last Node in List Show result
- nth-to-last-node-in-list
- 快慢指针-----Nth to Last Node in List
- 166. 链表倒数第n个节点(nth-to-last-node-in-list)(c++)----lintcode面试题之链表
- Nth to Last Node in List
- [Lintcode]Nth to Last Node in List
- [刷题]Nth to Last Node in List
- lintcode 容易题:nth to Last Node In List 链表倒数第n个节点
- Lintcode: Nth to Last Node in List
- Nth to Last Node in List
- LintCode Nth to Last Node in List 链表倒数第n个节点
- #166 Nth to Last Node in List
- Nth to Last Node in List
- Ch2-2: return the nth to the last node data of a singly linked list
- Lintcode174 Remove Nth Node From End of List solution 题解
- Q.2.3 Implement an algorithm to delete a node in the middle of a single linked list, given only acce
- define a class for a linked list and write a method to delete the nth node.
- 快慢指针- Add to List 19. Remove Nth Node From End of List
- 【java】遇到错误constructor ListNode in class ListNode cannot be applied to given types;