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.

题意:给出一个链表,包含next和random结点,作深拷贝

思路:链表的遍历操作

代码如下:

class RandomListNode
{int label;RandomListNode next, random;RandomListNode(int x) {this.label = x;}
}
class Solution
{public RandomListNode copyRandomList(RandomListNode head){if (null == head) return null;RandomListNode new_head = new RandomListNode(head.label);RandomListNode current = head, new_current = new_head;while (current != null){if (current.next != null){new_current.next = new RandomListNode(current.next.label);}if (current.random != null){new_current.random = new RandomListNode(current.random.label);}current = current.next;new_current = new_current.next;}return new_head;}
}

LeetCode Copy List with Random Pointer相关推荐

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

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

  2. LeetCode || Copy List with Random Pointer

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

  3. LeetCode 138. Copy List with Random Pointer

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

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

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

  6. LeetCode OJ - Copy List with Random Pointer

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

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

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

  9. Copy List with Random Pointer

    https://leetcode.com/problems/copy-list-with-random-pointer/ A linked list is given such that each n ...

最新文章

  1. [js] MD5算法
  2. docx文件上传java_java上传文件通过mybatis存储到数据库的blob格式中.docx
  3. linux ls in*,35 ls Command Examples in Linux (The Complete Guide)
  4. CSS+HTML+JQuery简单菜单
  5. 复制:王垠:数学和编程
  6. weka矿产分布文件_石材人注意!北方暴雪将至,货车停运,石材停止发货!(附北方石材分布介绍)...
  7. python聊天程序程序代码_python聊天程序实例代码分享 -电脑资料
  8. qq,微信抓句柄发送信息
  9. 我在Facebook工作四年的总结与反思
  10. 冰川时代4中英台词全集
  11. 跨维度的打击,是可以直接秒杀的
  12. Towards Accurate Scene Text Recognition with Semantic Reasoning Networks
  13. python自学软件-学习python用什么软件
  14. gson 解析int类型转换为double解决方案
  15. python求两数最大公因数_Python求两个数的最大公约数
  16. 支持在线大数据SQL查询平台开源项目
  17. 青龙面板库 大全(9.6更新)
  18. RINEX3 版本 Observation codes 介绍
  19. 熔断器Hystrix配置及使用
  20. java恒大集团面试经验,教你如何通过万科恒大面试 顺利拿到一流房企offer

热门文章

  1. 四种方案解决ScrollView嵌套ListView问题
  2. [置顶] 给Fedora修改默认的软件下载源
  3. 初学者自学python要看什么书-学习Python可以看书籍学习吗?老男孩Python入门课程...
  4. python手机版打了代码运行不了-三款可以在安卓手机上运行Python代码的软件
  5. python如何调用图片-python调用图片
  6. 零基础自学python的app-零基础入门免费学Python 课程和APP推荐
  7. python自动化干什么-python已经自动化了,大家一般用什么测试框架?
  8. python3.7下载安装教程-CentOS 7 下 安装 Python3.7
  9. python科学计算基础教程pdf下载-python科学计算 第二版 PDF 下载
  10. python中怎么输出中文-python中使用print输出中文的方法