Merge pull request #234 from resyon/dev

添加了0024题交换链表节点golang版本
This commit is contained in:
Carl Sun 2021-05-24 17:59:56 +08:00 committed by GitHub
commit 0aa0c9450a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 0 deletions

View File

@ -131,6 +131,27 @@ class Solution {
Python
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