Copying Linked Lists with Random Pointers

两个方法:
方法一:

1.不考虑随机指针的情况下复制链表;

2.在复制过程中建立一个以原链表节点地址为key,相应的复制链表节点地址为value的hash;

3.遍历原链表和新链表,得到原链表随机指针值,并复制给新链表。

方法二:

1.忽略随机指针值复制链表第n个节点并插入到第n个节点与第n+1个节点之间,以此为方式修改链表直到链表尾。

2.利用链表节点next指针指向节点的的拷贝这一已知,使用如下语句:

 srcCurrent->next->random = srcCurrent->random->next;

3.分开链表

srcCurrent->next = srcCurrent->next->next;
cpyCurrent->next = cpyCurrent->next->next;

  

Copying Linked Lists with Random Pointers的更多相关文章

  1. [Linked List]Intersection of Two Linked Lists

    Total Accepted: 53721 Total Submissions: 180705 Difficulty: Easy Write a program to find the node at ...

  2. LeetCode之“链表”:Intersection of Two Linked Lists

    此题扩展:链表有环,如何判断相交? 参考资料: 编程判断两个链表是否相交 面试精选:链表问题集锦 题目链接 题目要求: Write a program to find the node at whic ...

  3. 2016.5.24——Intersection of Two Linked Lists

    Intersection of Two Linked Lists 本题收获: 1.链表的输入输出 2.交叉链表:这个链表可以有交叉点,只要前一个节点的的->next相同即可. 题目:Inters ...

  4. LeetCode: Intersection of Two Linked Lists 解题报告

    Intersection of Two Linked Lists Write a program to find the node at which the intersection of two s ...

  5. [LeetCode] 160. Intersection of Two Linked Lists 求两个链表的交集

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...

  6. [LeetCode] Intersection of Two Linked Lists 求两个链表的交点

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...

  7. 【leetcode】Intersection of Two Linked Lists

    题目简述: Write a program to find the node at which the intersection of two singly linked lists begins. ...

  8. [LintCode] Intersection of Two Linked Lists 求两个链表的交点

    Write a program to find the node at which the intersection of two singly linked lists begins. Notice ...

  9. Intersection of Two Linked Lists

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...

随机推荐

  1. Java基础知识强化之集合框架笔记53:Map集合之Map集合的遍历 键值对对象找键和值

    1. Map集合的遍历(键值对对象找键和值) Map -- 夫妻对  思路:  A: 获取所有结婚证的集合  B: 遍历结婚证的集合,得到每一个结婚证  C: 根据结婚证获取丈夫和妻子 转换:  A: ...

  2. txt无法正常保存正文的解决办法

    最近遇到一个问题,txt文档中写了中文,则保存的时候 就会提示“该文件含有unicode格式字符,当文件保存为ANST编码文本文件时,该字符将会丢失”.虽然有解决办法,但不彻底,用起来总是很费劲,研究 ...

  3. C# FileSystemWatcher 监视磁盘文件变更

    简化需求:有一个简化了的需求是这样的:有一个拍照程序在运行,一旦抓拍之后则将图片文件存储至某目录,然后图片要上传至远程服务器并update数据库. 原需求:原先的需求是这样的:有一台PDA扫码枪,一个 ...

  4. JDK自带方法实现RSA非对称加密

    package jdbc.pro.lin; import java.security.InvalidKeyException; import java.security.Key; import jav ...

  5. css中判断IE版本的语句

    css中判断IE版本的语句<!--[if gte IE 6]> Only IE 6/+ <![endif]-->: 1. <!--[if !IE]> 除IE外都可识 ...

  6. php递归创建目录

    /** * 递归创建目录 * @param [string] $path [创建的目录] * @return [type] [description] */ function mk_Dir($path ...

  7. 网页Gzip

    网页Gzip压缩检测工具 网站Gzip压缩可以减小服务器带宽占用,提高用户打开网页速度,最多可以提升网站80%的性能,是每个网站必须开启的功能, 站长工具网页 Gzip压缩检测工具方便站长朋友们检测特 ...

  8. 为什么JS动态生成的input标签在后台有时候没法获取到

    最近在做一个产品添加的功能,需求有点奇葩,所以在添加的时候免不了要用到动态生成控件,然后我就使用了JS去动态生成一些 checkbox类型的input标签,在以前用asp.net在后台生成的input ...

  9. CentOS PHP-5.4.8 编译安装之初体验

    1. 下载5.4.8 版本 [root@Test data] wget http://museum.php.net/php5/php-5.4.8.tar.gz 2. 解压 [root@Test php ...

  10. 编写适合windows 7 平台的软件,给程序添加UAC认证

    Delphi程序必须在资源里面嵌入MANIFEST信息 一. 首先编辑一个文件,内容如下: <?xml version="1.0" encoding="UTF-8& ...