###### [leetcode] 【链表】24. Swap Nodes in Pairs

For example,
Given 1->2->3->4, you should return the list as 2->1->4->3.

Your algorithm should use only constant space. You may not modify the values in the list, only nodes itself can be changed.

# 题解

/**
* struct ListNode {
*     int val;
*     ListNode *next;
*     ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
while(cur&&next)
{
cur->next=next->next;
next->next=cur;
prev->next=next;
prev=cur;
cur=cur->next;
if(cur==NULL)
break;
next=cur->next;
}
}
};

#### [LeetCode] 024. Swap Nodes in Pairs (Medium) (C++/Python)

2015-03-05 14:39:27

#### LeetCode24. Swap Nodes in Pairs简单到一次性通过

2016-02-02 21:01:22

#### 24. Swap Nodes in Pairs [easy] (Python)

2016-05-29 15:09:02

#### Swap Nodes in Pairs -- LeetCode

2014-02-26 01:37:59

#### LeetCode 24 Swap Nodes in Pairs（交换序列中的结点）（Linked List）

2015-11-12 18:43:57

#### LeetCode 24 Swap Nodes in Pairs (C,C++,Java,Python)

2015-05-11 16:37:22

#### (Java)LeetCode-24. Swap Nodes in Pairs

2016-06-02 16:53:15

#### 24. Swap Nodes in Pairs -leetcode-java

2016-05-26 18:54:52

#### 【LeetCode-面试算法经典-Java实现】【024-Swap Nodes in Pairs（成对交换单链表的结点）】

2015-07-24 06:55:18

#### 24. Swap Nodes in Pairs（python）

2016-09-18 21:33:51

## 不良信息举报

[leetcode] 【链表】24. Swap Nodes in Pairs