leetcode 24. Swap Nodes in Pairs
来源:互联网 发布:keras 安装 windows 编辑:程序博客网 时间:2024/06/16 12:21
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){ if(head->next){ ListNode* tmp = head->next; head->next = swapPairs(tmp->next); tmp->next = head; return tmp; }else return head; }else return head; }};
阅读全文
0 0
- [LeetCode]24.Swap Nodes in Pairs
- 24. Swap Nodes in Pairs Leetcode Python
- 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
- 24. Swap Nodes in Pairs LeetCode
- 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
- LeetCode 24. Swap Nodes in Pairs
- ZigBee_CC2530_0CH_终端动态切换信道
- 几种排序算法的python实现
- springMVC中关于时间的处理
- 求链表中倒数第K个节点
- Python--类的创建与继承
- leetcode 24. Swap Nodes in Pairs
- 安卓开发环境ADT报错:adt版本低于sdk版本,请升级
- 缓冲流和包装流
- <c:param> 标签的使用
- 快速排序qsort,sort函数用法
- 代理模式
- 多余的.git目录出现在vendor的包内
- java接口与类之间继承小例题(1)
- PythonNewHere--Python列表与元组基本函数与操作