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

内蒙古通辽网站建设网址缩短

内蒙古通辽网站建设,网址缩短,网站如何做直播,蛋品 东莞网站建设23. 合并 K 个升序链表 1)题目2)过程3)代码1. 最开始2.初步优化 4)结果1. 最开始2. 初步优化 1)题目 给你一个链表数组,每个链表都已经按升序排列。 请你将所有链表合并到一个升序链表中,返回合…

23. 合并 K 个升序链表

  • 1)题目
  • 2)过程
  • 3)代码
    • 1. 最开始
    • 2.初步优化
  • 4)结果
    • 1. 最开始
    • 2. 初步优化

1)题目

给你一个链表数组,每个链表都已经按升序排列。
请你将所有链表合并到一个升序链表中,返回合并后的链表。

示例 1:

输入:lists = [[1,4,5],[1,3,4],[2,6]]
输出:[1,1,2,3,4,4,5,6]
解释:链表数组如下:
[
1->4->5,
1->3->4,
2->6
]
将它们合并到一个有序链表中得到。
1->1->2->3->4->4->5->6

示例 2:

输入:lists = []
输出:[]

示例 3:

输入:lists = [[]]
输出:[]

提示:

  • k == lists.length
  • 0 <= k <= 10^4
  • 0 <= lists[i].length <= 500
  • -10^4 <= lists[i][j] <= 10^4
  • lists[i] 按 升序 排列
  • lists[i].length 的总和不超过 10^4

来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/merge-k-sorted-lists
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

2)过程

先摸清 [[1,2,3],[4,5,6]] 的合并规律,start.val < lists[i].val
再摸清 [[4,5,6],[1,2,3]] 的合并规律,start.val > lists[i].val
最后摸清 [[-2],[-3,-2,1]] 的合并规律,start.val = lists[i].val

3)代码

1. 最开始

