添加“24.两两交换链表中的节点”Javascript版本

This commit is contained in:
纪飞
2021-05-18 12:30:49 +08:00
parent a811e9aa69
commit 3c5ed1ebae

View File

@ -132,6 +132,21 @@ Python
Go
Javascript:
```javascript
var swapPairs = function (head) {
let ret = new ListNode(0, head), temp = ret;
while (temp.next && temp.next.next) {
let cur = temp.next.next, pre = temp.next;
pre.next = cur.next;
cur.next = pre;
temp.next = cur;
temp = pre;
}
return ret.next;
};
```
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)