原来这道题也可以快慢指针,惊呆了
注意:1.快指针走k步的时候注意判断fast是否为null
function FindKthToTail( pHead , k ) {
let fast = pHead, slow = pHead;
for(let i=0;i<k;i++){
if(fast == null) return null;
fast = fast.next;
}
while(fast!=null){
fast = fast.next;
slow = slow.next;
}
return slow;
}