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