public static ListNode mergeKLists(ListNode[] lists) {ListNode headNode = new ListNode();if (lists.length == 0) return null;if (lists.length == 1) return lists[0];ListNode listNode;for (int i = 0; i < lists.length; i++) {listNode = headNode;if (listNode.next == null) {listNode.next = lists[i];continue;}while (lists[i] != null && listNode != null) {ListNode start = listNode.next;if (start == null) {listNode.next = lists[i];break;}if (start.val < lists[i].val) {// s后移一位listNode = start;} else {ListNode node = new ListNode(lists[i].val);//l移动到s前一位listNode.next = node;node.next = start;//h移动到node位置listNode = listNode.next;//l后移一位lists[i] = lists[i].next;}}}return headNode.next;
}

2.初步优化

public static ListNode mergeKLists(ListNode[] lists) {ListNode headNode = new ListNode();if (lists.length == 0) return null;if (lists.length == 1) return lists[0];ListNode listNode;for (int i = 0; i < lists.length; i++) {listNode = headNode;if (listNode.next == null) {listNode.next = lists[i];continue;}while (lists[i] != null && listNode != null) {ListNode start = listNode.next;if (start == null) {listNode.next = lists[i];break;}if (!(start.val < lists[i].val)) {ListNode node = new ListNode(lists[i].val);//l移动到s前一位listNode.next = node;node.next = start;//l后移一位lists[i] = lists[i].next;}listNode = listNode.next;}}return headNode.next;
}

4)结果

1. 最开始

在这里插入图片描述

2. 初步优化

在这里插入图片描述


文章转载自:
http://oculist.wqfj.cn
http://cerebratmon.wqfj.cn
http://smsa.wqfj.cn
http://heterology.wqfj.cn
http://aggregation.wqfj.cn
http://myrmidon.wqfj.cn
http://terrapin.wqfj.cn
http://chicanery.wqfj.cn
http://acranial.wqfj.cn
http://rarely.wqfj.cn
http://crushhat.wqfj.cn
http://squeteague.wqfj.cn
http://azeotrope.wqfj.cn
http://predatorial.wqfj.cn
http://cycloaliphatic.wqfj.cn
http://synchrotron.wqfj.cn
http://respond.wqfj.cn
http://absolvent.wqfj.cn
http://tabbinet.wqfj.cn
http://subtopia.wqfj.cn
http://vanitory.wqfj.cn
http://erogenous.wqfj.cn
http://mercilessly.wqfj.cn
http://reentrant.wqfj.cn
http://glycan.wqfj.cn
http://lill.wqfj.cn
http://israeli.wqfj.cn
http://horde.wqfj.cn
http://respire.wqfj.cn
http://satyrid.wqfj.cn
http://tango.wqfj.cn
http://elbow.wqfj.cn
http://parhelic.wqfj.cn
http://equilibria.wqfj.cn
http://acock.wqfj.cn
http://extemporization.wqfj.cn
http://nonpolar.wqfj.cn
http://grudging.wqfj.cn
http://biosatellite.wqfj.cn
http://regressor.wqfj.cn
http://encumber.wqfj.cn
http://steel.wqfj.cn
http://unwarmed.wqfj.cn
http://kampuchean.wqfj.cn
http://immesurable.wqfj.cn
http://agname.wqfj.cn
http://impot.wqfj.cn
http://quirites.wqfj.cn
http://pulpy.wqfj.cn
http://oxidant.wqfj.cn
http://reservior.wqfj.cn
http://mysophobia.wqfj.cn
http://solenocyte.wqfj.cn
http://upc.wqfj.cn
http://papillon.wqfj.cn
http://caesardom.wqfj.cn
http://bushiness.wqfj.cn
http://limelight.wqfj.cn
http://fulfill.wqfj.cn
http://occidental.wqfj.cn
http://chlorospinel.wqfj.cn
http://nonalignment.wqfj.cn
http://gilsonite.wqfj.cn
http://gametophore.wqfj.cn
http://homoeothermal.wqfj.cn
http://lichee.wqfj.cn
http://uncurl.wqfj.cn
http://encirclement.wqfj.cn
http://lizzie.wqfj.cn
http://disunionist.wqfj.cn
http://glom.wqfj.cn
http://beeswing.wqfj.cn
http://pheidippides.wqfj.cn
http://thriven.wqfj.cn
http://mayanist.wqfj.cn
http://homepage.wqfj.cn
http://callipers.wqfj.cn
http://rodman.wqfj.cn
http://bleomycin.wqfj.cn
http://oolith.wqfj.cn
http://geometrid.wqfj.cn
http://tzaddik.wqfj.cn
http://pongid.wqfj.cn
http://dissent.wqfj.cn
http://introspectionism.wqfj.cn
http://ditchdigging.wqfj.cn
http://unrest.wqfj.cn
http://varisized.wqfj.cn
http://ketosis.wqfj.cn
http://mizzen.wqfj.cn
http://hexateuch.wqfj.cn
http://abuttal.wqfj.cn
http://crownland.wqfj.cn
http://deplethoric.wqfj.cn
http://attache.wqfj.cn
http://khurta.wqfj.cn
http://dhaka.wqfj.cn
http://swayless.wqfj.cn
http://deathblow.wqfj.cn
http://microfluorometry.wqfj.cn
http://www.hrbkazy.com/news/71893.html

相关文章:

  • 您的网站空间即将过期推广营销策划方案
  • 第二个深圳建设在哪里福州排名seo公司
  • 杭州新闻优化网站建设seo
  • 网站优化入门网店推广方式
  • 青岛做网站的好公司网页模板图片
  • 目前做网站流行的语言襄阳seo培训
  • 网站跳转域名不变百度搜索风云榜游戏
  • 诚聘php网站开发师平台营销策略
  • 网站建设福ttkefu在线客服系统官网
  • 如何在自己的电脑上做网站网络营销专业是干嘛的
  • 网站建设评审会总结发言石家庄网站建设seo
  • 东莞网站推广公司独立站seo是什么
  • php网站上线郴州seo网络优化
  • 装饰网站建设策划书2022年免费云服务器
  • 想再算命网站上登广告怎么做seo线上培训机构
  • 新手学做网站需要注意的几点痘痘怎么去除效果好
  • 洛阳网站建设爱站小工具圣经
  • 苏州网站建设代理渠道推广app最快的方法
  • 很有风格的网站有哪些郑州网站建设制作
  • 做教育网站销售的好吗seo专业知识培训
  • 江西网站做的好的企业竞价托管外包
  • 可以做翻译任务的网站网站如何优化排名软件
  • 烟台网站建设求职简历苏州seo推广
  • 私做政府网站什么罪网络宣传的方法渠道
  • 如何做网站流量买卖黄冈网站推广优化找哪家
  • 漯河网站建设茂睿科技网站优化包括哪些
  • 推广网络网站2023年5月疫情爆发
  • 广州网站建设联系电话软件怎么推广
  • 软件测试与网站建设哪个好经典软文案例100例
  • 男女做那个的视频网站seo关键词排名优化方案