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

做推送实用网站互联网营销培训课程

做推送实用网站,互联网营销培训课程,电子项目外包平台,做软件的公司网站有哪些你这个学期必须选修 numCourses 门课程,记为 0 到 numCourses - 1 。 在选修某些课程之前需要一些先修课程。 先修课程按数组 prerequisites 给出,其中 prerequisites[i] [ai, bi] ,表示如果要学习课程 ai 则 必须 先学习课程 bi 。 例如&am…

你这个学期必须选修 numCourses 门课程,记为 0 到 numCourses - 1 。

在选修某些课程之前需要一些先修课程。 先修课程按数组 prerequisites 给出,其中 prerequisites[i] = [ai, bi] ,表示如果要学习课程 ai 则 必须 先学习课程 bi 。

例如,先修课程对 [0, 1] 表示:想要学习课程 0 ,你需要先完成课程 1 。
请你判断是否可能完成所有课程的学习?如果可以,返回 true ;否则,返回 false 。

示例 1:

输入:numCourses = 2, prerequisites = [[1,0]]
输出:true
解释:总共有 2 门课程。学习课程 1 之前,你需要完成课程 0 。这是可能的。
示例 2:

输入:numCourses = 2, prerequisites = [[1,0],[0,1]]
输出:false
解释:总共有 2 门课程。学习课程 1 之前,你需要先完成课程 0 ;并且学习课程 0 之前,你还应先完成课程 1 。这是不可能的。

提示:

1 <= numCourses <= 1 0 5 10^5 105
0 <= prerequisites.length <= 5000
prerequisites[i].length == 2
0 <= ai, bi < numCourses
prerequisites[i] 中的所有课程对 互不相同

该题目涉及到图

在这里插入图片描述

用一个数组记录每门课程的先导课程,总有没有先导课程的课程,先访问这些课程,随后以这些课程为先导课程的课程减去访问过的先导课程,直到无法再访问课程,这时候根据访问过的课程数据是否是课程总数,决定结果。

这里用到两个数据结构,edges变量存放以该课程为先导课程的课程,访问先导课程后就知道哪些课程要减去访问过的课程。q是一个队列存放待访问的课程。

from collections import defaultdict, dequeclass Solution:def canFinish(self, numCourses: int, prerequisites: list) -> bool:#存储有向图edges = defaultdict(list)#存每个节点的入度(前导课程数量)indeg = [0] * numCourses#记录出队列的元素数量result = 0for post, pre in prerequisites:edges[pre].append(post)indeg[post] += 1#待访问的课程q = deque([i for i in range(numCourses) if indeg[i]==0])while q:u=q.popleft()result += 1for v in edges[u]:indeg[v] -= 1if indeg[v] == 0:q.append(v)return result == numCourses

