mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 15:45:40 +08:00
Update 0024.两两交换链表中的节点.md
添加javascript递归版本实现
This commit is contained in:
@ -285,6 +285,21 @@ var swapPairs = function (head) {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// 递归版本
|
||||||
|
var swapPairs = function (head) {
|
||||||
|
if (head == null || head.next == null) {
|
||||||
|
return head;
|
||||||
|
}
|
||||||
|
|
||||||
|
let after = head.next;
|
||||||
|
head.next = swapPairs(after.next);
|
||||||
|
after.next = head;
|
||||||
|
|
||||||
|
return after;
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
### TypeScript:
|
### TypeScript:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
|
Reference in New Issue
Block a user