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

黔东南网站开发gzklyy微信指数

黔东南网站开发gzklyy,微信指数,阿里云网站的网页怎么做,衢州网站建设出售文章目录 一、题目描述示例 1示例 2示例 3 二、代码三、解题思路 一、题目描述 现在你总共有 numCourses 门课需要选,记为 0 到 numCourses - 1。给你一个数组 prerequisites ,其中 prerequisites[i] [ai, bi] ,表示在选修课程 ai 前 必须 …

文章目录

  • 一、题目描述
      • 示例 1
      • 示例 2
      • 示例 3
  • 二、代码
  • 三、解题思路


一、题目描述

现在你总共有 numCourses 门课需要选,记为 0numCourses - 1。给你一个数组 prerequisites ,其中 prerequisites[i] = [ai, bi] ,表示在选修课程 ai 前 必须 先选修 bi

例如,想要学习课程 0 ,你需要先完成课程 1 ,我们用一个匹配来表示:[0,1] 。

返回你为了学完所有课程所安排的学习顺序。可能会有多个正确的顺序,你只要返回 任意一种 就可以了。如果不可能完成所有课程,返回 一个空数组

示例 1

输入:numCourses = 2, prerequisites = [[1,0]]
输出:[0,1]
解释:总共有 2 门课程。要学习课程 1,你需要先完成课程 0。因此,正确的课程顺序为 [0,1] 。

示例 2

输入:numCourses = 4, prerequisites = [[1,0],[2,0],[3,1],[3,2]]
输出:[0,2,1,3]
解释:总共有 4 门课程。要学习课程 3,你应该先完成课程 1 和课程 2。并且课程 1 和课程 2 都应该排在课程 0 之后。
因此,一个正确的课程顺序是 [0,1,2,3] 。另一个正确的排序是 [0,2,1,3] 。

示例 3

输入:numCourses = 1, prerequisites = []
输出:[0]

提示:
1 <= numCourses <= 2000
0 <= prerequisites.length <= numCourses * (numCourses - 1)
prerequisites[i].length == 2
0 <= ai, bi < numCourses
ai != bi
所有[ai, bi] 互不相同

二、代码

代码如下:

class Solution:def findOrder(self, numCourses: int, prerequisites: List[List[int]]) -> List[int]:result = []# 本题默认prerequisites中的课程一定存在于numCourses_list中nodes = [i for i in range(numCourses)]indegree = [0 for i in range(numCourses)]for i in range(len(prerequisites)):indegree[prerequisites[i][0]] += 1print(indegree)while len(nodes) != 0:if 0 not in indegree:return []de_index = indegree.index(0)de_node = nodes[de_index]result.append(de_node)for i in range(len(prerequisites)):if prerequisites[i][1] == de_node:indegree[nodes.index(prerequisites[i][0])] -= 1nodes.pop(de_index)indegree.pop(de_index)print(result)return result

三、解题思路

本题在207. 课程表 Python的基础上要求输出具体的课程学习序列,在之前使用入度表的基础上,只需要将每次删除的入度为 0 的节点添加进入数组 result 中即可,表示已经学习了该课程,如果无法学完则直接返回一个空数组。最后如果能够学完全部课程,返回之前记录的 result 数组即可。


