// "static void main" must be defined in a public class.
public class Main {
public static void main(String[] args) {
int[][] info = new int[4][];
info[0] = null;
info[1] = new int[] {0};
info[2] = new int[] {1};
info[3] = new int[] {1,0};
int[] res = getCourseOrder(info, 3);
for (int i = 0; i<res.length; i++){
System.out.println(res[i]);
} } public static int[] getCourseOrder(int[][]courseInfo, int courseToTake){
List<Integer> list = new ArrayList<>(); Queue<Integer> queue = new LinkedList<>();
Set<Integer> set = new HashSet<>();
queue.add(courseToTake);
while(!queue.isEmpty()){
int course = queue.poll();
list.add(course);
int[] preCourses = courseInfo[course];
if(preCourses != null && preCourses.length>0){
for(int i = 0; i < preCourses.length; i++){
if(!set.contains(preCourses[i])){
queue.add(preCourses[i]);
set.add(preCourses[i]);
} }
}
}
int[] res = new int[list.size()];
for(int i=0; i<list.size(); i++){
res[i] = list.get(list.size() - i -1);
}
return res;
}
}

Microsoft - Get Course Order的更多相关文章

  1. Configure Visual Studio 2013 for debugging .NET framework

    https://referencesource.microsoft.com/ In order to configure Visual Studio 2013 do the following in ...

  2. 第十三篇 Integration Services:SSIS变量

    本篇文章是Integration Services系列的第十三篇,详细内容请参考原文. 简介在前一篇我们结合了之前所学的冒泡.日志记录.父子模式创建一个自定义的SSIS包日志记录模式.在这一篇,我们将 ...

  3. Tesseract Ocr引擎

    Tesseract Ocr引擎 1.Tesseract介绍 tesseract 是一个google支持的开源ocr项目,其项目地址:https://github.com/tesseract-ocr/t ...

  4. Python下Tesseract Ocr引擎及安装介绍

    1.Tesseract介绍 tesseract 是一个google支持的开源ocr项目,其项目地址:https://github.com/tesseract-ocr/tesseract,目前最新的源码 ...

  5. 【译】第十三篇 Integration Services:SSIS变量

    本篇文章是Integration Services系列的第十三篇,详细内容请参考原文. 简介在前一篇我们结合了之前所学的冒泡.日志记录.父子模式创建一个自定义的SSIS包日志记录模式.在这一篇,我们将 ...

  6. DDD实战12 值对象不创建表,而是直接作为实体中的字段

    这里的值对象如下风格: namespace Order.Domain.PocoModels { //订单地址 //虽然是值对象 但是不继承ValueObject //因为继承ValueObject会有 ...

  7. 异常详细信息: System.Security.SecurityException: 未找到源,不过,未能搜索部分或所有事件日志。 若要创建源,您需要用于读取所有事件日志的权限以确保新的源名称是唯一的。 不可访问的日志: Security。

    “/”应用程序中的服务器错误. 安全性异常 说明: 应用程序尝试执行安全策略不允许的操作.要授予此应用程序所需的权限,请与系统管理员联系,或在配置文件中更改该应用程序的信任级别. 异常详细信息: Sy ...

  8. C++银行储蓄程序代码

    */ * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:text.cpp * 作者:常轩 * 微信公众号:Worldhe ...

  9. 【Azure 环境】在Azure虚拟机(经典) 的资源中,使用SDK导出VM列表的办法

    Azure,  在2008年10月的Microsoft专业开发人员大会(PDC)上宣布,当时使用内部项目代号"Project Red Dog",并于2010年2月正式发布为Wind ...

随机推荐

  1. Redis之无序集合类型命令

    Redis 集合(Set) Redis 的 Set 是 String 类型的无序集合.集合成员是唯一的,这就意味着集合中不能出现重复的数据. Redis 中集合是通过哈希表实现的,所以添加,删除,查找 ...

  2. tomcat日志切割和定期删除

    tomcat日志切割和定期删除 在tomcat的软件环境中,如果我们任由日志文件无限增长,总有一天会将磁盘占满的(废话).特别是在日志文件增长速度很快的一些情况下,按日志切割日志文件并删除,就是一件很 ...

  3. Mycat配置入门

    配置: --bin 启动目录 --conf 配置文件存放配置文件: --server.xml:是Mycat服务器参数调整和用户授权的配置文件. --schema.xml:是逻辑库定义和表以及分片定义的 ...

  4. Three Pieces CodeForces - 1065D (BFS)

    链接 大意: n*n棋盘, 每个格子写有数字, 各不相同, 范围[1,n*n], 初始在数字1的位置, 可以操纵knight,bishop,rook三种棋子, 每走一步花费1, 交换棋子花费1, 问按 ...

  5. 『PyTorch』第三弹重置_Variable对象

    『PyTorch』第三弹_自动求导 torch.autograd.Variable是Autograd的核心类,它封装了Tensor,并整合了反向传播的相关实现 Varibale包含三个属性: data ...

  6. 『Python』图像金字塔、滑动窗口和非极大值抑制实现

    图像金字塔 1.在从cv2.resize中,传入参数时先列后行的 2.使用了python中的生成器,调用时使用for i in pyramid即可 3.scaleFactor是缩放因子,需要保证缩放后 ...

  7. 应用多种变形CSS3

    <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>    < ...

  8. CentOS搭建“加速器”

    1.安装Shadowsocks 服务端 yum -y update yum install -y python-setuptools && easy_install pip pip i ...

  9. Intel DAAL AI加速 ——传统决策树和随机森林

    # file: dt_cls_dense_batch.py #===================================================================== ...

  10. 51nod1269Devu and Flowers

    题解: 如果没有限制每一种花有多少,那么就是简单的排列组合问题. 那么我们强制让一些花一定都要选. 暴力搜索,然后组合数(逆元) 采用容斥原理来计算最后的答案 代码: #include<bits ...