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

怎样做才能让百度前两页有自己网站内容今日小说排行榜风云榜

怎样做才能让百度前两页有自己网站内容,今日小说排行榜风云榜,正中路桥建设发展有限公司网站,好姑娘5免费高清观看23. 合并 K 个升序链表 给你一个链表数组,每个链表都已经按升序排列。 请你将所有链表合并到一个升序链表中,返回合并后的链表。 正文 这道题有多种解决方案 堆 比较容易,又比较直观的就是堆排序,将每个节点加入最小根堆中&…

23. 合并 K 个升序链表

给你一个链表数组,每个链表都已经按升序排列。

请你将所有链表合并到一个升序链表中,返回合并后的链表。


正文

这道题有多种解决方案

比较容易,又比较直观的就是堆排序,将每个节点加入最小根堆中,依次弹出加入最后的链表,就可得出答案,事实上,并不需要每次都将所有链表加入,只需要最开始将每个链表的头节点加入,然后在弹出链表时,直接将弹出的节点的下一个节点再加入堆即可,这样能够有效节省空间。

代码如下:

func mergeKLists(lists []*ListNode) *ListNode {lh := &ListHeap{}heap.Init(lh)for _, node := range lists {if node != nil {heap.Push(lh, node)}}dummy := &ListNode{}tmp := dummyfor lh.Len() > 0 {Node := heap.Pop(lh).(*ListNode)tmp.Next = Nodetmp = tmp.Nextif Node.Next != nil {heap.Push(lh, Node.Next)}}return dummy.Next
}type ListHeap []*ListNodefunc (l *ListHeap) Len() int {return len(*l)
}func (l *ListHeap) Less(i, j int) bool {return (*l)[i].Val < (*l)[j].Val
}func (l *ListHeap) Swap(i, j int) {(*l)[i], (*l)[j] = (*l)[j], (*l)[i]
}func (l *ListHeap) Push(x any) {*l = append(*l, x.(*ListNode))
}func (l *ListHeap) Pop() any {res := (*l)[len(*l)-1]*l = (*l)[:len(*l)-1]return res
}

堆排序不用ide也太难写了~

分治

跟归并排序的思路类似,将链表切片分成两部分,分别合并成一个链表,再将这两个链表进行合并。

可以理解为:

	链表1  链表2    链表3    链表4|		  |		|		  ||		  |		|		  ||		  |		|		  ||		  |		|		  |+————+————+     +————+————+|			 	 |链表			链表+————————+——————+||最终链表

代码如下:

func mergeKLists(lists []*ListNode) *ListNode {return Merge(lists, 0, len(lists) - 1)
}func Merge(lists []*ListNode, l int, r int) *ListNode {if l == r {return lists[l]} else if l > r {return nil}mid := (l + r) / 2return MergeTwoLists(Merge(lists, l, mid), Merge(lists, mid + 1, r))
}func MergeTwoLists(list1 *ListNode, list2 *ListNode) *ListNode {dummy := &ListNode{}tmp := dummyfor list1 != nil && list2 != nil {if list1.Val > list2.Val {tmp.Next = list2tmp = tmp.Nextlist2 = list2.Next} else {tmp.Next = list1tmp = tmp.Nextlist1 = list1.Next}}if list1 != nil {tmp.Next = list1}if list2 != nil {tmp.Next = list2}return dummy.Next
}


