1、题目描述

2、问题分析

首先要完成一个普通的单链表的深度复制,然后将一个旧的单链表和新的单链表的节点使用map对应起来,最后,做一次遍历即可。

3、代码

 RandomListNode *copyRandomList(RandomListNode *head) {
if( head == NULL){
return NULL;
}
RandomListNode* newhead = new RandomListNode();
RandomListNode* np = newhead; RandomListNode* p = head;
map<RandomListNode*, RandomListNode*> m;
while (p != NULL){
RandomListNode* tmp = new RandomListNode(p->label);
m.insert(make_pair(p,tmp));
np->next = tmp;
np = np->next;
p = p->next;
} p = head ;
np = newhead->next;
while( p != NULL){
np->random = m[p->random];
p = p->next;
np = np->next;
}
return newhead->next; }

LeetCode题解之Copy List with Random Pointer的更多相关文章

  1. 【LeetCode练习题】Copy List with Random Pointer

    Copy List with Random Pointer A linked list is given such that each node contains an additional rand ...

  2. 【LEETCODE OJ】Copy List with Random Pointer

    Problem link: http://oj.leetcode.com/problems/copy-list-with-random-pointer/ Deepcopy a linked list ...

  3. 【LeetCode】138. Copy List with Random Pointer

    题目: A linked list is given such that each node contains an additional random pointer which could poi ...

  4. LeetCode OJ:Copy List with Random Pointer(复制存在随机链接的链表)

    A linked list is given such that each node contains an additional random pointer which could point t ...

  5. 【LeetCode】138. Copy List with Random Pointer 复制带随机指针的链表 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人公众号:负雪明烛 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https:/ ...

  6. [Leetcode Week17]Copy List with Random Pointer

    Copy List with Random Pointer 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/copy-list-with-random- ...

  7. Copy List with Random Pointer leetcode java

    题目: A linked list is given such that each node contains an additional random pointer which could poi ...

  8. 16. Copy List with Random Pointer

    类同:剑指 Offer 题目汇总索引第26题 Copy List with Random Pointer A linked list is given such that each node cont ...

  9. 133. Clone Graph 138. Copy List with Random Pointer 拷贝图和链表

    133. Clone Graph Clone an undirected graph. Each node in the graph contains a label and a list of it ...

随机推荐

  1. 公共技术点(Android 动画基础)

    转载地址:http://p.codekk.com/blogs/detail/559623d8d6459ae793499787 一 传统 View 动画(Tween/Frame) 1.1 Tween 动 ...

  2. JavaScript对象Object

    <script> var obj = new Object(); var obj2 = {}; obj2.firstName = "wang"; obj2.lastNa ...

  3. INTEST/EXTEST SCAN 的学习

    intest scan的一些基本知识.INTEST scan指的是对IP 内部的scan cell的扫描测试,针对IP内部的flip-flop进行shift/capture的操作.和INTEST SC ...

  4. UIKit 框架之UIControl

    前面的UIWebView.UIImageView这些都是视图,显示为主,与用户交互较少,最多也就是通过UIResponder与用户交互.但这样会很麻烦,还要判断点击次数等等问题,那问题就来了:OC中怎 ...

  5. [转][MVC4]ASP.NET MVC4+EF5(Lambda/Linq)读取数据

    本文转自:https://blog.csdn.net/dingxiaowei2013/article/details/29405687 继续上一节初始ASP.NET MVC4,继续深入学习,感受了一下 ...

  6. [Angularjs]cookie操作

    摘要 现在很多app采用内嵌h5的方式进行开发,有些数据会存在webveiw的cookie中,那么如果使用angularjs开发单页应用,就需要用到angularjs的cookie操作.这里提供一个简 ...

  7. CPU简单科普

    CPU简单科普 本文仅限于对小白科普. 误解一:CPU使用率和硬盘使用率一样. 误解二:一台电脑只有一个CPU. 误解三:CPU的核数,就是CPU的数量. 误解三:CPU主频越高越厉害:CPU核数越多 ...

  8. Redis集合操作

    Redis的集合以无序的形式存储多个各不相同的元素 (常用的集合命令) SADD : SADD key-name item [item ...]----------将一个或多个元素添加到集合里,并返回 ...

  9. Spring源码分析:非懒加载的单例Bean初始化过程(下)

    上文Spring源码分析:非懒加载的单例Bean初始化过程(上),分析了单例的Bean初始化流程,并跟踪代码进入了主流程,看到了Bean是如何被实例化出来的.先贴一下AbstractAutowireC ...

  10. SQL:多表联合更新

    update 表一 set 表一.列1 = 表二.列1 from 表一,表二 where 表一.列2 = 表二.列2