mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 11:34:46 +08:00
增加 0024.两两交换链表中的节点的递归解法 go 版
This commit is contained in:
@ -153,6 +153,19 @@ func swapPairs(head *ListNode) *ListNode {
|
||||
}
|
||||
```
|
||||
|
||||
```go
|
||||
// 递归版本
|
||||
func swapPairs(head *ListNode) *ListNode {
|
||||
if head == nil || head.Next == nil {
|
||||
return head
|
||||
}
|
||||
next := head.Next
|
||||
head.Next = swapPairs(next.Next)
|
||||
next.Next = head
|
||||
return next
|
||||
}
|
||||
```
|
||||
|
||||
Javascript:
|
||||
```javascript
|
||||
var swapPairs = function (head) {
|
||||
|
Reference in New Issue
Block a user