题解 | #链表中倒数最后k个结点#
链表中倒数最后k个结点
https://www.nowcoder.com/practice/886370fe658f41b498d40fb34ae76ff9
using System; using System.Collections.Generic; class Solution { public ListNode FindKthToTail (ListNode head, int k) { // write code here if(head == null) return null; ListNode slow = head; ListNode fast = head; int len = 0; while(fast != null){ fast = fast.next; len++; if(len > k) slow = slow.next; } return k > len ? null : slow; } }
逆天啊为什么我的oj时间这么久,复制别人的也久的离谱