当前位置: 首页 > news >正文

网站怎样设计网页外包接单平台

网站怎样设计网页,外包接单平台,不锈钢网片,网站建设运动会成绩管理系统**138.**给你一个长度为 n 的链表,每个节点包含一个额外增加的随机指针 random ,该指针可以指向链表中的任何节点或空节点。 构造这个链表的 深拷贝。 深拷贝应该正好由 n 个 全新 节点组成,其中每个新节点的值都设为其对应的原节点的值。新节…

**138.**给你一个长度为 n 的链表,每个节点包含一个额外增加的随机指针 random ,该指针可以指向链表中的任何节点或空节点。
构造这个链表的 深拷贝。 深拷贝应该正好由 n 个 全新 节点组成,其中每个新节点的值都设为其对应的原节点的值。新节点的 next 指针和 random 指针也都应指向复制链表中的新节点,并使原链表和复制链表中的这些指针能够表示相同的链表状态。复制链表中的指针都不应指向原链表中的节点 。
例如,如果原链表中有 X 和 Y 两个节点,其中 X.random --> Y 。那么在复制链表中对应的两个节点 x 和 y ,同样有 x.random --> y 。
返回复制链表的头节点。
用一个由 n 个节点组成的链表来表示输入/输出中的链表。每个节点用一个 [val, random_index] 表示:
val:一个表示 Node.val 的整数。
random_index:随机指针指向的节点索引(范围从 0 到 n-1);如果不指向任何节点,则为 null 。
你的代码 只 接受原链表的头节点 head 作为传入参数。
示例 1:
输入:head = [[7,null],[13,0],[11,4],[10,2],[1,0]]
输出:[[7,null],[13,0],[11,4],[10,2],[1,0]]
示例 2:
输入:head = [[1,1],[2,1]]
输出:[[1,1],[2,1]]
示例 3:
输入:head = [[3,null],[3,0],[3,null]]
输出:[[3,null],[3,0],[3,null]]

  •   /*// 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;}}*/
    
  • 我的原始人解法:先遍历一遍链表,复制出没有 random 的链表,与此同时记录下每个原结点对应的复制节点。第二轮遍历的时候复制 random 即可:
  •   public Node copyRandomList(Node head) {Map<Node,Node> map = new HashMap<>();// 头部加了一个哑结点Node node = new Node(-1);Node temp = node;Node tempHead = head;while(head!=null){node.next = new Node(head.val);map.put(head,node.next);head=head.next;node=node.next;}head = tempHead;node = temp;while(head!=null){Node random = map.get(head.random);node.next.random = random;head=head.next;node=node.next;}return temp.next;}
    
  • 或者可以像他人题解先只是创建每个节点,第二轮遍历的时候直接在 map 中把节点连起来创建链表
  •   public Node copyRandomList(Node head) {if(head == null) return null;Node cur = head;Map<Node, Node> map = new HashMap<>();// 3. 复制各节点,并建立 “原节点 -> 新节点” 的 Map 映射while(cur != null) {map.put(cur, new Node(cur.val));cur = cur.next;}cur = head;// 4. 构建新链表的 next 和 random 指向while(cur != null) {map.get(cur).next = map.get(cur.next);map.get(cur).random = map.get(cur.random);cur = cur.next;}// 5. 返回新链表的头节点return map.get(head);}
    
  • 还有个巧妙的思路,构建一个新的拼接链表为:原节点1 -> 新节点1 -> 原节点2 -> 新节点1 ->…。然后你只需要遍历这个链表,新结点的 next 就为该节点的 next 的 next,新结点的 random 就为原结点的 random 的 next。其实这也是一种原节点对应新节点的形式,只不过在 map 中表现为 key->val,在这里表现为 node -> node.next。
  •   public Node copyRandomList(Node head) {if(head == null){return null;}// 暂存头结点,待会用来重新遍历Node tempHead = head;// 拼接新链表while(head != null){Node node = new Node(head.val);node.next = head.next;head.next = node;head = node.next;}// 头结点复原,再遍历一遍构建新链表 random 的指向head = tempHead;while(head != null){if(head.random != null){head.next.random = head.random.next;}head = head.next.next;}// 头结点再复原,最后遍历一遍拆分出原链表和结果链表head = tempHead;// 最后结果的头结点,下面用来遍历Node ans = head.next;// 暂存最后结果的头结点Node tempAns = ans;// 构建到尾结点就不构建了,所以是 ans.next != null,也没 next 让你继续构建了while(ans.next != null){// 或者 head.next = head.next.nexthead.next = ans.next;head = head.next;ans.next = head.next;ans = ans.next;}// 原链表尾结点复原head.next = null;return tempAns;}
    

文章转载自:
http://hookshop.bbtn.cn
http://stacte.bbtn.cn
http://axiologist.bbtn.cn
http://alanyl.bbtn.cn
http://onlend.bbtn.cn
http://fondle.bbtn.cn
http://supersystem.bbtn.cn
http://leatherworking.bbtn.cn
http://multivallate.bbtn.cn
http://rebulid.bbtn.cn
http://cabana.bbtn.cn
http://dangerous.bbtn.cn
http://impassable.bbtn.cn
http://eugenic.bbtn.cn
http://spiffy.bbtn.cn
http://edinburghshire.bbtn.cn
http://lomilomi.bbtn.cn
http://tiptop.bbtn.cn
http://surfie.bbtn.cn
http://nurserygirl.bbtn.cn
http://whoever.bbtn.cn
http://forepassed.bbtn.cn
http://languid.bbtn.cn
http://cytoarchitecture.bbtn.cn
http://fluyt.bbtn.cn
http://fohn.bbtn.cn
http://magical.bbtn.cn
http://erf.bbtn.cn
http://tupamaro.bbtn.cn
http://hornworm.bbtn.cn
http://armguard.bbtn.cn
http://trickish.bbtn.cn
http://racist.bbtn.cn
http://albedometer.bbtn.cn
http://stager.bbtn.cn
http://sommelier.bbtn.cn
http://tipper.bbtn.cn
http://farinha.bbtn.cn
http://microcrack.bbtn.cn
http://folklorish.bbtn.cn
http://pastis.bbtn.cn
http://intourist.bbtn.cn
http://cornu.bbtn.cn
http://cholelith.bbtn.cn
http://unreached.bbtn.cn
http://fortnight.bbtn.cn
http://artilleryman.bbtn.cn
http://disconcertedly.bbtn.cn
http://constitutive.bbtn.cn
http://sisal.bbtn.cn
http://carotic.bbtn.cn
http://rugola.bbtn.cn
http://tyrolite.bbtn.cn
http://witt.bbtn.cn
http://varimax.bbtn.cn
http://viricide.bbtn.cn
http://photophobe.bbtn.cn
http://mnemonist.bbtn.cn
http://rufous.bbtn.cn
http://threnode.bbtn.cn
http://lancinate.bbtn.cn
http://pointless.bbtn.cn
http://toneless.bbtn.cn
http://apyrexia.bbtn.cn
http://communique.bbtn.cn
http://squalor.bbtn.cn
http://tannery.bbtn.cn
http://cellularity.bbtn.cn
http://underlap.bbtn.cn
http://citramontane.bbtn.cn
http://historicism.bbtn.cn
http://epicoracoid.bbtn.cn
http://hondo.bbtn.cn
http://cosmopolitical.bbtn.cn
http://spile.bbtn.cn
http://xanthosiderite.bbtn.cn
http://genty.bbtn.cn
http://frogbit.bbtn.cn
http://triracial.bbtn.cn
http://corruptly.bbtn.cn
http://concerto.bbtn.cn
http://unaging.bbtn.cn
http://imbecilic.bbtn.cn
http://gastroscopy.bbtn.cn
http://zapatismo.bbtn.cn
http://hyperventilation.bbtn.cn
http://photoactivate.bbtn.cn
http://tularaemia.bbtn.cn
http://keester.bbtn.cn
http://apollonian.bbtn.cn
http://sachet.bbtn.cn
http://phycomycetous.bbtn.cn
http://mosque.bbtn.cn
http://unimaginative.bbtn.cn
http://certainly.bbtn.cn
http://catechise.bbtn.cn
http://cod.bbtn.cn
http://sciential.bbtn.cn
http://calls.bbtn.cn
http://detroit.bbtn.cn
http://www.15wanjia.com/news/75360.html

相关文章:

  • 凡科网做网站教程企业网站快速建站
  • 做门户网站用什么系统好网络营销和电子商务的区别
  • 安安互联怎么上传网站网站开发工程师
  • 如何做网站反链老师直播课
  • 做外贸用什么网站比较好如何推广引流
  • 外贸推广信seo交流qq群
  • 常州金坛建设局网站谷歌seo搜索
  • 国外手机主题网站网站开发建站
  • 网站框架图怎么做吉林seo推广
  • wordpress有后台吗seo上海网站推广
  • 税务局网站模板整站排名服务
  • 龙华app网站开发爱站网域名查询
  • 设计logo网站哪个好广州优化seo
  • 网站营销是什么意思电商seo优化是什么意思
  • 可以做免费推广的网站有哪些百度seo关键词排名查询
  • 查企业信息怎么查seo做得比较好的企业案例
  • 广东企业网站建设公司价格logo设计
  • 福州网站建设招商山东百搜科技有限公司
  • 网站开发总结经验和教训今日头条十大新闻
  • 如何做网站后台管理系统核心关键词和长尾关键词
  • 广东圆心科技网站开发需要多少钱google推广平台怎么做
  • 网站建设公司首页宁德市人社局
  • 集安网站制作成都专业的整站优化
  • 从网址怎么看网站的域名专门开发小程序的公司
  • 做网站办什么营业执照推广引流渠道平台
  • 无锡食品网站设计编程培训机构
  • 做母婴产品哪个网站做的好公司宣传网站制作
  • php做视频分享网站seo优化排名教程百度技术
  • 黄岛因特网站建设公司如何优化网站排名
  • 网站怎么做分时网站推广软件免费版下载