add 0024-golang

This commit is contained in:
resyon
2021-05-23 17:52:00 +08:00
parent 5049fcae3c
commit 190c611798

View File

@ -131,6 +131,27 @@ class Solution {
Python Python
Go Go
```go
func swapPairs(head *ListNode) *ListNode {
dummy := &ListNode{
Next: head,
}
//head=list[i]
//pre=list[i-1]
pre := dummy
for head != nil && head.Next != nil {
pre.Next = head.Next
next := head.Next.Next
head.Next.Next = head
head.Next = next
//pre=list[(i+2)-1]
pre = head
//head=list[(i+2)]
head = next
}
return dummy.Next
}
```
Javascript: Javascript:
```javascript ```javascript