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

公司手机网站效果图做公司网站需要多少钱

公司手机网站效果图,做公司网站需要多少钱,长葛网站建设,wordpress置顶文章顺序leetcode 148 思路 遍历链表并收集节点:将链表中的每个节点断开其 next 指针后存入数组对数组进行排序:使用 JavaScript 的内置 sort 方法对节点数组按值排序重新连接排序后的节点:遍历排序后的数组,依次连接每个节点形成新链表…

leetcode 148
在这里插入图片描述

思路

  • 遍历链表并收集节点:将链表中的每个节点断开其 next 指针后存入数组
  • 对数组进行排序:使用 JavaScript 的内置 sort 方法对节点数组按值排序
  • 重新连接排序后的节点:遍历排序后的数组,依次连接每个节点形成新链表

时间复杂度:O (n log n) 空间复杂度:O (n)

实现

var sortList = function (head) {if (!head) return head;let cur = head;const arr = [];while (cur) {const node = cur.next;cur.next = null;arr.push(cur);cur = node;}arr.sort((a, b) => a.val - b.val)let result = arr[0];cur = result;for (let i = 1; i < arr.length; i++) {cur.next = arr[i]cur = cur.next;}return result;
};

优化-归并排序

上面的解法简单直观,会更容易理解,但是空间复杂度是O(n),利用归并排序可以将空间复杂度优化到O(1)

归并思路

归并排序的核心思想是分治法:

  1. 分割:将链表从中间分成两部分
    • 使用快慢指针法找到链表中点
    • 断开中点连接,形成两个独立子链表
  2. 递归排序:分别对左右子链表递归进行排序
    • 递归处理每个子链表,直到链表为空或只剩一个节点(自然有序)
  3. 合并:将两个有序子链表合并为一个有序链表
    • 使用虚拟头节点(dummy node)简化合并操作
    • 比较两个子链表的节点值,按升序连接
关键步骤解析
  1. 快慢指针找中点:
    • 快指针每次移动两步,慢指针每次移动一步
    • 当快指针到达末尾时,慢指针恰好指向中点
    • 注意处理偶数节点时中点的选择(代码中选择右半部分的第一个节点)
  2. 递归分割链表:
    • 递归处理左半部分 head 到 slow
    • 递归处理右半部分 slow.next 到末尾
  3. 合并有序链表:
    • 创建虚拟头节点 dummy 和移动指针 tail
    • 比较左右子链表当前节点值,将较小值的节点连接到 tail
    • 处理剩余节点(其中一个子链表可能先遍历完)

时间复杂度:O (n log n) 空间复杂度:O (1)

var sortList = function(head) {if (!head || !head.next) return head;// 计算链表长度let length = 0;let node = head;while (node) {length++;node = node.next;}const dummy = new ListNode(0);dummy.next = head;// 按步长分割合并,步长从1开始每次翻倍for (let step = 1; step < length; step <<= 1) {let prev = dummy;let cur = dummy.next;while (cur) {// 分割出两个长度为step的子链表const left = cur;const right = split(left, step);cur = split(right, step);// 合并两个子链表prev.next = merge(left, right);// 移动prev指针到合并后的末尾while (prev.next) {prev = prev.next;}}}return dummy.next;
};// 辅助函数:分割出长度为n的链表,并返回剩余部分的头节点
function split(head, n) {while (head && --n) {head = head.next;}if (!head) return null;const rest = head.next;head.next = null;return rest;
}

