public class Solution {
public ListNode FindKthToTail(ListNode head,int k) {
if (head == null || k == 0)
return null;
ListNode pA = head;
ListNode pB = null;
for(int i = 0; i < k-1;i++){
if(pA.next != null)
pA = pA.next;
else
return null;
}
pB = head;
while(pA.next != null){
pA = pA.next;
pB = pB.next;
}
return pB;
}
}
剑指offer22倒数第k个节点
最新推荐文章于 2024-08-15 21:00:00 发布