输出一个链表的倒数第k个节点

public ListNode FindKToTail(ListNode head,int ){

ListNode p=head;  int count=0;

while(p!=null){

p=p.next;

count++;

}

if(k>count){

return null;

}

ListNode pNode=head;

if(int j=0;j<count-k;j++){

pNode=pNode.next;

}

return pNode;

}

猜你喜欢

转载自blog.csdn.net/sd116460/article/details/81414450