From cedb32f7b20619473623f50c15183d54ef35c973 Mon Sep 17 00:00:00 2001 From: daluozha <561890199@qq.com> Date: Wed, 5 May 2021 04:26:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=89=91=E6=8C=87offer22=20=E8=A1=A5=E5=85=85j?= =?UTF-8?q?s=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../链表篇/剑指offer22倒数第k个节点.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/animation-simulation/链表篇/剑指offer22倒数第k个节点.md b/animation-simulation/链表篇/剑指offer22倒数第k个节点.md index eef029b..2666add 100644 --- a/animation-simulation/链表篇/剑指offer22倒数第k个节点.md +++ b/animation-simulation/链表篇/剑指offer22倒数第k个节点.md @@ -93,3 +93,18 @@ public: }; ``` +JS Code: +```javascript +var getKthFromEnd = function(head, k) { + if(!head) return head; + let pro = head, after = head; + for(let i = 0; i < k - 1; i++){ + pro = pro.next; + } + while(pro.next){ + pro = pro.next; + after = after.next; + } + return after; +}; +``` \ No newline at end of file