🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
<div id="div14"><h4> 14, 链表中倒数第K个结点 <h4></div> ```javascript /* function ListNode(x){ this.val = x; this.next = null; }*/ function FindKthToTail(head, k) { if (head === null || k <= 0) return null; let pNode1 = head, pNode2 = head; while (--k) { if (pNode2.next !== null) { pNode2 = pNode2.next; } else { return null; } } while (pNode2.next !== null) { pNode1 = pNode1.next; pNode2 = pNode2.next; } return pNode1; } ```