题目输入一个链表输出该链表中倒数第k个结点。https://www.nowcoder.com/practice/529d3ae5a407492994ad2a246518148a?tpId13tqId11167rp2ru/activity/ojqru/ta/coding-interviews/question-ranking思路使用快慢指针双指针让快指针先走k步然后快慢指针一起移动当快指针走到末尾时慢指针正好指向倒数第k个节点。codeimportjava.util.*;/* public class ListNode { int val; ListNode next null; ListNode(int val) { this.val val; } }*/publicclassSolution{publicListNodeFindKthToTail(ListNodehead,intk){if(headnull)returnnull;//head为空if(k0)returnnull;//k不合法ListNodefasthead;ListNodeslowhead;intcount0;while(count!k){if(fast!null){fastfast.next;count;}else{returnnull;//k超出链表的个数}}while(fast!null){fastfast.next;slowslow.next;}returnslow;}}