LeetCode---Swap Nodes in Pairs
来源:互联网 发布:保险网络大学考证 编辑:程序博客网 时间:2024/05/16 10:52
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.
/** * 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 || head->next == NULL) return head; ListNode* first = head; ListNode* last = head->next; first->next = swapPairs(last->next); last->next = first; return last; }};
0 0
- LeetCode:Swap Nodes in Pairs
- LeetCode: Swap Nodes in Pairs
- [Leetcode] Swap Nodes in Pairs
- LeetCode : Swap Nodes in Pairs
- [LeetCode] Swap Nodes in Pairs
- Leetcode: Swap nodes in pairs
- [LeetCode]Swap Nodes in Pairs
- [LeetCode]Swap Nodes in Pairs
- LeetCode-Swap Nodes in Pairs
- LeetCode - Swap Nodes in Pairs
- LeetCode | Swap Nodes in Pairs
- 【leetcode】Swap Nodes in Pairs
- Leetcode: Swap Nodes in Pairs
- LeetCode - Swap Nodes in Pairs
- 【LeetCode】Swap Nodes in Pairs
- Leetcode: Swap Nodes in Pairs
- Leetcode Swap Nodes in Pairs
- LeetCode Swap Nodes in Pairs
- Java基础笔试题
- 1501101221-hpu-1015: 【C语言训练】列出最简真分数序列*
- 中软Java工程师面试题
- java EJB 加密与解密原理的一个例子
- 学习C++——复合类型
- LeetCode---Swap Nodes in Pairs
- Xcode6中修改项目的启动图片
- weblogic host name varify ssl
- Java中出现错误:“编码GBK的不可映射字符”的解决方法
- 谷歌掐架甲骨文:揭秘 Java 侵权案始末
- 不一样的手感至薄A7强芯 苹果iPad Air评测
- ORACLE PL/SQL编程详解之七:程序包的创建与应用
- Java的String类
- 2015年TCL i709M最新评测报导;5英寸机身背部镜面设计