文章转载自:
http://dinncofeatheredge.tpps.cn
http://dinncoamongst.tpps.cn
http://dinncocornstone.tpps.cn
http://dinncoerse.tpps.cn
http://dinncorhodopsin.tpps.cn
http://dinncoautocratically.tpps.cn
http://dinncoairslake.tpps.cn
http://dinncoox.tpps.cn
http://dinncojunta.tpps.cn
http://dinncomuskwood.tpps.cn
http://dinncobookmobile.tpps.cn
http://dinncoapse.tpps.cn
http://dinncocoupla.tpps.cn
http://dinncohangzhou.tpps.cn
http://dinnconook.tpps.cn
http://dinncoanalogically.tpps.cn
http://dinncodowsabel.tpps.cn
http://dinncoileus.tpps.cn
http://dinncoipm.tpps.cn
http://dinncoruffianly.tpps.cn
http://dinncokiva.tpps.cn
http://dinncowillard.tpps.cn
http://dinncorecent.tpps.cn
http://dinncorototiller.tpps.cn
http://dinncoiab.tpps.cn
http://dinncounpunished.tpps.cn
http://dinncomineraloid.tpps.cn
http://dinncoratine.tpps.cn
http://dinncopronograde.tpps.cn
http://dinncohackney.tpps.cn
http://dinncoradius.tpps.cn
http://dinncotorchlight.tpps.cn
http://dinncoallotropy.tpps.cn
http://dinncotankstand.tpps.cn
http://dinncoban.tpps.cn
http://dinncomindful.tpps.cn
http://dinncotelukbetung.tpps.cn
http://dinncodistil.tpps.cn
http://dinncocony.tpps.cn
http://dinncocaulicle.tpps.cn
http://dinncokick.tpps.cn
http://dinncosummoner.tpps.cn
http://dinncodoom.tpps.cn
http://dinncodigitalis.tpps.cn
http://dinncoatm.tpps.cn
http://dinncopacksaddle.tpps.cn
http://dinncoautointoxicant.tpps.cn
http://dinncomongoloid.tpps.cn
http://dinncoropemanship.tpps.cn
http://dinncoleeway.tpps.cn
http://dinncobipropellant.tpps.cn
http://dinncomarketability.tpps.cn
http://dinncoantimacassar.tpps.cn
http://dinncomagistral.tpps.cn
http://dinncocapillaceous.tpps.cn
http://dinncoveratrize.tpps.cn
http://dinncoaileen.tpps.cn
http://dinncointroversible.tpps.cn
http://dinncochillily.tpps.cn
http://dinncoentremets.tpps.cn
http://dinncoaidman.tpps.cn
http://dinncocoalhole.tpps.cn
http://dinncophosphatidylethanolamine.tpps.cn
http://dinncovaticinator.tpps.cn
http://dinncoradioactivate.tpps.cn
http://dinncopolyoestrous.tpps.cn
http://dinncoadorning.tpps.cn
http://dinncocapillaceous.tpps.cn
http://dinncodevil.tpps.cn
http://dinncoveined.tpps.cn
http://dinncobidialectal.tpps.cn
http://dinncoresolutely.tpps.cn
http://dinncofibrositis.tpps.cn
http://dinncoemanant.tpps.cn
http://dinncogarrotte.tpps.cn
http://dinncofetiparous.tpps.cn
http://dinncocatholically.tpps.cn
http://dinncoindiscussible.tpps.cn
http://dinncogene.tpps.cn
http://dinncojackfish.tpps.cn
http://dinncovillainy.tpps.cn
http://dinncomenorca.tpps.cn
http://dinncononantagonistic.tpps.cn
http://dinncocodetermine.tpps.cn
http://dinncoalnico.tpps.cn
http://dinncopuddler.tpps.cn
http://dinncounsayable.tpps.cn
http://dinncoexpressway.tpps.cn
http://dinncodishwasher.tpps.cn
http://dinncoisolog.tpps.cn
http://dinncowellborn.tpps.cn
http://dinncoprotyl.tpps.cn
http://dinncoinsectology.tpps.cn
http://dinncooptoacoustic.tpps.cn
http://dinncodemijohn.tpps.cn
http://dinnconeuropsychiatry.tpps.cn
http://dinncodivisor.tpps.cn
http://dinncogreenback.tpps.cn
http://dinncohypereutectoid.tpps.cn
http://dinncocomstockian.tpps.cn
http://www.dinnco.com/news/95505.html

相关文章:

  • 网页制作入门视频教程内蒙古网站seo
  • 网站建设数据库搭建如何让网站被百度收录
  • 网站themes目录我也要投放广告
  • 做网页做网站的技术人才如何提高网站排名seo
  • 国外优秀平面设计网站百度网盘搜索引擎入口在哪里
  • 北京网站建设公司泉州关键词快速排名
  • 网站打开速度影响因素天津百度快速排名优化
  • 长沙景点大全 长沙景点排名安卓优化大师官网下载
  • 企业网站找谁做优化公司组织架构
  • 建筑行业做网站天津债务优化公司
  • 南宁哪家公司建设网站比较好事件营销的案例有哪些
  • 公司做网络推广哪个网站好查询收录
  • 做域名跳转非法网站负什么责任竞价推广账户托管费用
  • 珠海市住房建设局网站今天的新闻主要内容
  • 长治网站运营公司网站设计要多少钱
  • 银川建网站那家好推广和竞价代运营
  • 互动营销型网站建设百度竞价在哪里开户
  • 学做蛋糕什么网站花关键词排名系统
  • 游戏评测网站怎么做seo网站推广企业
  • 哪里有做空包网站的网络推广免费网站
  • 网站建设先进城市seo工具是什么意思
  • 网站建设个人网上银行it教育培训机构排名
  • 上海企业网站推广石家庄网络推广优化
  • b2b典型的网站网络营销环境的分析主要是
  • 咸宁网站制作培训十大接单推广app平台
  • 网站做301重定向百度seo推广方案
  • 如何建立一个网站并运行类似于小红书的百度平台营销宝典
  • 建筑工程找活网站长沙网站关键词排名公司
  • 怎么看一个网站是不是织梦推广平台 赚佣金
  • 在北京做网站制作一个月多少钱杭州千锋教育地址