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

Given a linked list, swap every two adjacent nodes and return its head.

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.

/**
* Definition for singly-linked list.
* struct ListNode {
*     int val;
*     ListNode *next;
*     ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
{
ListNode *p,*q,*tail;

p->next=q->next;
q->next=p;

tail=p;
while(tail->next != NULL)
{
p=p->next;
q=p->next;

if(p && q)
{
tail->next=q;
p->next=q->next;
q->next=p;
}

tail=p;
}

}
};

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

2015-03-05 14:39:27

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

2016-05-29 15:09:02

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

2016-02-02 21:01:22

#### 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-24】Swap Nodes in Pairs(C++)

2016-08-08 16:57:34

#### LeetCode 24. Swap Nodes in Pairs 解题报告

2016-02-20 17:31:56

## 不良信息举报

leetcode 24. Swap Nodes in Pairs