From 561f2390c0df2db9ea94abe67311fc28177bcb6a Mon Sep 17 00:00:00 2001 From: daluozha <561890199@qq.com> Date: Wed, 5 May 2021 04:13:37 +0800 Subject: [PATCH] =?UTF-8?q?leetcode=20328=20=E8=A1=A5=E5=85=85js=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../链表篇/leetcode328奇偶链表.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/animation-simulation/链表篇/leetcode328奇偶链表.md b/animation-simulation/链表篇/leetcode328奇偶链表.md index cc72283..83f4cd9 100644 --- a/animation-simulation/链表篇/leetcode328奇偶链表.md +++ b/animation-simulation/链表篇/leetcode328奇偶链表.md @@ -89,3 +89,19 @@ public: }; ``` +JS Code: +```javascript +var oddEvenList = function(head) { + if(!head || !head.next) return head; + let odd = head, even = head.next, evenHead = even; + while(odd.next && even.next){ + odd.next = even.next; + odd = odd.next; + even.next = odd.next; + even = even.next; + } + odd.next = evenHead; + return head; +}; +``` +