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

模板建站符合哪些工作需求?制作书签的意义

模板建站符合哪些工作需求?,制作书签的意义,都是做面食网站,大沥网站设计148. 排序链表 题目#xff1a;给你链表的头结点 head #xff0c;请将其按升序排列并返回排序后的链表。 题目链接#xff1a; 148. 排序链表 时间复杂度#xff1a;快排 O(n^2) 超出时间限制 class Solution {public ListNode sortList(ListNode head) {if(headnull)…148. 排序链表 题目给你链表的头结点 head 请将其按升序排列并返回排序后的链表。 题目链接 148. 排序链表 时间复杂度快排 O(n^2) 超出时间限制 class Solution {public ListNode sortList(ListNode head) {if(headnull){return head;}ListNode dummynew ListNode(Integer.MIN_VALUE,null);ListNode pointnewdummy;ListNode pointoldhead;while(pointold!null){while(pointnew!nullpointnew.next!null){if(pointold.valpointnew.next.val){ListNode nextpointnew.next;ListNode nodenew ListNode(pointold.val);pointnew.nextnode;node.nextnext;pointnewdummy;break;}else{pointnewpointnew.next;}}if(pointnew.nextnull){ListNode nextpointnew.next;ListNode nodenew ListNode(pointold.val);pointnew.nextnode;node.nextnext;pointnewdummy;}pointoldpointold.next;}return dummy.next;} }归并排序O(logn) class Solution {public ListNode sortList(ListNode head) {if(headnull||head.nextnull){return head;}//找中点截断链表ListNode fast head;ListNode slow head;ListNode prenull;while(fast!nullfast.next!null){preslow;slowslow.next;fastfast.next.next;}//递归截断链表pre.nextnull;ListNode leftsortList(head);ListNode rightsortList(slow);//合并链表ListNode dummynew ListNode(0);ListNode res dummy;while (left ! null right ! null) {if (left.val right.val) {res.next left;left left.next;} else {res.next right;right right.next;}resres.next;}res.nextleft!null?left:right;return dummy.next;} }归并排序迭代方法 时间复杂度O(logn)空间复杂度为O(1) 直接当作n个长度为1的链表进行归并 先归并为2个有序继而48…直到其长度大于链表长度n public ListNode sortList(ListNode head) {if (head null || head.next null) {return head;}// 获取链表长度int length 0;ListNode current head;while (current ! null) {length;current current.next;}ListNode dummy new ListNode(0);dummy.next head;ListNode left, right, tail;// 每次翻倍增加子链表的长度for (int step 1; step length; step * 2) {current dummy.next;tail dummy;while (current ! null) {left current;right split(left, step); // 分割出两个子链表current split(right, step); //划分下一个lefttail merge(left, right, tail); // 合并两个子链表}}return dummy.next;}// 分割链表private ListNode split(ListNode head, int step) {if (head null) return null;for (int i 1; head.next ! null i step; i) {head head.next;}ListNode right head.next;head.next null;return right;}// 合并两个链表private ListNode merge(ListNode l1, ListNode l2, ListNode tail) {ListNode current tail;while (l1 ! null l2 ! null) {if (l1.val l2.val) {current.next l1;l1 l1.next;} else {current.next l2;l2 l2.next;}current current.next;}current.next (l1 ! null) ? l1 : l2;while (current.next ! null) {current current.next;}return current;}
http://www.dnsts.com.cn/news/39548.html

相关文章:

  • jeecg 做网站大数据营销
  • 南宁有多少家网站建设推广的公司关键词免费
  • 太原建站的模板致远oa协同管理系统
  • 做网站架构做网站 以图搜货
  • 网站降权处理公司名词解释
  • 企业注册信息查询网站网站标题符号
  • 高端设计参考网站镇江网站关键字优化机构
  • 建设三库一平台石家庄整站优化
  • 网站商城系统设计网站里的动态是如何制作
  • 毕业设计代做网站企业网站建设包含哪些内容
  • 我是做网站的 哪里有单接四川建设数据共享平台
  • 心理咨询 网站模版做公寓酒店跟网站合作有什么技巧
  • 兰州营销型网站建设安宁网站建设熊掌号
  • seo技术建站学校网站建设会议讲话稿
  • 软件下载网站如何建设电脑上怎么删除wordpress
  • 印刷网站开发的可行性报告今天最新的招聘信息
  • seo搜索优化网站推广排名设计网页布局的常用方法有
  • 清湖做网站的中山门户网站制作在哪里买
  • 杭州利兴建设官方网站Vs做的网站调试时如何适应网页
  • 化工建网站多少费用潍坊优化公司
  • 宣城网站建设jidela2021可以访问黄的浏览器
  • 网站如何做ssl认证深圳市住房和建设局网站下载
  • 自己怎么做网站购买空间哪家编程机构比较好
  • 学校网站建设市场福州微信公众号开发
  • 网站备案 图标wordpress rss 修改
  • 永久免费不收费的软件app谷歌seo 外贸建站
  • 网站收录上万没有流量html网站开发实例教程
  • 绍兴网站建设方案托管廊坊网站建设方案开发
  • 怎么做整人点不完的网站视频php ajax网站开发典型实例 pdf
  • thinkphp怎么做网站企业网站设计软件