LeetCode 138. Copy List with Random Pointer

参考链接:http://www.cnblogs.com/grandyang/p/4261431.html
Solution1:
此题同《剑指offer》的第26题,只记住了其一,没记住其二。。。

/*** Definition for singly-linked list with a random pointer.* struct RandomListNode {*     int label;*     RandomListNode *next, *random;*     RandomListNode(int x) : label(x), next(NULL), random(NULL) {}* };*/
class Solution {
public:RandomListNode *copyRandomList(RandomListNode *head) {if (!head) return NULL;RandomListNode *cur = head;while (cur) {RandomListNode *node = new RandomListNode(cur->label);node->next = cur->next;cur->next = node;cur = node->next;}cur = head;while (cur) {if (cur->random) {cur->next->random = cur->random->next;}cur = cur->next->next;}cur = head;RandomListNode *res = head->next;while (cur) {RandomListNode *tmp = cur->next;cur->next = tmp->next;if(tmp->next) tmp->next = tmp->next->next;cur = cur->next;}return res;}
};

LeetCode 138. Copy List with Random Pointer相关推荐

  1. Leetcode 138 Copy List With Random Pointer

    题目描述 A linked list is given such that each node contains an additional random pointer which could po ...

  2. leetcode 138. Copy List with Random Pointer | 138. 复制带随机指针的链表(复杂链表的复制)

    题目 https://leetcode.com/problems/copy-list-with-random-pointer/ 题解 复杂链表的复制,经典问题,考察与 HashMap 的结合.注意如果 ...

  3. 138. Copy List with Random Pointer

    /** 138. Copy List with Random Pointer * 2016-5-22 by Mingyang* 要遍历两次,第一次用来找到所有的next节点,并且把新旧节点全部存在ha ...

  4. leetcode -day8 Copy List with Random Pointer Single Number I II

    五一中间断了几天,开始继续... 1.  Copy List with Random Pointer A linked list is given such that each node cont ...

  5. LeetCode OJ - Copy List with Random Pointer

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

  6. 【LeetCode】Copy List with Random Pointer

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

  7. LeetCode Copy List with Random Pointer

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

  8. [Leetcode] Copy list with random pointer 对带有任意指针的链表深度拷贝

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

  9. LeetCode || Copy List with Random Pointer

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

最新文章

  1. axure怎么做5秒倒计时_如何用Axure做倒计时,由分到秒?
  2. MPLS 的组成:路由器和交换机的作用——Vecloud
  3. 51 nod 1427 文明 (并查集 + 树的直径)
  4. 寄存器(cpu工作原理)
  5. HNOI2010——弹飞绵羊(lct)
  6. 你认识的老罗又回来了!罗永浩:我的创造力才刚刚开始猥琐发育
  7. java 自定义报表_设计好的报表是如何在 web 上显示的
  8. 理解javascript:void(0);和href=#
  9. 个人h5第三方支付接口_个人免签支付接口系统搭建源码多种方式
  10. s400x ugee 驱动_联想_ThinkPad|ThinkCentre|ThinkStation服务与驱动下载_常见问题
  11. Distral: Robust multitask reinforcement learning.
  12. Pycharm this applicatation failed to start because it could not find or laod the qt plaform plugin
  13. “笨办法学python”学习笔记-一些附加题
  14. XYplorer 20.90.0900中文版 — 资源管理器
  15. 自己的邮箱还有在用吗,还安全吗?
  16. 小世界效应:从凯文·贝肯到六度分隔理论(1)
  17. 【CC2530的点对点无线通讯开发(包含BasicRf协议栈、双击、长按、呼吸灯、跑马灯)】
  18. ubuntu18 百度云盘
  19. 用Ubuntu编写第一个C程序并预处理、编译、汇编、链接
  20. react中的css(css in js)

热门文章

  1. 一些关于虚拟交易的有趣文章
  2. tensorflow随笔——LeNet网络
  3. 150分试卷c语言,连续5道C语言题目一共送150分啊,题目2.一个农场有头母牛,现 爱问知识人...
  4. html5动画在线制作工具,KoolShow-KoolShow(HTML5动画制作工具) v2.4.4 官方版-CE安全网...
  5. python处理二进制文件_使用Python进行二进制文件读写的简单方法(推荐)
  6. 安阳学院有几次计算机考试,安阳:2017年上半年全国计算机等级考试顺利结束...
  7. untubu安装mysql_简单操作阿里云untubu服务器并且配置LAMP环境
  8. python api接口10060_Python web抓取[错误10060]
  9. python数据加载常规教程_Python加载数据的5种不同方式(收藏)
  10. linux /proc/stat 计算线程cpu,Linux下用/proc/stat文件来计算cpu的利用率(附源码)