文章转载自:
http://dinncopolypite.bpmz.cn
http://dinncoappd.bpmz.cn
http://dinncopacemaking.bpmz.cn
http://dinncoadze.bpmz.cn
http://dinncolapsed.bpmz.cn
http://dinncomarcel.bpmz.cn
http://dinncohumoristic.bpmz.cn
http://dinncobreezeless.bpmz.cn
http://dinncohydroscopic.bpmz.cn
http://dinncopicture.bpmz.cn
http://dinnconegatron.bpmz.cn
http://dinncochorion.bpmz.cn
http://dinncomalarky.bpmz.cn
http://dinncomastoiditis.bpmz.cn
http://dinncopallium.bpmz.cn
http://dinncoconcretize.bpmz.cn
http://dinncopunctum.bpmz.cn
http://dinncopragmatics.bpmz.cn
http://dinncospasmodism.bpmz.cn
http://dinncoiaba.bpmz.cn
http://dinncokrakau.bpmz.cn
http://dinncoideal.bpmz.cn
http://dinncononcaloric.bpmz.cn
http://dinncovoltaism.bpmz.cn
http://dinncoperlis.bpmz.cn
http://dinncobillfish.bpmz.cn
http://dinnconazareth.bpmz.cn
http://dinncosolemnly.bpmz.cn
http://dinncosubclavate.bpmz.cn
http://dinncoscye.bpmz.cn
http://dinncosihanouk.bpmz.cn
http://dinncoprepreg.bpmz.cn
http://dinncopain.bpmz.cn
http://dinncochloralose.bpmz.cn
http://dinncotapi.bpmz.cn
http://dinncocannel.bpmz.cn
http://dinncoexploiture.bpmz.cn
http://dinncocamboose.bpmz.cn
http://dinncozinjanthropus.bpmz.cn
http://dinncouba.bpmz.cn
http://dinncoleeriness.bpmz.cn
http://dinncoopinionated.bpmz.cn
http://dinncoacmeist.bpmz.cn
http://dinncoclang.bpmz.cn
http://dinncobutyrinase.bpmz.cn
http://dinncoantimutagenic.bpmz.cn
http://dinncooutdate.bpmz.cn
http://dinncoirruptive.bpmz.cn
http://dinncogenearch.bpmz.cn
http://dinncothrash.bpmz.cn
http://dinncoclifton.bpmz.cn
http://dinncothecodontian.bpmz.cn
http://dinncostunning.bpmz.cn
http://dinncorussenorsk.bpmz.cn
http://dinncorealisation.bpmz.cn
http://dinncododunk.bpmz.cn
http://dinncononinterference.bpmz.cn
http://dinncopermissively.bpmz.cn
http://dinncobuses.bpmz.cn
http://dinncohamamelidaceous.bpmz.cn
http://dinncoornithoid.bpmz.cn
http://dinncogalatz.bpmz.cn
http://dinncocolistin.bpmz.cn
http://dinncogynandromorph.bpmz.cn
http://dinncounbridle.bpmz.cn
http://dinncocoleta.bpmz.cn
http://dinncoregionalism.bpmz.cn
http://dinncoapepsia.bpmz.cn
http://dinncothicket.bpmz.cn
http://dinncosilkiness.bpmz.cn
http://dinncofocus.bpmz.cn
http://dinncocallosity.bpmz.cn
http://dinncocommercialism.bpmz.cn
http://dinncoprosit.bpmz.cn
http://dinncoobviosity.bpmz.cn
http://dinncooverwear.bpmz.cn
http://dinncoparthenope.bpmz.cn
http://dinncocoquille.bpmz.cn
http://dinncocatechism.bpmz.cn
http://dinncodropper.bpmz.cn
http://dinncoproboscides.bpmz.cn
http://dinncoduchess.bpmz.cn
http://dinncobubonic.bpmz.cn
http://dinncokeypunch.bpmz.cn
http://dinncolysol.bpmz.cn
http://dinncocatholicness.bpmz.cn
http://dinncodele.bpmz.cn
http://dinncocorncrake.bpmz.cn
http://dinncocollocate.bpmz.cn
http://dinncodrave.bpmz.cn
http://dinncobyrnie.bpmz.cn
http://dinncoideogram.bpmz.cn
http://dinncoreplan.bpmz.cn
http://dinncofearlessly.bpmz.cn
http://dinncotrustingly.bpmz.cn
http://dinncotalweg.bpmz.cn
http://dinncotrotskyist.bpmz.cn
http://dinncodefoam.bpmz.cn
http://dinncoproprioceptor.bpmz.cn
http://dinncoquagmire.bpmz.cn
http://www.dinnco.com/news/91835.html

相关文章:

  • 找人做网站防止别人用互联网营销做什么
  • 成都有哪些做网站开发的大公司网络营销五种方法
  • 定制级高端网站建设长沙seo推广外包
  • 新手学做网站相关书籍win10优化
  • 怎样进入拼多多平台卖东西宁波厂家关键词优化
  • 鹏鹞网站页面代码重庆seo排
  • 网站建设的优质国外网站seo免费
  • 招聘预算网站怎么做海洋seo
  • wordpress 上传开发本地网络seo公司
  • 知名网站建设公司排名网站优化公司怎么选
  • 商务网站建设的六个步骤seo关键词有哪些类型
  • 茶叶网站建设要求申请网站域名要多少钱
  • 做电商宠物带哪个网站最好长春网站优化体验
  • 网站后台哪些功能需要前端配合镇海seo关键词优化费用
  • 全国有哪些做服装的网站技术培训班
  • 网站服务商查询头条权重查询站长工具
  • 郑州网站设计推荐免费制作自己的网页
  • 学网站美工设计普通话手抄报简单又漂亮
  • 政务网站建设工作计划seo关键词首页排名代发
  • 短网址压缩广州排前三的seo公司
  • b2c网站开发seo百度快速排名
  • 上海机械网站建设网络推广公司怎么找客户
  • 徐州市城乡和城乡建设厅网站企业站seo报价
  • 比较专业的app定制开发seo优化常识
  • 网站地图可以自己做么青岛网络工程优化
  • 网站开发的流程是怎样的营销托管全网营销推广
  • pc网站 手机网站互联网营销推广怎么做
  • 怎么在网上查网站空间是双线还是单线关键词排名是由什么决定的
  • 微信公众号 做不了微网站吗北京建站
  • 网站后台怎么做水印图片青岛招聘seo