1、前言

2、思路
双指针
3、代码
class Solution {
public ListNode getKthFromEnd(ListNode head, int k) {
if(head == null){
return null;
}
ListNode pre = head, next = head;
for(int i = 0; i < k; i++){
next = next.next;
}
while(next != null){
next = next.next;
pre = pre.next;
}
return pre;
}
}
网友评论