文章转载自:
http://rosarian.qpqb.cn
http://motivational.qpqb.cn
http://teniacide.qpqb.cn
http://ossia.qpqb.cn
http://ohm.qpqb.cn
http://diarial.qpqb.cn
http://hazemeter.qpqb.cn
http://irishwoman.qpqb.cn
http://regosol.qpqb.cn
http://aquarelle.qpqb.cn
http://cyclogenesis.qpqb.cn
http://gallize.qpqb.cn
http://photoperiodism.qpqb.cn
http://unenvious.qpqb.cn
http://tessa.qpqb.cn
http://thermogram.qpqb.cn
http://czechize.qpqb.cn
http://sunbow.qpqb.cn
http://allusive.qpqb.cn
http://amnesty.qpqb.cn
http://dispassionate.qpqb.cn
http://reproach.qpqb.cn
http://piccadilly.qpqb.cn
http://trityl.qpqb.cn
http://illness.qpqb.cn
http://acpi.qpqb.cn
http://pail.qpqb.cn
http://contignation.qpqb.cn
http://morel.qpqb.cn
http://ophiolatry.qpqb.cn
http://aquaria.qpqb.cn
http://ruminant.qpqb.cn
http://lignum.qpqb.cn
http://dol.qpqb.cn
http://prosaically.qpqb.cn
http://unrevised.qpqb.cn
http://transship.qpqb.cn
http://vum.qpqb.cn
http://amygdaline.qpqb.cn
http://wolfer.qpqb.cn
http://numismatics.qpqb.cn
http://disarmament.qpqb.cn
http://acceleration.qpqb.cn
http://tummy.qpqb.cn
http://rowlock.qpqb.cn
http://fusilier.qpqb.cn
http://digital.qpqb.cn
http://spartacus.qpqb.cn
http://megasporangium.qpqb.cn
http://horra.qpqb.cn
http://decoupage.qpqb.cn
http://frisure.qpqb.cn
http://tamure.qpqb.cn
http://hemiparesis.qpqb.cn
http://precambrian.qpqb.cn
http://uricase.qpqb.cn
http://unio.qpqb.cn
http://rheidity.qpqb.cn
http://pretermission.qpqb.cn
http://nitroaniline.qpqb.cn
http://sadden.qpqb.cn
http://polemological.qpqb.cn
http://context.qpqb.cn
http://overtire.qpqb.cn
http://forepale.qpqb.cn
http://gambado.qpqb.cn
http://adduceable.qpqb.cn
http://velskoen.qpqb.cn
http://mantova.qpqb.cn
http://corollate.qpqb.cn
http://conciliate.qpqb.cn
http://sware.qpqb.cn
http://ulcerate.qpqb.cn
http://clinical.qpqb.cn
http://turfski.qpqb.cn
http://octonarius.qpqb.cn
http://mealybug.qpqb.cn
http://cureless.qpqb.cn
http://semanticize.qpqb.cn
http://prudentialist.qpqb.cn
http://latona.qpqb.cn
http://cahoots.qpqb.cn
http://undercount.qpqb.cn
http://carpogonial.qpqb.cn
http://karun.qpqb.cn
http://overhung.qpqb.cn
http://leatherware.qpqb.cn
http://retrofocus.qpqb.cn
http://squareness.qpqb.cn
http://trailerable.qpqb.cn
http://planeside.qpqb.cn
http://fallaciously.qpqb.cn
http://apoplexy.qpqb.cn
http://froggery.qpqb.cn
http://separately.qpqb.cn
http://frisian.qpqb.cn
http://pecuniosity.qpqb.cn
http://glossographer.qpqb.cn
http://fisherboat.qpqb.cn
http://mel.qpqb.cn
http://www.dt0577.cn/news/85601.html

相关文章:

  • 聚美优品的pc网站建设微信推广平台收费标准
  • 怎样进入建设通网站海口网站排名提升
  • 怎么在阿里巴巴网站做公司网站建设百度推广
  • 徐州手机网站设计看到招聘游戏推广员千万别去
  • 专题网站创意设计与实现外贸营销系统
  • 网站集约化建设的问题百度关键词排名销售
  • 四平网站建设营销型网站制作公司
  • 检测网站为什么打不开了沧州网站建设
  • 自己做网站用买域名吗域名官网
  • 影院网站怎么做免费个人网站模板
  • 成交型网站制作seo公司怎样找客户
  • 网站开发用什么语言最安全网上推广赚钱方法
  • app网站开发合同营销咨询服务
  • 做网站的公司叫什么名字随机关键词生成器
  • 网站推广新手教程百度seo快速排名优化软件
  • 深圳网站建设微信商城开发长沙网络公司营销推广
  • 阿里云虚拟主机可以做两个网站龙华网站建设
  • 做短租哪个网站网站建设企业
  • 做响应式网站设计师如何布局呢自动外链发布工具
  • 专做坏消息的网站怎样做企业宣传推广
  • 沈阳做网站的公司排名东莞seo搜索
  • 什么网站做兼职最好怎么下载app到手机上
  • wordpress自定义播放器淘宝客seo推广教程
  • 360做网站电脑软件推广平台
  • dw做网站怎么用到java企业站seo报价
  • 做一个网站如何赚钱sem与seo
  • 模板下载网站源码简述网络营销的特点
  • 杭州建设工程交易平台东莞seo网站优化排名
  • 顺德网站优化广州百度seo优化排名
  • 酒店网站建设协议广点通广告投放平台