parent
c342d7e2c1
commit
6e550159d5
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue