方法一:

class Solution(object):
def minimumSemesters(self, N, relations):
"""
:type N: int
:type relations: List[List[int]]
:rtype: int
"""
dic = {}
dic2 = {}
for i in range(1, N+1):
dic[i] = 0
dic2[i] = []
for r in relations:
dic[r[1]]+=1
dic2[r[0]].append(r[1])
ans = 0
keys = dic.keys()
while keys:
arr = []
for k in keys:
if dic[k] == 0:
arr.append(k)
if not arr: return -1
for k in arr:
if k in dic2:
for w in dic2[k]:
dic[w] -= 1
del dic[k]
ans += 1
keys = dic.keys()
return ans

leetcode-第5周双周赛-1136平行课程的更多相关文章

  1. LeetCode第8场双周赛(Java)

    这次我只做对一题. 原因是题目返回值类型有误,写的是 String[] ,实际上应该返回 List<String> . 好吧,只能自认倒霉.就当涨涨经验. 5068. 前后拼接 解题思路 ...

  2. LeetCode 第 15 场双周赛

    1287.有序数组中出现次数超过25%的元素 1288.删除被覆盖区间 1286.字母组合迭代器 1289.下降路径最小和 II 下降和不能只保留原数组中最小的两个,hacked. 1287.有序数组 ...

  3. LeetCode 第 14 场双周赛

    基础的 api 还是不够熟悉啊 5112. 十六进制魔术数字 class Solution { public: char *lltoa(long long num, char *str, int ra ...

  4. leetcode-第14周双周赛-1274-矩形内船只的数目

    题目描述: 自己的提交: # """ # This is Sea's API interface. # You should not implement it, or s ...

  5. leetcode-第14周双周赛-1273-删除树节点

    题目描述: 自己的提交:动态规划 class Solution: def deleteTreeNodes(self, nodes: int, parent: List[int], value: Lis ...

  6. leetcode-第14周双周赛-1272-删除区间

    题目描述: 自己的提交: class Solution: def removeInterval(self, intervals: List[List[int]], toBeRemoved: List[ ...

  7. leetcode-第14周双周赛-1271-十六进制魔术数字

    自己的提交: class Solution: def toHexspeak(self, num: str) -> str: num = hex(int(num)) num = str(num)[ ...

  8. leetcode-第12周双周赛-5111-分享巧克力

    题目描述: 方法: class Solution: def maximizeSweetness(self, A: List[int], K: int) -> int: def possible( ...

  9. leetcode-12周双周赛-5090-抛掷硬币

    题目描述: 二维dp: class Solution: def probabilityOfHeads(self, prob: List[float], target: int) -> float ...

随机推荐

  1. spring配置hibernate的sessionFactory

    1.首先通过dataSource来配置sessionFactory <!--读入配置文件 --> <bean id="propertyConfigurer" cl ...

  2. sklearn中模型抽取

    特征抽取sklearn.feature_extraction 模块提供了从原始数据如文本,图像等众抽取能够被机器学习算法直接处理的特征向量. 1.特征抽取方法之 Loading Features fr ...

  3. 【POJ】2253 Frogger

    = =.请用C++提交.. 如果有朋友能告诉我G++和C++交题什么机制..我感激不尽.G++杀我. 题目链接:http://poj.org/problem?id=2253 题意:青蛙A要去找B约会, ...

  4. kafka 入门

    李克华 云计算高级群: 292870151 195907286 交流:Hadoop.NoSQL.分布式.lucene.solr.nutch  kafka入门:简介.使用场景.设计原理.主要配置及集群搭 ...

  5. Shell 学习(三)

    目录 Shell 学习(三) 流程控制 1 if判断 2 case 语句 3 for循环 4 while 循环 2 read 读取控制台输入 2.1 基本语法 2.2 应用实例 3 函数 3.1 系统 ...

  6. Extremely fast hash algorithm-xxHash

    xxHash - Extremely fast hash algorithm xxHash is an Extremely fast Hash algorithm, running at RAM sp ...

  7. FCC知识点总结

    1.DOMContentLoaded事件 2.延迟脚本 defer 3.异步脚本async 4.[找最长单词]—— 找出句子中最长的单词,并返回它的长度. 5.数组slice().splice() s ...

  8. Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support:appcompat-v7:26.1.0

    android studio  3.0 出现此问题可能是因为 你的android studio 时脱机状态 无法下载资源 这时候你可以点击左上角分File->Other Settings-> ...

  9. 下载和安装mongodb4.2.0+robmongo可视化工具

    一.mongodb下载安装 1.mongodb下载地址:https://www.mongodb.com/download-center/community?jmp=nav 下了很久很久,可以找其他途径 ...

  10. CSS3——伸缩布局及应用

    CSS3在布局方面做了非常大的改进,使得我们对块级元素的布局排列变得十分灵活,适应性非常强,其强大的伸缩性,在响应式开中可以发挥极大的作用. 主轴:Flex容器的主轴主要用来配置Flex项目,默认是水 ...