leetcode 328 补充js代码

This commit is contained in:
daluozha 2021-05-05 04:13:37 +08:00
parent 096d624df3
commit 561f2390c0

View File

@ -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;
};
```