题解 | #链表中倒数最后k个结点#
链表中倒数最后k个结点
https://www.nowcoder.com/practice/886370fe658f41b498d40fb34ae76ff9
import java.util.*; public class Solution { public ListNode FindKthToTail (ListNode pHead, int k) { // write code here ListNode curr = pHead; int size = 0; if(curr == null) size =0; else{ while(curr != null){ size++; curr = curr.next; } } if(size<k){ return null; } int yu = size - k; int ss = 0; while(true){ if(ss!=yu){ pHead = pHead.next; ss++; }else{ return pHead; } } } }