24-m-Swap Nodes in Pairs
来源:互联网 发布:java中布尔函数编程 编辑:程序博客网 时间:2024/06/05 00:29
交换相邻节点。逻辑简单,就看指针操作了。另外,对于链表来说,加个头结点真的省事很多,以及对终点的判断也很重要。
如下:
struct ListNode* swapPairs(struct ListNode* head) { if (head == NULL) return NULL;// struct ListNode **slow = &head, **fast = &((*slow)->next); struct ListNode p = {-1, head}; struct ListNode *slow = &p, *fast = slow->next; if (fast->next == NULL) return head; struct ListNode *tempP = NULL; while (fast != NULL) {// tempP = fast->next; if (fast->next == NULL) break; slow->next = fast->next; fast->next = fast->next->next; slow->next->next = fast; slow = fast; fast = slow->next; } return p.next;}
0 0
- 24-m-Swap Nodes in Pairs
- [24]Swap Nodes in Pairs
- 24、Swap Nodes in Pairs
- 24 Swap Nodes in Pairs
- #24 Swap Nodes in Pairs
- 24 Swap Nodes in Pairs
- 24 - Swap Nodes in Pairs
- 24 Swap Nodes in Pairs
- [24]Swap Nodes in Pairs
- [24] Swap Nodes in Pairs
- 【24】Swap Nodes in Pairs
- 24-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
- java—类与继承小结
- HDU3338Kakuro Extension(最大流,ISAP)建图是关键
- android 设置线程的优先级
- Android-View
- iOS开发UI篇 -- 04011控制器切换方式之Modal介绍
- 24-m-Swap Nodes in Pairs
- printf中的%c,%d,%u........都分别代表输出的是什么类型的?
- 利用std::for_each 定义宏函数
- gdb结合coredump定位崩溃进程
- iOS程序进入后台后仍运行定时器
- CListView下CheckBox的显示和注意点
- 十三周项目一
- Android studio
- Django教程:[30]DJANGO_SETTINGS_MODULE配置