题目内容:
ListNode cur = head;
int count = 0;
while(cur != null){
count++;
cur = cur.next;
}
count = count - k;
cur = head;
while(count != 0){
cur = cur.next;
count--;
}
return cur;
有两种做法:
- 先遍历计算初结点个数,用结点个数与参数k作差,差值就是正数时要返回的结点(上面是这种)
- 先将链表逆置,在遍历链表时,以k为参数进行遍历