LeetCode(24) Swap Nodes in Pairs
来源:互联网 发布:焊接机器人编程 编辑:程序博客网 时间:2024/05/13 21:50
/** * 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 == NULL) return NULL; if(head->next == NULL) return head; ListNode *newHead = new ListNode(0); newHead->next = head; ListNode *p1, *p2, *p3; p1 = newHead; p2 = p1->next; p3 = p1->next->next; while(p1->next != NULL && p1->next->next != NULL) { p2 = p1->next; p3 = p1->next->next; ListNode *tmp; p1->next = p2->next; tmp = p3->next; p3->next = p2; p2->next = tmp; p1 = p1->next->next; } return newHead->next; }};
0 0
- LeetCode(24)Swap Nodes in Pairs
- [LeetCode 24] Swap Nodes in Pairs
- [leetcode 24]Swap Nodes in Pairs
- LeetCode | #24 Swap Nodes in Pairs
- [Leetcode 24 链表]Swap Nodes in Pairs
- leetcode 24 Swap Nodes in Pairs
- 【leetcode】【单链表】【24】Swap Nodes in Pairs
- Leetcode 24 Swap Nodes in Pairs
- Swap Nodes in Pairs - LeetCode 24
- LeetCode 24 - Swap Nodes in Pairs
- leetcode 24 -- Swap Nodes in Pairs
- LeetCode 24:Swap Nodes in Pairs
- leetcode-24Swap Nodes in Pairs
- leetcode 24: Swap Nodes in Pairs
- Leetcode#24 Swap Nodes in Pairs
- LeetCode 24: Swap Nodes in Pairs
- LeetCode(24) Swap Nodes in Pairs
- [Leetcode 24, Medium] Swap Nodes in Pairs
- C#静态构造函数
- Java中单例设计模式
- 1066 Bash游戏
- ping工具的C语言简单实现 (ICMP echo)
- 窜梁鸿于海曲
- LeetCode(24) Swap Nodes in Pairs
- Apache Web Server -> httpd 的文档根目录 及 访问控制
- Ruby String(2)
- 遍历搜索空间的例子:熄灯问题
- 杭电1005Number Sequence
- Linux、xshell等中文乱码问题
- MVC传递数据-传递对象或对象集合
- Linux自学笔记:在虚拟机上安装Linux操作系统
- 面试问题总结