mirror of
https://github.com/chefyuan/algorithm-base.git
synced 2024-11-28 06:48:53 +00:00
leetcode 328 补充js代码
This commit is contained in:
parent
096d624df3
commit
561f2390c0
@ -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;
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user