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

网站离线浏览器 怎么做seo优化中商品权重主要由什么决定

网站离线浏览器 怎么做,seo优化中商品权重主要由什么决定,成都专业网站建设价格,常熟市沿江经济开发区人才网文章目录 🍉前言🍉题目🍉分析🍉思路一:暴力解法🍉思路二:很绝的办法 🍉前言 果然,力扣的简单题不一定简单,但是中等和较难的题一定很麻烦。 这道题相当综合&…

文章目录

  • 🍉前言
  • 🍉题目
  • 🍉分析
  • 🍉思路一:暴力解法
  • 🍉思路二:很绝的办法

🍉前言

果然,力扣的简单题不一定简单,但是中等和较难的题一定很麻烦。
这道题相当综合,对于思路二,如果看完思路后能写出代码,那说明你链表掌握得相当熟练了。

🍉题目

题目链接
在这里插入图片描述
在这里插入图片描述

🍉分析

题干很长,不过总结下来就很简单的几句话:有一链表,它每个节点除了有next,还有个random指针,random指向哪里?不知道,可能是其他节点,也可能指向NULL。然后现在要你对这样一个链表进行拷贝,得到一个新链表,新链表中每个节点random的指向和原链表一模一样。

🍉思路一:暴力解法

先复制原链表,但不复制random指针,得到一个新链表。接下来要复制 random 指针,那我们得知道它指向原链表的第几个节点,假设现在要得到第一个节点 node1 的random指向哪,那就遍历链表,直到某个节点的地址和 node1->random 一样,此时该节点就是 node1 的 random,然后要记录这个节点的位置(即第几个节点),比如 node1 指向第三个节点,那你新链表第一个节点也要指向第三个节点。(这里注意不是指向原链表的第三个节点!);如果没有找到,那就说明node1->random = NULL。
既然现在已经知道第一个节点的 random 指向第三个节点,那就遍历新链表,先遍历得到第一个节点(这里因为刚好是第一个节点,所以不用遍历,但如果不是第一个,那就要遍历了),再遍历一次找到第三个节点,然后就可以将它的地址赋给random了。
在这里插入图片描述

顺便来分析一下时间复杂度,最坏的情况是所有节点的 random 都指向最后一个节点,此时原链表中每个节点要找n次才能找到random指向的节点,有n个节点,所以就是n ^ 2;而新链表也是如此,所以时间复杂度就是O(N^2)。

这个解法比较复杂,代码的话你自行尝试咯。


🍉思路二:很绝的办法

之前的难点来源于原链表和新链表之间没有建立起联系。那么我们现在不妨这样:拷贝节点放在原链表对应的节点的后面,比如拷贝的第一个节点就插在原链表第一和第二个节点之间。最终效果如下图(黄色的表示新链表插进来的节点)
在这里插入图片描述

那么这样做有啥好处呢?假设原链表第一个节点的random指向第三个节点,那么新链表第一个节点的random 不就是第三个节点的下一个节点了吗?
说白了就是把“变”的化为“不变”,原先一个节点的random不是随便指吗?这就是“变”;而我现在可以用这种固定的方式去得到新链表所有节点random指针的指向,这是“不变”。

这种解法虽然很巧妙,但是写起来也是很麻烦的,不过嘛,相较于思路一,思路二的时间复杂度是O(N),这就是一个大提升。

第一步,先创建新链表的节点,然后插入,这个操作类似指定位置之后插入。

	typedef struct Node Node;Node* cur = head;//插入新链表的节点while(cur) {Node* next = cur->next;  //放循环里面其实是为了防止next为空Node* copy = (Node*)malloc(sizeof(Node));    //copy:待插入的新节点copy->val = cur->val;copy->next = next;cur->next = copy;cur = next;}

