找到链表中倒数第k个结点
2017-12-08 17:26
155 查看
public static Node findK(Node head,int k){ if(head==null||k==0)return null; Node first=head;//快指针 Node second=null;//慢指针 for(int i=0;i<k-1;i++){ if(first.next!=null){ first=first.next; } else{ return null; } } second=head; while(first.next!=null){ first=first.next; second=second.next; } return second; }
相关文章推荐
- 找到链表倒数第K个结点
- 每天一个小算法(5)----找到链表倒数第K个结点
- 求链表中倒数第k个结点
- 微软100题(13)求链表倒数第K个结点
- 输入一个单向链表,输出该链表中倒数第K个结点
- 华为OJ基础篇-输出单向链表中倒数第k个结点
- 剑指offer:链表中倒数第k个结点
- 求链表中的倒数第K个结点
- [编程题]链表中倒数第k个结点
- 剑指Offer(14)______链表中倒数第k个结点
- 链表中倒数第k个结点
- 链表中倒数第k个结点 【微软面试100题 第十三题】
- 剑指offer-3-面试15:链表中倒数第k个结点
- 单链表的面试题---找到链表的中间节点--找到链表的倒数第K个节点
- 链表中倒数第k个结点
- 链表中倒数第k个结点
- 剑指offer_链表---链表中倒数第k个结点
- 链表中倒数第k个结点
- 剑指Offer(Java版):链表中倒数第K个结点
- 【算法】求链表中倒数第K个结点