leetcode_swap_nodes_in_pair
来源:互联网 发布:淘宝店发货地址不能改 编辑:程序博客网 时间:2024/04/30 02:56
//很简单的一道题
* 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 *p,*ptr,*q,*t;
t=p=ptr=q=head;
while(ptr!=NULL)
{
if(ptr->next==NULL)
break;
p=ptr;
q=ptr->next;
p->next=q->next;
q->next=p; //注意这里ptr跟p是一个指向,所以p改变后,ptr也会改变
if(t==head)
head=q;
else
t->next=q;
t=ptr;
if(ptr->next==NULL)
break;
ptr=ptr->next;
}
return head;
}
};
- leetcode_swap_nodes_in_pair
- Android 图片处理工具类封装
- spring配置文件详解--真的蛮详细
- 解读Makefile (1)
- 合作,向强者学习,成长
- Java之高精度
- leetcode_swap_nodes_in_pair
- JQuery历史版本
- 笔记之--response和request对象编码等
- virtualbox文件共享ubuntu为host机器,win7为guest
- git Please move or remove them before you can merge. 错误解决方案
- 二维树状数组-poj2155
- 1007Financial Management
- 虚拟机 网络模式简介 及桥接模式设置
- 解读Makefile (2)