Leetcode#24 Swap Nodes in Pairs
来源:互联网 发布:网络话飞机场什么意思 编辑:程序博客网 时间:2024/04/28 18:55
Given a linked list, swap every two adjacent nodes and return its head.
For example,
Given 1->2->3->4
, you should return the list as 2->1->4->3
.
Your algorithm should use only constant space. You may not modify the values in the list, only nodes itself can be changed.
Difficulty: Medium
ListNode* swapPairs(ListNode* head) { ListNode* first; ListNode* second; ListNode* third; ListNode* temp = new ListNode(0);; ListNode* beg; if(!head || !head -> next) { return head; } first = head; beg = head->next; while(first &&first->next) { third = first->next->next; second = first->next; temp ->next = second; first->next = second->next; second->next = first; temp = first; first = first->next; } return beg; }
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
- 每天一个Linux命令-1(grep)
- 如何压缩 Microsoft Virtual PC 2007 虚拟硬盘文件(.VHD文件)
- JAVA设计模式之外观模式(门面模式)
- oracle 集合 varray
- java基础之 IO系统
- Leetcode#24 Swap Nodes in Pairs
- 超实用的iOS面试题集合
- JAVA设计模式之桥接模式
- 关于Eclipse C++出现Launch failed,Binary not found问题的解决方案(Win7环境下)
- excel宏调用webservice使用存储过程同步excel数据的方法
- reveals her inspira
- Android 开机启动, service 自动运行。
- 300+ 优秀常用wordpress插件推荐
- 在桌面上显示“这台电脑”Windows Server 2012 R2