mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 19:44:45 +08:00
@ -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
|
||||
|
Reference in New Issue
Block a user