1、前言
![](https://img.haomeiwen.com/i11345146/43dbd0b9e666ea24.png)
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;
}
}
网友评论