[Leetcode]Swap Nodes in Pairs
来源:互联网 发布:实时监测网速软件 编辑:程序博客网 时间:2024/06/05 20:07
//不熟啊不熟,链表...next指针要先改,然后再是指向node本身的指针
/**
* Definition for singly-linked list.* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode *swapPairs(ListNode *head) {
//ListNode ret(0);
//ret.next=head;
if(head==NULL||head->next==NULL)return head;
ListNode *p=head;//&ret;
ListNode *pre=p->next;
head=pre;
ListNode *prepre=p;
while(p&&pre)
{
//prepre->next=pre;
p->next=pre->next;
pre->next=p;
prepre=p;
p=p->next;
if(p==NULL)break;
else
pre=p->next;
}
//return ret.next;
return head;
}
};
0 0
- LeetCode:Swap Nodes in Pairs
- LeetCode: Swap Nodes in Pairs
- [Leetcode] Swap Nodes in Pairs
- LeetCode : Swap Nodes in Pairs
- [LeetCode] Swap Nodes in Pairs
- Leetcode: Swap nodes in pairs
- [LeetCode]Swap Nodes in Pairs
- [LeetCode]Swap Nodes in Pairs
- LeetCode-Swap Nodes in Pairs
- LeetCode - Swap Nodes in Pairs
- LeetCode | Swap Nodes in Pairs
- 【leetcode】Swap Nodes in Pairs
- Leetcode: Swap Nodes in Pairs
- LeetCode - Swap Nodes in Pairs
- 【LeetCode】Swap Nodes in Pairs
- Leetcode: Swap Nodes in Pairs
- Leetcode Swap Nodes in Pairs
- LeetCode Swap Nodes in Pairs
- Display a view from another controller in ASP.NET MVC
- mini2440驱动分析之LCD
- 纯CSS气泡框实现方法探究
- How to add css class and id in @Html.TextBox mvc4 at the same time
- Hadoop2.4.1部署(完整版)
- [Leetcode]Swap Nodes in Pairs
- Session timed Out in MVC 4
- S3C2400之LCD控制器详解一
- 纯CSS圆角框
- Why I do not have access rights on the server?
- http://blog.csdn.net/lwj103862095/article/details/7860648
- How to run an ajax call after another ajax call?
- TQ2440裸奔三部曲例1.1
- How to delete user created by websecurity