mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 12:15:58 +08:00
添加“24.两两交换链表中的节点”Javascript版本
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user