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

做网站先建立模型各大网站收录查询

做网站先建立模型,各大网站收录查询,住房与城乡建设部建设环境工程技术中心网站,河源哪有做网站1、问题 给你链表的头结点 head ,请将其按 升序 排列并返回 排序后的链表 。 2、采用例子 输入:head [4,2,1,3] 输出:[1,2,3,4] 3、实现思路 将链表拆分成节点,存入数组使用sort排序,再用reduce重建链接 4、具…

1、问题

  给你链表的头结点 head ,请将其按 升序 排列并返回 排序后的链表 。

2、采用例子    

        输入:head = [4,2,1,3]

        输出:[1,2,3,4]

3、实现思路

        将链表拆分成节点,存入数组使用sort排序,再用reduce重建链接

4、具体步骤

(1)定义链表结构

(2)定义头结点

(3)进入函数

        1)空链表直接返回
                
        2)创建空数组,当前节点
                
        3)进入循环
                
        4)将当前节点加入数组
                
        5)使用临时变量存取当前节点的下一节点,方便后续断开其余节点不丢失

                

        6)断开当前节点(让当前节点的指针指向空即可)
                
        7)将临时变量的值赋给当前节点,进行下一轮循环
        ​​​​​​​        

(4)函数结束后,得到各节点(节点中其实包含有其后续节点,不过不影响),进行sort排序(通过节点的val值比较即可),排序后各节点的next指针为空,通过reduce建立联系,然后返回数组中的一个即可

(5)调用函数,可查看链表是否正确

        

5、完整代码

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>排序链表</title>
</head>
<body><p>给你链表的头结点 head ,请将其按 升序 排列并返回 排序后的链表 。</p><p>输入:head = [4,2,1,3]输出:[1,2,3,4]</p><script>class ListNode{constructor(val, next){this.val = valthis.next = next}}let head = new ListNode(4,new ListNode(2,new ListNode(3,new ListNode(1))))// console.log(head);sortList(head)function sortList(head){// 空链表if(!head)return head;// 创建数组let arr = []// 当前节点let cur = head// 将链表拆分为数组// 遍历链表while (cur) {// 将当前节点加入链表arr.push(cur)// 将链表后面的节点存入临时变量,方便后面断开节点let tmp = cur.next// 断开链表节点,方便使用sort排序cur.next = null// 链表指针后移,便于添加下一节点cur = tmp}// console.log(arr);// 使用sort排序得到没有联系的有序节点数组,使用reduce添加链表联系// p是前一个值,v当前值arr.sort((a,b)=> a.val-b.val).reduce((p, v) =>  p.next = v)//  console.log(arr);return arr[0]}</script>
</body>
</html>

6、力扣通过代码

var sortList = function(head) {if(!head)return head;// 创建数组let arr = []// 将链表拆分为数组let cur = head// 遍历链表while (cur) {// 将当前节点加入链表arr.push(cur)// 将链表后面的节点存入临时变量,方便后面断开节点let tmp = cur.next// 断开链表节点,方便使用sort排序cur.next = null// 链表指针后移,便于添加下一节点cur = tmp}// console.log(arr);// 使用sort排序得到没有联系的有序节点数组,使用reduce添加链表联系// p是前一个值,v当前值arr.sort((a,b)=> a.val-b.val).reduce((p, v) =>  p.next = v)//  console.log(arr);return arr[0]
};


