复杂链表的复制
来源:互联网 发布:js把毫秒数转换成日期 编辑:程序博客网 时间:2024/06/07 10:51
/** * Definition for singly-linked list with a random pointer. * class RandomListNode { * int label; * RandomListNode next, random; * RandomListNode(int x) { this.label = x; } * }; */import java.util.HashMap;public class Solution { public RandomListNode copyRandomList(RandomListNode head) {if(head == null) return null; HashMap<RandomListNode,RandomListNode> map = new HashMap<RandomListNode,RandomListNode>(); RandomListNode cur = head; RandomListNode headCopy = new RandomListNode(head.label),curCopy=headCopy; map.put(cur, headCopy); cur = cur.next; while(cur != null){ RandomListNode temp = new RandomListNode(cur.label); curCopy.next = temp; curCopy = temp; map.put(cur, curCopy); cur = cur.next; } cur = head; curCopy = headCopy; while(cur != null){ if(cur.random!=null) curCopy.random = map.get(cur.random); cur = cur.next; curCopy = curCopy.next; } return headCopy; }}
题目描述
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.
阅读全文
0 0
- 复杂链表的复制
- 复杂链表的复制
- 复杂链表的复制
- 复杂链表的复制
- 复杂链表的复制
- 复杂链表的复制
- 复杂链表的复制
- 复杂链表的复制
- 复杂链表的复制
- 复杂链表的复制
- 复杂链表的复制
- 复杂链表的复制
- 复杂链表的复制
- 复杂链表的复制
- 复制复杂的链表
- 复杂链表的复制
- 复杂链表的复制
- 复杂链表的复制
- nrf51822-主从通信分析1
- Android studio无线调试
- 脉冲云为何要用docker
- 2.1 通过极限获得切线斜率
- nrf51822-主从通信分析2
- 复杂链表的复制
- JS数组去重2017
- org.dom4j.DocumentException: null Nested exception: null
- linux给文件授权
- windows 使用sc命令将程序注册成服务 实现后台运行开机自启
- 抓包工具Fidder详解(主要来抓取Android中app的请求)
- Spark的Master,Worker调试
- 为什么要设置Java环境变量(详解)
- oracle sql日期比较