Leetcode--Swap Nodes in Pairs
最傻的方法:
- ListNode *swapPairs(ListNode *head) {
- if (head == NULL)
- return NULL;
- ListNode *temp = );
- ListNode *head_2 = temp;
- while (head != NULL && head->next != NULL) {
- temp = temp->next = new ListNode(head->next->val);
- temp = temp->next = new ListNode(head->val);
- head = head->next->next;
- }
- if (head != NULL)
- temp->next = head;
- return head_2->next;
- }
好一点的方法
- ListNode* swapPairs(ListNode* head) {
- if(!head || !head->next)
- return head;
- ListNode * temp = head->next;
- head->next = swapPairs(temp->next);
- temp->next = head;
- return temp;
- }
Leetcode--Swap Nodes in Pairs的更多相关文章
- LeetCode: Swap Nodes in Pairs 解题报告
Swap Nodes in Pairs Given a linked list, swap every two adjacent nodes and return its head. For exam ...
- [LeetCode]Swap Nodes in Pairs题解
Swap Nodes in Pairs: Given a linked list, swap every two adjacent nodes and return its head. For exa ...
- [LeetCode] Swap Nodes in Pairs 成对交换节点
Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2-&g ...
- leetcode—Swap Nodes in Pairs
1.题目描述 Given a linked list, swap every two adjacent nodes and return its head. For example, Given ...
- Leetcode:Swap Nodes in Pairs 单链表相邻两节点逆置
Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2-& ...
- [LeetCode]Swap Nodes in Pairs 成对交换
Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2-& ...
- [Leetcode] Swap nodes in pairs 成对交换结点
Given a linked list, swap every two adjacent nodes and return its head. For example,Given1->2-> ...
- LeetCode Swap Nodes in Pairs 交换结点对(单链表)
题意:给一个单链表,将其每两个结点交换,只改尾指针,不改元素值. 思路:迭代法和递归法都容易写,就写个递归的了. 4ms /** * Definition for singly-linked list ...
- leetcode Swap Nodes in Pairs python
# Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = ...
- 【LeetCode】Swap Nodes in Pairs 链表指针的应用
题目:swap nodes in pairs <span style="font-size:18px;">/** * LeetCode Swap Nodes in Pa ...
随机推荐
- iOS 解决图片上传到服务器旋转90度的问题(图片倒置)
//使用swift的朋友们可以,把这个所在的类的.h,在-Header-Swift.h中一用一下. - (UIImage *)fixOrientation:(UIImage *)aImage { if ...
- WebLogic集群体系架构
WebLogic Server集群概述 WebLogic Server 群集由多个 WebLogic Server 服务器实例组成,这些服务器实例同时运行并一起工作以提高可缩放性和可靠性.对于客户端 ...
- 005_重写 Standard Delete Button
以后会用JS直接删除,但是在加载.js时候出现问题,会在以后进一步追踪完善: <apex:page standardController="Opportunity" > ...
- Codefroces 750C:New Year and Rating(思维)
http://codeforces.com/contest/750/problem/C 题意:有n场比赛,每场比赛有一个c,代表比赛结束后分数的增长情况,有一个d,代表这场比赛在div1或者div2打 ...
- Android4.0 添加一个新的Android 键值
这里添加新的键值,不是毫无凭据凭空创造的一个键值,而是根据kernel中检测到的按键值,然后转化为Android所需要的数值: 以添加一个Linux键值为217,把它映射为android的键值Brow ...
- javascript数据属性和访问器属性
var book={ _year:2004, edition:1};Object.defineProperty(book,"year",{ get:function(){ retu ...
- js 两个滚动事件相互影响
document.addEventListener('scroll', function(event) { if (event.target.id === 't_r_content') { // or ...
- js 、jsdoc生成33
============== js 点击事件后没方法名,调用有方法名 document.getElementById('lind').onclick=abc;//传统的id选择器 中没有# 哦 fun ...
- 年终汇报、总结、述职:教你做一场B格满满的技术大会演讲
什么样的演讲和呈现最受听众欢迎,内容干货?逻辑清晰?长相帅气? 偶尔被邀作为speaker参加一些圈内的技术大会进行演讲.这里我分享下自己的经验,如何做一场B格满满的技术大会演讲,希望给做汇报.总结. ...
- Hibernate 继承映射
@Entity@Inheritance(strategy=InheritanceType.SINGLE_TABLE)@DiscriminatorColumn()public class Animal ...