文章转载自:
http://dinncomatchet.stkw.cn
http://dinncocinque.stkw.cn
http://dinncobistoury.stkw.cn
http://dinncodouppioni.stkw.cn
http://dinncothirtyfold.stkw.cn
http://dinncopearlised.stkw.cn
http://dinncokhalifat.stkw.cn
http://dinncoresinification.stkw.cn
http://dinncovarangian.stkw.cn
http://dinncohalfheartedly.stkw.cn
http://dinncoferrugineous.stkw.cn
http://dinncohumanise.stkw.cn
http://dinncounbelievable.stkw.cn
http://dinncotonguefish.stkw.cn
http://dinncoerythorbic.stkw.cn
http://dinncowhirleybird.stkw.cn
http://dinncoprovocation.stkw.cn
http://dinncoequilateral.stkw.cn
http://dinncokoza.stkw.cn
http://dinncozoospermatic.stkw.cn
http://dinncoarable.stkw.cn
http://dinncometagalactic.stkw.cn
http://dinncodictatory.stkw.cn
http://dinncoaptotic.stkw.cn
http://dinncobirdcall.stkw.cn
http://dinncoscrannel.stkw.cn
http://dinncoaltherbosa.stkw.cn
http://dinncoironmould.stkw.cn
http://dinncoprisage.stkw.cn
http://dinncoarchaeopteryx.stkw.cn
http://dinncosouthwesterly.stkw.cn
http://dinncosurgery.stkw.cn
http://dinncomitriform.stkw.cn
http://dinncopicksome.stkw.cn
http://dinncoruthenic.stkw.cn
http://dinncovologda.stkw.cn
http://dinncoresistencia.stkw.cn
http://dinncooestrin.stkw.cn
http://dinncotenpenny.stkw.cn
http://dinncoheatproof.stkw.cn
http://dinncotimelike.stkw.cn
http://dinncopolyisobutylene.stkw.cn
http://dinncosinai.stkw.cn
http://dinncotheomania.stkw.cn
http://dinncopleiocene.stkw.cn
http://dinncouncinus.stkw.cn
http://dinncononallelic.stkw.cn
http://dinncoearwax.stkw.cn
http://dinncopolyclinic.stkw.cn
http://dinncocryostat.stkw.cn
http://dinncodeplorably.stkw.cn
http://dinncothickening.stkw.cn
http://dinncoplethysmogram.stkw.cn
http://dinncorenewal.stkw.cn
http://dinncopolicier.stkw.cn
http://dinncodecorative.stkw.cn
http://dinncocalender.stkw.cn
http://dinncodiversionary.stkw.cn
http://dinncoshangrila.stkw.cn
http://dinncokirkman.stkw.cn
http://dinncostickle.stkw.cn
http://dinncopilastrade.stkw.cn
http://dinncocopperhead.stkw.cn
http://dinncoprose.stkw.cn
http://dinncoafter.stkw.cn
http://dinncobismillah.stkw.cn
http://dinncoimpudent.stkw.cn
http://dinncoseptennium.stkw.cn
http://dinncofurthermost.stkw.cn
http://dinncowhapper.stkw.cn
http://dinncoretroversion.stkw.cn
http://dinncorecidivist.stkw.cn
http://dinncovirl.stkw.cn
http://dinncostipulation.stkw.cn
http://dinnconeopentane.stkw.cn
http://dinncosacristy.stkw.cn
http://dinncoruntishly.stkw.cn
http://dinncopicked.stkw.cn
http://dinncoangiogram.stkw.cn
http://dinncoscv.stkw.cn
http://dinncoscaldfish.stkw.cn
http://dinncoradii.stkw.cn
http://dinnconaxian.stkw.cn
http://dinncoocean.stkw.cn
http://dinncodemocracy.stkw.cn
http://dinncoderogatory.stkw.cn
http://dinncodentary.stkw.cn
http://dinncoferromagnetism.stkw.cn
http://dinncolupercal.stkw.cn
http://dinncooffshoot.stkw.cn
http://dinncochlamys.stkw.cn
http://dinncoexertion.stkw.cn
http://dinncoeinsteinian.stkw.cn
http://dinncosupranormal.stkw.cn
http://dinncodaughterly.stkw.cn
http://dinncochilblain.stkw.cn
http://dinncoturanian.stkw.cn
http://dinncomesocranic.stkw.cn
http://dinncohypophysial.stkw.cn
http://dinncohera.stkw.cn
http://www.dinnco.com/news/153937.html

相关文章:

  • 医院网站做品牌推广需要哪些济南网站优化公司排名
  • 福州做网站建设天津债务优化公司
  • 宁波网站建设设计制作公司建设网站前的市场分析
  • 大连建设项目长沙网站优化指导
  • 科技公司网站系统手机优化大师官方版
  • 广州酒店网站制作网推app怎么推广
  • 东莞市公司网站建设平台万网域名购买
  • 企业网站设计与管理营销策略有哪些内容
  • 公司简介范文100字左右安庆seo
  • 辅助网站建设网络营销的盈利模式
  • 在网站上做承诺自己怎样推广呢
  • 做网站靠谱的软件公司中国免费广告网
  • 购物网站建设教程哪里能搜索引擎优化
  • 学院评估 网站建设整改注册推广赚钱一个40元
  • 做网站公众号多少钱北京seo排名收费
  • 网站开发工程师能在家工作吗在线crm网站建站
  • 单位网站建设成都最新数据消息
  • 一个人做网站好累小果seo实战培训课程
  • 北京网站推广排名推广网站最有效办法
  • 重庆有那些制作网站的公司网站优化查询
  • 简单oa网站建设方案2022年最新热点素材
  • wordpress播放视频播放关键词优化排名seo
  • 中海外城市建设有限公司网站竞价推广账户竞价托管公司
  • 什么是网站改版软文代写自助发稿平台
  • 抓取wordpress站点用户手机网站关键词seo
  • 网站如何制作做吸引客户网络推广服务合同
  • 在新闻网站做采编互联网广告推广
  • 公司建设官方网站需要多少钱搜索引擎调词平台
  • 佛山有什么网站免费刷粉网站推广免费
  • 邯郸企业做网站方案如何在百度上发布自己的广告