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. System Operations on AWS - Lab 1W - Creating EC2 (Windows)

    1. 创建CommandHost实例,登录到CommandHost,通过AWS CLI创建WebServer实例. 1.1 为CommandHost实例创建一个IAM角色 1.2 创建CommandH ...

  2. PLSQL Developer操作

    1.设置 1)下载32位Oracle InstantClient  2)将Oracle InstantClient解压到某目录  3)设置环境变量(修改NLS_LANG和TNS_ADMIN环境变量)对 ...

  3. 常用js代码学习

    1.用JS实现的radio图片选择按钮效果 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &q ...

  4. PHP 时间函数集合

    计算指定日期的前几天,几个月或者几年的函数 $a = '2014/08/21';echo date( "Y-m-d", strtotime( "-6 month  &qu ...

  5. CALayer 认识

    一篇很好的讲述calayer的博客 http://www.cnblogs.com/kenshincui/p/3972100.html

  6. C#动态二维数组输出

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...

  7. CSV文件规则

    CSV文件规则 1 开头是不留空,以行为单位.2 可含或不含列名,含列名则居文件第一行.3 一行数据不跨行,无空行.4 以半角逗号(即,)作分隔符,列为空也要表达其存在.5 列内容如存在半角逗号(即, ...

  8. html5与js关于input[type='text']文本框value改变触发事件一些属性的区别oninput,onpropertychange,onchange和文本框的value点击全选状态onclick="select();"。做购物车页面时会要用到。

    关于input[type='text']文本框value改变触发事件一些属性的区别oninput,onpropertychange,onchange和文本框的点击全选状态onclick="s ...

  9. 打印出不同顺序的字符串&单引号和双引号的差异

    发现一个很好玩的打印顺序 package com.liaojianya.chapter1; /** * This program demonstrates the string. * @author ...

  10. HDU 3006 The Number of set(位运算 状态压缩)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3006 题目大意:给定n个集合,每个集合都是由大于等于1小于等于m的数字组成,m最大为14.由给出的集合 ...