Skip to content

Commit 49acc74

Browse files
Merge pull request youngyangyang04#2479 from bluedusk/master
Update 0024.两两交换链表中的节点.md
2 parents db0bd95 + 6e55015 commit 49acc74

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Diff for: problems/0024.两两交换链表中的节点.md

+15
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,21 @@ var swapPairs = function (head) {
285285
};
286286
```
287287

288+
```javascript
289+
// 递归版本
290+
var swapPairs = function (head) {
291+
if (head == null || head.next == null) {
292+
return head;
293+
}
294+
295+
let after = head.next;
296+
head.next = swapPairs(after.next);
297+
after.next = head;
298+
299+
return after;
300+
};
301+
```
302+
288303
### TypeScript:
289304

290305
```typescript

0 commit comments

Comments
 (0)