/*
public class ListNode {
int val;
ListNode next = null;
ListNode(int val) {
this.val = val;
}
}*/
public class Solution {
public ListNode FindKthToTail(ListNode head,int k) {
int len = 0;
ListNode temp = head;
while (temp.next != null) {
len++;
temp = temp.next;
}
int pos = len - k + 1;
int value = 0;
temp = head;
int i = 0;
ListNode head2 = new ListNode(0);
head2.next = null;
ListNode temp2 = head2;
while (temp != null) {
if (i < pos) {
i++;
}
else {
}
temp = temp.next;
}
return new ListNode(temp.val);
}
}
链表中倒数第k个结点
最新推荐文章于 2019-06-25 14:31:09 发布