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个结点
最新推荐文章于 2024-12-27 15:07:41 发布