Swap Nodes in Pairs
来源:互联网 发布:达内云笔记源码 编辑:程序博客网 时间:2024/06/04 17:42
/** * 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) { if(!head) { return head; } ListNode *pre=head; if(!(head->next)) { return head; } ListNode *cur=head->next; pre->next=cur->next; cur->next=pre; ListNode *hyperpre=pre; head=cur; while((hyperpre->next)&&(hyperpre->next->next)) { pre=hyperpre->next; cur=pre->next; pre->next=cur->next; cur->next=pre; hyperpre->next=cur; hyperpre=pre; } return head; }};
0 0
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes In Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- preg_replace正则表达式的使用
- 从头到尾彻底理解KMP(2014年8月22日版)
- 由双系统变单系统——如何删除另一个操作系统
- oracle得到本周数据
- 介绍三款串口监控工具
- Swap Nodes in Pairs
- Generate Parentheses
- 系统学习数字图像处理之图像复原与重建
- 同时上内外网
- 关于在多个controller中使用同一个函数的问题
- 负载均衡软件之NginX
- Valid Parentheses
- STM32学习笔记
- python实例学习