LeetCode 328. Odd Even Linked List — JavaScript

Gary Huang
Aug 13, 2022

--

最強高中生出現,真心誇張
var oddEvenList = function(head) {
if (head === null || head.next === null) return head;

let odd = head;
let even = head.next;
let evenhead = even;

while (odd.next !== null && even.next !== null) {
odd.next = even.next
odd = odd.next

even.next = odd.next
even = even.next
}
odd.next = evenhead;
return head
};

用兩條 link list 串接奇數跟偶數,最後合併

--

--

Gary Huang

Self-taught in programming, currently working as a web developer and also a online course instructor, helping self-taught programmers find employment.