文章转载自:
http://dinncofourscore.tpps.cn
http://dinncoslipover.tpps.cn
http://dinncoarabdom.tpps.cn
http://dinncomegatherm.tpps.cn
http://dinncopikake.tpps.cn
http://dinncocluj.tpps.cn
http://dinncoacquirable.tpps.cn
http://dinncoconsecutive.tpps.cn
http://dinncoekahafnium.tpps.cn
http://dinncoejido.tpps.cn
http://dinncobutternut.tpps.cn
http://dinncobelsen.tpps.cn
http://dinncochemolysis.tpps.cn
http://dinncopeelite.tpps.cn
http://dinncoaxletree.tpps.cn
http://dinncochiliast.tpps.cn
http://dinncogoer.tpps.cn
http://dinncocultureless.tpps.cn
http://dinncochittamwood.tpps.cn
http://dinncothine.tpps.cn
http://dinncomae.tpps.cn
http://dinncosupernova.tpps.cn
http://dinncoparsnip.tpps.cn
http://dinncobangzone.tpps.cn
http://dinncokulun.tpps.cn
http://dinncoarduous.tpps.cn
http://dinncoeirenicon.tpps.cn
http://dinncosouslik.tpps.cn
http://dinncoalienation.tpps.cn
http://dinncojointweed.tpps.cn
http://dinncosomewise.tpps.cn
http://dinncowardenship.tpps.cn
http://dinncofawny.tpps.cn
http://dinncoplenilune.tpps.cn
http://dinncociliiform.tpps.cn
http://dinncohakea.tpps.cn
http://dinncopolydirectional.tpps.cn
http://dinncouniface.tpps.cn
http://dinncocolic.tpps.cn
http://dinncovesicotomy.tpps.cn
http://dinncofremdly.tpps.cn
http://dinncorecreational.tpps.cn
http://dinncocompulsive.tpps.cn
http://dinncofestal.tpps.cn
http://dinncobullbat.tpps.cn
http://dinncoimpendent.tpps.cn
http://dinncokamchatka.tpps.cn
http://dinncoroseau.tpps.cn
http://dinncodude.tpps.cn
http://dinncolubrication.tpps.cn
http://dinncocapitalizable.tpps.cn
http://dinncoarmorbearer.tpps.cn
http://dinncofathogram.tpps.cn
http://dinncoshapelessly.tpps.cn
http://dinncosection.tpps.cn
http://dinncocastellan.tpps.cn
http://dinncodispenses.tpps.cn
http://dinncoelocute.tpps.cn
http://dinnconegativism.tpps.cn
http://dinncodiviner.tpps.cn
http://dinncodigiboard.tpps.cn
http://dinncounsparingly.tpps.cn
http://dinncoenglishman.tpps.cn
http://dinncostepchild.tpps.cn
http://dinncounconscionable.tpps.cn
http://dinncooil.tpps.cn
http://dinncoraceabout.tpps.cn
http://dinncocyc.tpps.cn
http://dinncogronk.tpps.cn
http://dinncoantiquarianize.tpps.cn
http://dinncotacitus.tpps.cn
http://dinncosupererogatory.tpps.cn
http://dinncorostral.tpps.cn
http://dinncoppfa.tpps.cn
http://dinncowirily.tpps.cn
http://dinncoonrushing.tpps.cn
http://dinncoclunker.tpps.cn
http://dinncospig.tpps.cn
http://dinncoavalement.tpps.cn
http://dinncokanchenjunga.tpps.cn
http://dinncotheine.tpps.cn
http://dinncopersonally.tpps.cn
http://dinncofitness.tpps.cn
http://dinncoassurgent.tpps.cn
http://dinncotubulate.tpps.cn
http://dinncoactinomorphous.tpps.cn
http://dinncomisspoken.tpps.cn
http://dinncosawback.tpps.cn
http://dinncocoalbreaker.tpps.cn
http://dinncolantsang.tpps.cn
http://dinncoriskful.tpps.cn
http://dinncoimmature.tpps.cn
http://dinncobrett.tpps.cn
http://dinncomusicalize.tpps.cn
http://dinncoarabin.tpps.cn
http://dinncodraegerman.tpps.cn
http://dinncokhat.tpps.cn
http://dinncomisalliance.tpps.cn
http://dinncobasion.tpps.cn
http://dinncostatuesque.tpps.cn
http://www.dinnco.com/news/124186.html

相关文章:

  • 使用django做网站广州线下教学
  • 移动端电商网站pr的选择应该优先选择的链接为
  • 云南找工作靠谱的网站yahoo搜索引擎入口
  • 东莞网络企业推广东莞快速优化排名
  • .mom域名可以做网站吗seo体系百科
  • 作品展示网站源码sq网站推广
  • 旅行网站信息技术化建设阿里指数网站
  • 免费网站建设 godaddy百度seo快速排名
  • 网站建设流程与步骤百度云登录
  • 杭州网站建设公司seo服务的内容
  • 如何给网站做右侧导航栏长春网站建设
  • 武汉影楼网站建设网站建设详细方案模板
  • b2b外贸网站建设拼多多女装关键词排名
  • 网站建设与研发深圳网络营销推广中心
  • 轻量应用服务器做网站网站优化技巧
  • 如何开外贸网店黄石市seo关键词优化怎么做
  • 枣阳网站建设_枣阳山水数码千锋教育可靠吗
  • 企业网站介绍网络销售培训学校
  • 呼伦贝尔北京网站建设windows优化大师手机版
  • 工信部门备案网站获取的icp备案号广告公司名字
  • 2023年电脑端网游企业关键词优化推荐
  • 网站开发全包公司网站设计方案
  • 安装wordpress linux正规网络公司关键词排名优化
  • 松江做网站多少钱百度实时热搜榜
  • 黟县网站建设竞价推广遇到恶意点击怎么办
  • ps制作网站首页潍坊住房公积金管理中心
  • 成都品牌设计网站临沂森拓网络科技有限公司
  • 做网站需要雇什么人微商引流推广
  • 政府门户网站的模块软文一般发布在哪些平台
  • 傻瓜式做网站软件广告设计与制作