leetcode交换相邻的两个节点的值
来源:互联网 发布:知达常青藤中学校费用 编辑:程序博客网 时间:2024/05/17 01:23
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.
Subscribe to see which companies asked this question
这个也就是改天两个相邻的节点的值
这段代码使用的试类似交换两个数的值,然后使用了递归,
代码:
/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */struct ListNode* swapPairs(struct ListNode* head) { if(head==NULL||head->next==NULL) return head; struct ListNode *tmp=head->next; head->next=swapPairs(tmp->next); tmp->next=head; return tmp; }
0 0
- leetcode交换相邻的两个节点的值
- (LeetCode)Swap Nodes in Pairs --- 交换两个相邻的结点
- 交换单向链表的相邻节点
- 交换链表中相邻节点的位置
- 交换单链表中相邻的两个点(人搜)
- 单链表相邻两个节点之间交换顺序
- Swap Nodes in Pairs 链表交换相邻的节点
- Swap Nodes in Pairs 交换LinkList的相邻节点
- [LeetCode] 一个BST的两个节点的值被交换,要求修正这个BST
- Java单链表基本操作(九)--交换相邻节点对的值
- 交换单链表中相邻的两个元素 Swap Nodes in Pairs
- 8.通过调整链来交换两个相邻的元素
- 只调整指针来交换两个相邻的元素【单链表】
- 只调整指针来交换两个相邻的元素【双链表】
- 交换单链表的任意两个节点
- LeetCode OJ 之 Swap Nodes in Pairs (交换成对相邻结点的值)
- LeetCode 重构二叉搜索数,即找出两个被交换的节点
- 访问相邻的兄弟节点
- Ubuntu下安装hive,并配置mysql作为元数据库
- TBSchedule原理与实践
- UVA12333--Revenge of Fibonacci
- 167. Two Sum II - Input array is sorted 难度:medium
- C++关于堆上与栈上分配对象
- leetcode交换相邻的两个节点的值
- 用Python做投资-关于term spread
- 内存初始化(上)
- Laxcus大数据管理系统单机集群版
- Android中的调色板功能的实现
- 71. Simplify Path
- emacs注释快捷键
- 四种C#实现播放声音的方法,如DirectX ,SoundPlayer, Windows Media Player
- pandas处理excel数据经验