当前位置:网站首页>Sword finger offer 35. replication of complex linked list
Sword finger offer 35. replication of complex linked list
2022-07-28 10:54:00 【jjj34】
Title Description

Knowledge point :
1. Hashtable Relevant knowledge points of hash table _jcxj2934 The blog of -CSDN Blog
2. Related knowledge of linked list : The finger of the sword Offer 06. Print linked list from end to end _jcxj2934 The blog of -CSDN Blog
The idea and code are as follows :
Writing reference leetcode Official answer
/*
// Definition for a Node.
class Node {
int val;
Node next;
Node random;
public Node(int val) {
this.val = val;
this.next = null;
this.random = null;
}
}
*/
class Solution {
HashMap<Node,Node> map = new HashMap<>();
public Node copyRandomList(Node head) {
// Through the first next Create a new linked list <1>
// Give it after you create it random assignment
// do random You can go through hash Table to quickly find the new node corresponding to the old node
//key It is an old linked list node ,value Is a new linked list node
if(head == null)
{
return null;
}
// If the node doesn't exist , create <1>
// stay next It doesn't exist when traversing , So this one if Is to pass next Create all the new linked lists
if(!map.containsKey(head))
{
Node headnew = new Node(head.val);
map.put(head,headnew);
headnew.next = copyRandomList(head.next);
headnew.random = copyRandomList(head.random);
}
// by random Only when you assign a value , Return to new node
return map.get(head);
}
}边栏推荐
- GKConstantNoiseSource
- Go memory model (version on May 31st, 2014)
- Characteristics and installation of non relational database mongodb
- Advance.ai sailing guide helps enterprises sail to Indonesia and grasp half of the Southeast Asian market
- Attention attention mechanism flow chart
- Blue Bridge Cup embedded Hal library ADC
- CGAL compilation error
- GKBillowNoiseSource
- Judge whether the nixie tube is a common anode or a common cathode
- The Xiongguan pass is like an iron road, and now we are going to cross it from the beginning
猜你喜欢

蓝桥杯嵌入式-HAL库-USART_RX

10_ UE4 advanced_ Add fall and cast actions

GKRidgedNoiseSource

MySQL Architecture Principle
c语言进阶篇:指针(一)

Blue Bridge Cup embedded Hal library USART_ RX

GKSpheresNoiseSource

Attention attention mechanism flow chart

Configuring raspberry pie, process and problems encountered

Pyqt5 rapid development and practice 4.12 calendar and time
随机推荐
CRM+零代码:轻松实现企业信息化
11_ue4进阶_男性角色换成女性角色,并修改动画
Here is a super practical excel shortcut set (common + summary of eight categories)
nodejs:搭建express 服务,设置session以及实现退出操作
GKObstacle
ICML 2022 | graph represents the structure aware transformer model of learning
从零开始Blazor Server(2)--整合数据库
JDBC各个类的解释
02.1.2. logic type bool
GKCoherentNoiseSource
OCR 知识 概括
粒子群解决tsp的技术问题
数组相关的知识点
学会这些分析方法及模型,遇到问题不再没思路
哈希表的相关知识点
低代码(aPaas)为什么最近又火了?
GKPolygonObstacle
乱打日志的男孩运气怎么样我不知道,加班肯定很多
Semeval 2022 | introducing knowledge into ner system, aridamo academy won the best paper award
Network file system service (NFS)