题意

A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.

Return a deep copy of the list.

Subscribe to see which companies asked this question.

解法

回头补上

实现

/*** 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 *splitCopyList(RandomListNode* head){RandomListNode* copyhead = head->next;RandomListNode* cur = head;while(cur != NULL){RandomListNode* ccur = cur->next;cur->next = ccur->next;if(cur->next != NULL) ccur->next = cur->next->next;else ccur->next = NULL;cur = cur->next;}return copyhead;}RandomListNode *copyRandomRela(RandomListNode* head){RandomListNode* cur = head;while(cur != NULL){RandomListNode* random = cur->random;RandomListNode* ccur = cur->next;if(random != NULL){ccur->random = random->next;}cur = ccur->next;}return head;}RandomListNode *copyNextRela(RandomListNode* head){RandomListNode* cur = head;while(cur != NULL){RandomListNode* ccur = new RandomListNode(cur->label);ccur->next = cur->next;cur->next = ccur;cur = ccur->next;}return head;}RandomListNode *copyRandomList(RandomListNode *head) {if(head == NULL) return head;RandomListNode* nextHead = copyNextRela(head);RandomListNode* randomHead = copyRandomRela(head);RandomListNode* copyHead = splitCopyList(randomHead);return copyHead;}
};

LeetCode-M-Copy List with Random Pointe相关推荐

  1. LeetCode 138. Copy List with Random Pointer

    LeetCode 138. Copy List with Random Pointer 参考链接:http://www.cnblogs.com/grandyang/p/4261431.html Sol ...

  2. 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 ...

  3. [LeetCode] Copy List with Random Pointe

    题目的关键是要让新链表和原有链表发送关联,可以通过这种关联来设置新链表的random pointer 思路:将新链表的元素插入到原有链表元素的后面,如下图所示,就可以根据原有链表的radom-> ...

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

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

  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 138 Copy List With Random Pointer

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

  8. 138. Copy List with Random Pointer

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

  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 ...

  10. [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. 2021-02-23 如何用简单易懂的例子解释条件随机场(CRF)模型?它和HMM有什么区别?从HMM、MEMM、CRF某牛自己总结的
  2. iptables配置管理
  3. 【Android 安装包优化】WebP 图片格式性能测试 ( 测试 WebP 图片解码速度 | 测试 WebP 图片编码速度 )
  4. python自动访问网页_Python自动化 selenium 网页自动化-在访问一个网页时弹出的浏览器窗口,我该如何处理?...
  5. linux启动tongweb命令,linux7开机自启动东方通tongweb
  6. es分页查询重复数据_ES优化 - 巨量数据如何提高查询性能
  7. Android中用文件初始化sqlite 数据库(二)
  8. Eclipse Qt开发环境的建立【转】
  9. LiteIDE中运行GO
  10. windows创建bat文件进行截图
  11. 大数据分析平台搭建指南
  12. 挑战全网目前最全python例子(附源码),独此一家,经典值得收藏!!!(五):Python绘图,Python实战
  13. K-means聚类攻击类型
  14. Wifi热点java_java实现笔记本电脑设置成WiFi热点
  15. 使用微擎后台授权须知
  16. 2019年最新的一波手机APP分享,每一个都是大家的菜哦!
  17. java面试题有哪些?
  18. python网络编程学什么_python网络编程学习《一》
  19. bzoj 3398: [Usaco2009 Feb]Bullcow 牡牛和牝牛
  20. Elasticsearch在Linux中的单节点部署和集群部署

热门文章

  1. KMM(Kotlin Multiplatform Mobile)环境搭建
  2. 大数据增量采集OGGAdapter的安装部署与相关配置
  3. 买保险前的27条必读
  4. transform动画
  5. 关于ActiveMQ消息队列不消费的思考
  6. sv中关于coverage的写法
  7. 小学计算机工作总结第一学期,第一学期信息技术教师教学工作总结
  8. ro手游服务器维护公告,《仙境传说RO守护永恒的爱》7月29日停服维护公告
  9. 03-menuStrip设置带有复选框的按钮
  10. java contains 效率_java String contains逻辑的优化