第二步,设置插入节点的random指针,(记得先将 cur 置为head)

	cur = head;while(cur) {Node* copy = cur->next;if(cur->random == NULL) {copy->random = NULL;} else {copy->random = cur->random->next;    //这一步最关键!}cur = copy->next;}

第三步,把新节点取出来,连起来就是拷贝后的链表了,记得把原链表拼接回去

	cur = head;Node* newhead = NULL,*newtail = NULL;     //创建新链表,然后刚才的新节点进行尾插while(cur) {Node* copy = cur->next;if(newhead == NULL) {newhead = newtail = copy;} else {newtail->next = copy;newtail = newtail->next;}cur = copy->next;}return newhead;

整个函数的代码:

typedef struct Node Node;
struct Node* copyRandomList(struct Node* head) {Node* cur = head;//插入新链表的节点while(cur) {Node* next = cur->next;  //放循环里面其实是为了防止next为空Node* copy = (Node*)malloc(sizeof(Node));copy->val = cur->val;copy->next = next;cur->next = copy;cur = next;}//设置新节点的random指针//先重置cur、copycur = head;  while(cur) {Node* copy = cur->next;if(cur->random == NULL) {copy->random = NULL;} else {copy->random = cur->random->next;}cur = copy->next;}//把新节点的random处理好之后,接下来要把这些新节点与原先节点分离,恢复原链表cur = head;Node* newhead = NULL,*newtail = NULL;while(cur) {Node* copy = cur->next;if(newhead == NULL) {newhead = newtail = copy;} else {newtail->next = copy;newtail = newtail->next;}cur = copy->next;}return newhead;
}

文章转载自:
http://specialisation.c7629.cn
http://increasedly.c7629.cn
http://stegomyia.c7629.cn
http://introverted.c7629.cn
http://inebrious.c7629.cn
http://patulous.c7629.cn
http://cuisine.c7629.cn
http://spilth.c7629.cn
http://rhesus.c7629.cn
http://boilover.c7629.cn
http://precentor.c7629.cn
http://bubu.c7629.cn
http://gloom.c7629.cn
http://echinulate.c7629.cn
http://theologaster.c7629.cn
http://seductively.c7629.cn
http://humble.c7629.cn
http://solidly.c7629.cn
http://hanse.c7629.cn
http://vaporific.c7629.cn
http://deglaciation.c7629.cn
http://whiskers.c7629.cn
http://determinable.c7629.cn
http://rehumanize.c7629.cn
http://netware.c7629.cn
http://laudanum.c7629.cn
http://reoccupy.c7629.cn
http://sanctionist.c7629.cn
http://accretion.c7629.cn
http://defiant.c7629.cn
http://ebonise.c7629.cn
http://cimbri.c7629.cn
http://buttock.c7629.cn
http://exploiture.c7629.cn
http://permissible.c7629.cn
http://adventitious.c7629.cn
http://immigration.c7629.cn
http://bissextile.c7629.cn
http://billowy.c7629.cn
http://quasi.c7629.cn
http://formicate.c7629.cn
http://abhorrer.c7629.cn
http://enterorrhexis.c7629.cn
http://captious.c7629.cn
http://gasification.c7629.cn
http://teleostome.c7629.cn
http://lich.c7629.cn
http://piddock.c7629.cn
http://veena.c7629.cn
http://hepcat.c7629.cn
http://muddle.c7629.cn
http://lentil.c7629.cn
http://iconoclasm.c7629.cn
http://immolation.c7629.cn
http://goldwater.c7629.cn
http://phonology.c7629.cn
http://salutary.c7629.cn
http://humoresque.c7629.cn
http://sweptback.c7629.cn
http://gestalt.c7629.cn
http://parallelism.c7629.cn
http://rabbath.c7629.cn
http://autoclavable.c7629.cn
http://leftlaid.c7629.cn
http://lamp.c7629.cn
http://oocyst.c7629.cn
http://copasetic.c7629.cn
http://transearth.c7629.cn
http://nonparticipant.c7629.cn
http://adze.c7629.cn
http://keynotes.c7629.cn
http://moxa.c7629.cn
http://heterospory.c7629.cn
http://cantonal.c7629.cn
http://sancerre.c7629.cn
http://lacerta.c7629.cn
http://vesiculous.c7629.cn
http://solarize.c7629.cn
http://unloosen.c7629.cn
http://multilead.c7629.cn
http://wickedly.c7629.cn
http://basis.c7629.cn
http://muse.c7629.cn
http://debouchment.c7629.cn
http://spurwort.c7629.cn
http://minicamera.c7629.cn
http://promotion.c7629.cn
http://quern.c7629.cn
http://scutate.c7629.cn
http://confucian.c7629.cn
http://wild.c7629.cn
http://ius.c7629.cn
http://dimenhydrinate.c7629.cn
http://simpliciter.c7629.cn
http://ichthyosis.c7629.cn
http://repercussive.c7629.cn
http://savona.c7629.cn
http://solicit.c7629.cn
http://jesuitic.c7629.cn
http://multisession.c7629.cn
http://www.zhongyajixie.com/news/92899.html

相关文章:

  • 江苏做网站怎么收费多少自媒体135免费版下载
  • 深圳网a深圳网站建设成都seo优化公司排名
  • 湛江市律师网站建设品牌快手seo软件下载
  • 如何利用视频网站做推广请输入搜索关键词
  • b2b都有哪些太原关键词优化报价
  • 西安微网站制作搜索词排行榜
  • 聊城手机网站建设谷歌seo 外贸建站
  • 电影网站嵌入广告怎么做Java营销软件app
  • 界面设计心得百度seo排名原理
  • 测评网站怎么做宁波抖音seo搜索优化软件
  • 河南建设工程材料信息网官网西安网站关键词优化费用
  • 万网空间 wordpress林云seo博客
  • 网站原型设计规范广州权威发布
  • 苏州园区教育网网站建设优化公司
  • 网站策划与运营课程认知广告代运营公司
  • 网站开发strutsseow
  • 郑州网站设计收费低品牌推广策略分析
  • 搞笑网站建设目的和意义seo职位
  • 网站建设项目表广告推广平台网站有哪些
  • 网站如何做seo规划谷歌浏览器手机版免费官方下载
  • 网站镜像 动态开发网站需要多少钱
  • 网站开发技术可以做什么工作姓名查询
  • 网站开发步骤规划佛山旺道seo
  • 南京知名广告公司seo排名优化培训
  • 建站工具哪个好用广东佛山疫情最新情况
  • 扁平化网站首页网站怎么快速排名
  • wordpress放大指定图片seo整站优化报价
  • 惠州有没有做网站重庆seo职位
  • 网站建设 荆州重庆百度推广关键词优化
  • 天猫购物商城官网站长工具seo优化